青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

OpenCV Remapping

https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/remap/remap.html

Goal

In this tutorial you will learn how to:

  1. Use the OpenCV function remap to implement simple remapping routines.

Theory

What is remapping?

  • It is the process of taking pixels from one place in the image and locating them in another position in a new image.

  • To accomplish the mapping process, it might be necessary to do some interpolation for non-integer pixel locations, since there will not always be a one-to-one-pixel correspondence between source and destination images.

  • We can express the remap for every pixel location (x,y) as:

    g(x,y) = f ( h(x,y) )

    where g() is the remapped image, f() the source image and h(x,y) is the mapping function that operates on (x,y).

  • Let’s think in a quick example. Imagine that we have an image I and, say, we want to do a remap such that:

    h(x,y) = (I.cols - x, y )

    What would happen? It is easily seen that the image would flip in the x direction. For instance, consider the input image:

    Original test image

    observe how the red circle changes positions with respect to x (considering x the horizontal direction):

    Original test image
  • In OpenCV, the function remap offers a simple remapping implementation.

Code

  1. What does this program do?
    • Loads an image
    • Each second, apply 1 of 4 different remapping processes to the image and display them indefinitely in a window.
    • Wait for the user to exit the program
  2. The tutorial code’s is shown lines below. You can also download it from here
 #include "opencv2/highgui/highgui.hpp"  #include "opencv2/imgproc/imgproc.hpp"  #include <iostream>  #include <stdio.h>   using namespace cv;   /// Global variables  Mat src, dst;  Mat map_x, map_y;  char* remap_window = "Remap demo";  int ind = 0;   /// Function Headers  void update_map( void );   /**  * @function main  */  int main( int argc, char** argv )  {    /// Load the image    src = imread( argv[1], 1 );    /// Create dst, map_x and map_y with the same size as src:   dst.create( src.size(), src.type() );   map_x.create( src.size(), CV_32FC1 );   map_y.create( src.size(), CV_32FC1 );    /// Create window   namedWindow( remap_window, CV_WINDOW_AUTOSIZE );    /// Loop   while( true )   {     /// Each 1 sec. Press ESC to exit the program     int c = waitKey( 1000 );      if( (char)c == 27 )       { break; }      /// Update map_x & map_y. Then apply remap     update_map();     remap( src, dst, map_x, map_y, CV_INTER_LINEAR, BORDER_CONSTANT, Scalar(0,0, 0) );      /// Display results     imshow( remap_window, dst );   }   return 0;  }   /**  * @function update_map  * @brief Fill the map_x and map_y matrices with 4 types of mappings  */  void update_map( void )  {    ind = ind%4;     for( int j = 0; j < src.rows; j++ )    { for( int i = 0; i < src.cols; i++ )        {          switch( ind )          {            case 0:              if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )                {                  map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;                  map_y.at<float>(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ;                 }              else                { map_x.at<float>(j,i) = 0 ;                  map_y.at<float>(j,i) = 0 ;                }                  break;            case 1:                  map_x.at<float>(j,i) = i ;                  map_y.at<float>(j,i) = src.rows - j ;                  break;            case 2:                  map_x.at<float>(j,i) = src.cols - i ;                  map_y.at<float>(j,i) = j ;                  break;            case 3:                  map_x.at<float>(j,i) = src.cols - i ;                  map_y.at<float>(j,i) = src.rows - j ;                  break;          } // end of switch        }     }   ind++; } 

