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

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>
            久久综合福利| 亚洲福利小视频| 久久久久久网| 久久精品一区二区三区不卡牛牛| 欧美片在线播放| 宅男精品视频| 午夜久久久久| 亚洲激情成人网| 亚洲免费影院| 亚洲电影欧美电影有声小说| 亚洲国产网站| 国产欧美一区二区三区久久| 久久久久久久久久码影片| 免费观看一级特黄欧美大片| 亚洲视频精选在线| 久久一区中文字幕| 亚洲一级免费视频| 麻豆精品在线播放| 久久精品中文字幕一区二区三区| 久久九九99视频| 久久久亚洲成人| 亚洲欧美99| 欧美激情第1页| 蜜桃av噜噜一区| 国产亚洲欧美一级| 中日韩高清电影网| 亚洲在线观看视频网站| 欧美精品一区二区三区蜜桃| 欧美国产视频日韩| 亚洲第一网站| 免费在线成人| 亚洲国产岛国毛片在线| 一区二区亚洲精品国产| 欧美一区二粉嫩精品国产一线天| 亚洲一区观看| 国产精品美女一区二区在线观看 | 亚洲第一区色| 亚洲韩国青草视频| 久久资源av| 亚洲国产精品一区二区www| 亚洲高清一区二| 欧美福利视频一区| 日韩亚洲精品在线| 欧美一二三区在线观看| 国产一区二区三区四区三区四| 久久动漫亚洲| 欧美成在线观看| 亚洲视频一区二区| 国产一区白浆| 欧美xart系列高清| 一区二区三区视频免费在线观看| 午夜日韩在线| 91久久综合亚洲鲁鲁五月天| 欧美日本一道本| 久久深夜福利免费观看| 日韩视频在线免费观看| 国产精品久久久一区麻豆最新章节| 亚洲——在线| 91久久极品少妇xxxxⅹ软件| 欧美一区二区三区精品电影| 亚洲国产高清一区二区三区| 国产精品第13页| 媚黑女一区二区| 欧美一级午夜免费电影| 亚洲国产黄色片| 久久精品视频一| 亚洲一二三区在线观看| 在线观看亚洲视频啊啊啊啊| 国产精品素人视频| 欧美日韩中文字幕在线| 欧美日韩国产探花| 欧美大片免费观看| 久久一区激情| 久久天天躁狠狠躁夜夜爽蜜月 | 国产精品成人一区二区三区夜夜夜| 久久精品91久久久久久再现| 亚洲欧美国产日韩天堂区| 99re6热只有精品免费观看| 亚洲国产精品热久久| 亚洲电影av| 日韩一区二区精品视频| 99热在这里有精品免费| 一区二区三区高清在线观看| 亚洲图片激情小说| 久久男女视频| 欧美激情无毛| 国产精品日韩一区二区| 国产精品久久久久久久7电影| 欧美日在线观看| 国产精品日本精品| 伊甸园精品99久久久久久| 亚洲国产婷婷| 99精品99久久久久久宅男| 亚洲一区二区三| 国产欧美日韩一级| 在线成人中文字幕| 麻豆精品在线观看| 久久久久久9| 欧美日韩国产在线播放网站| 国产精品乱码一区二三区小蝌蚪 | 亚洲三级视频在线观看| 日韩视频中文| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲国产成人精品久久久国产成人一区 | 欧美一区二区视频观看视频| 欧美在线3区| 亚洲精品日产精品乱码不卡| 国产精品99久久久久久宅男 | 极品中文字幕一区| 99国内精品久久久久久久软件| 亚洲欧美在线网| 欧美激情一区二区三区| 久久久www成人免费毛片麻豆| 欧美天堂亚洲电影院在线观看 | 欧美在线免费| 国产精品丝袜白浆摸在线| 亚洲欧洲视频| 欧美激情久久久| 美腿丝袜亚洲色图| 亚洲激情成人| 亚洲国产精品欧美一二99| 蜜臀av性久久久久蜜臀aⅴ| 激情欧美国产欧美| 免费日韩视频| 欧美激情一区二区三区四区| 亚洲精品久久久久久下一站 | 国产精品一二三| 久久精品国产77777蜜臀| 亚洲自拍偷拍网址| 黄色精品在线看| 亚洲欧洲日本mm| 国产精品毛片| 欧美a一区二区| 欧美日韩一区成人| 久久久久久久久蜜桃| 麻豆精品在线播放| 亚洲尤物在线| 久久久久国产一区二区三区四区| 亚洲欧洲一区二区在线播放| av成人手机在线| 永久免费毛片在线播放不卡| 亚洲精品综合在线| 黑人巨大精品欧美一区二区| 亚洲精品视频在线观看网站 | 一本色道久久综合亚洲精品不卡| 亚洲精品日本| 1769国内精品视频在线播放| 正在播放欧美一区| 91久久在线播放| 久久精品夜色噜噜亚洲a∨| 9久re热视频在线精品| 久久精品国产99| 欧美一区观看| 亚洲一区二区三区免费在线观看| 亚洲国产另类 国产精品国产免费| 亚洲天堂视频在线观看| 夜夜嗨av一区二区三区中文字幕 | 欧美视频官网| 日韩一级免费| 日韩视频永久免费| 免费黄网站欧美| 久久久一二三| 激情综合中文娱乐网| 久久久中精品2020中文| 久久婷婷久久一区二区三区| 国产日产欧产精品推荐色| 亚洲自拍啪啪| 久久先锋影音| 久久精品色图| 亚洲国产91| 看片网站欧美日韩| 欧美日韩一区二| 亚洲美女免费精品视频在线观看| 亚洲专区一二三| 亚洲精品一区二区在线| 激情成人综合| 国产日韩在线亚洲字幕中文| 欧美a级片一区| 欧美va亚洲va香蕉在线| 久久人人爽人人爽爽久久| 久久成人国产| 久久精品在线| 久久精品夜夜夜夜久久| 久久精品中文| 欧美成人一区二区三区在线观看 | 亚洲欧美日韩国产精品| 亚洲午夜久久久| 中文在线资源观看视频网站免费不卡| 亚洲人成网站777色婷婷| 日韩视频免费在线观看| 亚洲午夜性刺激影院| 篠田优中文在线播放第一区| 性伦欧美刺激片在线观看| 久久精品国产一区二区三区免费看| 久久国产黑丝| 欧美激情亚洲视频| 亚洲福利视频免费观看| 欧美一区免费视频| 午夜综合激情| 久久亚洲综合|