Explanation

  1. Create some variables we will use:

    Mat src, dst; Mat map_x, map_y; char* remap_window = "Remap demo"; int ind = 0; 
  2. Load an image:

    src = imread( argv[1], 1 ); 
  3. Create the destination image and the two mapping matrices (for x and y )

    dst.create( src.size(), src.type() ); map_x.create( src.size(), CV_32FC1 ); map_y.create( src.size(), CV_32FC1 ); 
  4. Create a window to display results

    namedWindow( remap_window, CV_WINDOW_AUTOSIZE ); 
  5. Establish a loop. Each 1000 ms we update our mapping matrices (mat_x and mat_y) and apply them to our source image:

    while( true ) {   /// Each 1 sec. Press ESC to exit the program   int c = waitKey( 1000 );    if( (char)c == 27 )     { break; }    /// Update map_x & map_y. Then apply remap   update_map();   remap( src, dst, map_x, map_y, CV_INTER_LINEAR, BORDER_CONSTANT, Scalar(0,0, 0) );    /// Display results   imshow( remap_window, dst ); } 

    The function that applies the remapping is remap. We give the following arguments:

    • src: Source image
    • dst: Destination image of same size as src
    • map_x: The mapping function in the x direction. It is equivalent to the first component of h(i,j)
    • map_y: Same as above, but in y direction. Note that map_y and map_x are both of the same size as src
    • CV_INTER_LINEAR: The type of interpolation to use for non-integer pixels. This is by default.
    • BORDER_CONSTANT: Default

    How do we update our mapping matrices mat_x and mat_y? Go on reading:

  6. Updating the mapping matrices: We are going to perform 4 different mappings:

    1. Reduce the picture to half its size and will display it in the middle:

      h(i,j) = ( 2*i - src.cols/2  + 0.5, 2*j - src.rows/2  + 0.5)

      for all pairs (i,j) such that: \dfrac{src.cols}{4}<i<\dfrac{3 \cdot src.cols}{4} and \dfrac{src.rows}{4}<j<\dfrac{3 \cdot src.rows}{4}

    2. Turn the image upside down: h( i, j ) = (i, src.rows - j)

    3. Reflect the image from left to right: h(i,j) = ( src.cols - i, j )

    4. Combination of b and c: h(i,j) = ( src.cols - i, src.rows - j )

This is expressed in the following snippet. Here, map_x represents the first coordinate of h(i,j) and map_y the second coordinate.

for( int j = 0; j < src.rows; j++ ) { for( int i = 0; i < src.cols; i++ )     {       switch( ind )       {         case 0:           if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )             {               map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;               map_y.at<float>(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ;              }           else             { map_x.at<float>(j,i) = 0 ;               map_y.at<float>(j,i) = 0 ;             }               break;         case 1:               map_x.at<float>(j,i) = i ;               map_y.at<float>(j,i) = src.rows - j ;               break;         case 2:               map_x.at<float>(j,i) = src.cols - i ;               map_y.at<float>(j,i) = j ;               break;         case 3:               map_x.at<float>(j,i) = src.cols - i ;               map_y.at<float>(j,i) = src.rows - j ;               break;       } // end of switch     }   }  ind++; } 

Result

  1. After compiling the code above, you can execute it giving as argument an image path. For instance, by using the following image:

    Original test image
  2. This is the result of reducing it to half the size and centering it:

    Result 0 for remapping
  3. Turning it upside down:

    Result 0 for remapping
  4. Reflecting it in the x direction:

    Result 0 for remapping
  5. Reflecting it in both directions:

Result 0 for remapping

posted on 2017-12-20 17:44 zmj 閱讀(688) 評論(0)  編輯 收藏 引用

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美伦理视频网站| 亚洲视频一区二区免费在线观看| 国产真实精品久久二三区 | 久久久精品动漫| 欧美一区二区三区免费观看| 久久久久国内| 亚洲欧美日韩一区二区在线| 91久久久精品| 欧美激情按摩| 免费亚洲电影| 亚洲成色精品| 亚洲高清在线观看| 亚洲国产精品成人| 亚洲激情国产精品| 亚洲精品色婷婷福利天堂| 欧美国产日产韩国视频| 欧美成人一区二区| 亚洲国产精品va在线看黑人动漫 | 亚洲一区二区三区高清| 亚洲精品美女久久久久| 在线免费观看日本欧美| 黄色日韩在线| 亚洲大片在线观看| 亚洲精选国产| 亚洲一区二区欧美日韩| 午夜精品视频在线| 久久精品麻豆| 免费观看在线综合色| 亚洲丰满在线| 一本不卡影院| 欧美综合第一页| 欧美日韩精品免费观看视频完整| 国产综合香蕉五月婷在线| 亚洲视频福利| 亚洲国产日韩美| 久久精品视频一| 国产欧美激情| 欧美国产一区二区三区激情无套| 久久精品视频在线观看| 久久亚洲综合网| 国产欧美日韩| 亚洲综合视频1区| 欧美激情一区二区三区蜜桃视频| 午夜一区二区三视频在线观看 | 狂野欧美激情性xxxx欧美| 国产精品女主播一区二区三区| 亚洲欧美日韩国产成人| 欧美成ee人免费视频| 极品尤物一区二区三区| 午夜精品久久久久久久99水蜜桃| 亚洲第一天堂无码专区| 久久男女视频| 在线国产欧美| 男人的天堂亚洲| 久久久免费观看视频| 激情综合在线| 久久综合给合久久狠狠色| 欧美在线观看视频在线| 国产日产欧美一区| 国产精品a久久久久| 欧美日韩国产高清视频| 亚洲欧洲一区| 亚洲国产精品女人久久久| 久久综合色婷婷| 亚洲欧洲日本一区二区三区| 麻豆国产精品777777在线| 欧美一区午夜精品| 午夜一区在线| 国产亚洲精品一区二区| 久久深夜福利| 欧美a级一区| 在线视频欧美一区| 亚洲欧美精品| 在线成人h网| 亚洲精品美女久久7777777| 欧美日韩国产经典色站一区二区三区| 夜夜嗨av一区二区三区| 亚洲性线免费观看视频成熟| 国产日韩1区| 欧美黄色免费| 国产精品扒开腿做爽爽爽视频| 欧美一区二区播放| 玖玖视频精品| 亚洲免费影院| 久久午夜电影网| 亚洲香蕉视频| 久久大香伊蕉在人线观看热2| 亚洲成在人线av| 国产精品99久久久久久人| 国产亚洲激情| 亚洲区免费影片| 国产裸体写真av一区二区| 欧美成人午夜剧场免费观看| 欧美色区777第一页| 久久久一本精品99久久精品66| 欧美电影免费观看| 先锋影音久久| 欧美大片免费| 久久久精品国产免大香伊| 欧美高清视频一区二区三区在线观看 | 中国成人亚色综合网站| 欧美一区2区三区4区公司二百| 91久久久久久| 午夜日本精品| 中文久久乱码一区二区| 久久久蜜桃精品| 欧美一级一区| 欧美日韩国产电影| 欧美岛国在线观看| 国产欧美精品一区aⅴ影院| 亚洲黄色免费电影| 国产亚洲永久域名| 中日韩美女免费视频网站在线观看| 黄色亚洲精品| 午夜精品在线看| 亚洲欧美日韩精品在线| 欧美精品色网| 欧美国产在线观看| 尤物yw午夜国产精品视频明星| av不卡在线| 亚洲一区二区三区四区在线观看| 欧美一级免费视频| 欧美三级午夜理伦三级中视频| 老司机免费视频久久| 国产乱码精品1区2区3区| 亚洲精品视频啊美女在线直播| 在线播放中文字幕一区| 欧美一区二区三区四区在线| 亚洲欧美一级二级三级| 欧美色中文字幕| 亚洲欧洲精品一区二区三区波多野1战4 | 久久久久久成人| 国产精品yjizz| 99热在线精品观看| 日韩亚洲视频| 欧美国产视频在线观看| 亚洲成色999久久网站| 亚洲高清视频在线| 久久久噜噜噜| 欧美多人爱爱视频网站| 国产一在线精品一区在线观看| 亚洲系列中文字幕| 午夜精彩国产免费不卡不顿大片| 欧美视频免费看| 亚洲精品美女91| 欧美69wwwcom| 亚洲韩国精品一区| 一本色道久久加勒比精品| 欧美激情一区二区三区成人 | 亚洲一区二区三区在线观看视频 | 中文日韩在线| 国产精品女人久久久久久| 亚洲免费视频在线观看| 欧美中文字幕精品| 在线看片第一页欧美| 免费一级欧美片在线观看| 亚洲欧洲日产国码二区| 亚洲一区二区三区中文字幕| 国产精品免费区二区三区观看| 亚洲欧美激情在线视频| 久久综合久久久| 亚洲美女视频网| 国产精品拍天天在线| 欧美一级视频精品观看| 欧美不卡视频一区发布| 99国产精品视频免费观看一公开| 欧美日韩国产成人在线91| 亚洲永久在线| 欧美成人免费在线视频| 亚洲一区二区免费视频| 黑人一区二区| 欧美色精品天天在线观看视频| 欧美一区二区三区在线看| 欧美国产日韩一区二区三区| 一区二区三区精品在线| 国产精品一区毛片| 母乳一区在线观看| 中文在线资源观看网站视频免费不卡| 久久se精品一区二区| 亚洲欧洲一区二区三区久久| 欧美三级电影大全| 久久久天天操| 久久这里只有精品视频首页| 蜜桃精品一区二区三区| 一区二区三区日韩精品视频| 久久精品一区四区| 艳女tv在线观看国产一区| 国产一区二区黄色| 欧美日韩精品三区| 欧美va亚洲va香蕉在线| 亚洲一区二区在线免费观看视频| 狠狠网亚洲精品| 国产精品久久久久久久电影 | 久久久美女艺术照精彩视频福利播放| 日韩午夜电影在线观看| 在线观看一区视频| 国产欧美日韩精品丝袜高跟鞋| 欧美黄污视频| 可以看av的网站久久看| 欧美在线资源|