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

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>
            久久久久天天天天| 国产精品久久久久久妇女6080| 亚洲国产精品成人精品| 亚洲性感美女99在线| 99国产精品久久| 99国产精品久久久久老师 | 国产在线日韩| 国产日韩综合| 国产日韩欧美在线一区| 国产性天天综合网| 樱桃成人精品视频在线播放| 91久久线看在观草草青青| 99re66热这里只有精品3直播| 亚洲午夜小视频| 欧美影院午夜播放| 欧美成人在线网站| 欧美激情日韩| 亚洲女爱视频在线| 久久久精品日韩欧美| 久久免费视频观看| 免费久久99精品国产| 欧美午夜欧美| 亚洲福利一区| 亚洲欧美视频一区| 欧美不卡一卡二卡免费版| 夜夜爽夜夜爽精品视频| 久久精品人人做人人综合| 欧美日韩国产精品一区二区亚洲| 国产日韩一区二区三区在线播放| 亚洲精品影视| 久热成人在线视频| 一区二区不卡在线视频 午夜欧美不卡在 | 久久人91精品久久久久久不卡 | 国产精品国产三级国产专播品爱网| 国产一区二区福利| 欧美精品啪啪| 亚洲国产精品传媒在线观看| 中文精品视频| 免费av成人在线| 国产欧美在线播放| 一级成人国产| 亚洲高清123| 久久国产精品99国产| 国产精品久久网站| 一本色道久久综合精品竹菊| 久久婷婷麻豆| 亚洲一区亚洲二区| 欧美日韩在线一二三| 亚洲精品欧洲| 免费亚洲一区二区| 久久精品亚洲一区二区| 国产日韩欧美电影在线观看| 亚洲综合日韩在线| 9i看片成人免费高清| 欧美黄污视频| 日韩视频免费观看高清在线视频| 欧美成人午夜激情在线| 久久网站热最新地址| 国内自拍亚洲| 另类成人小视频在线| 久久国产成人| 黑人巨大精品欧美一区二区小视频| 亚洲综合国产激情另类一区| 国产精品99久久久久久白浆小说| 欧美日韩综合一区| 99在线精品观看| 99视频国产精品免费观看| 欧美日韩激情小视频| 亚洲一区在线播放| 亚洲一区二区三区在线视频| 国产精品免费一区二区三区观看| 午夜精品av| 亚洲综合另类| 国产一区清纯| 欧美韩国一区| 欧美三级日韩三级国产三级 | 欧美一级播放| 久久丁香综合五月国产三级网站| 国产一区在线观看视频| 蜜臀99久久精品久久久久久软件| 久久精品视频导航| 亚洲国产日韩欧美综合久久| 亚洲欧洲一区二区在线观看| 欧美日韩国产首页在线观看| 亚洲一区视频在线| 久久久久久久综合色一本| 亚洲国产欧美日韩| 一区二区三区视频在线| 国产在线国偷精品产拍免费yy| 欧美成人精品福利| 欧美视频在线观看一区| 久久久久久久综合色一本| 蜜臀久久99精品久久久久久9| 在线视频精品| 麻豆精品91| 欧美成人免费全部| 亚洲无限乱码一二三四麻| 亚洲天堂免费观看| 在线不卡欧美| 亚洲深夜影院| 黄色一区二区三区四区| 亚洲欧洲精品一区二区| 国产麻豆综合| 亚洲精品一区二区三区不| 国内精品久久久久影院 日本资源 国内精品久久久久伊人av | 亚洲午夜免费福利视频| 久久免费国产精品1| 亚洲国产精品久久久| 久久这里只精品最新地址| 久久精品在线| 欧美精品九九| 亚洲黄色成人久久久| 亚洲免费观看| 亚洲精品午夜| 国产真实乱子伦精品视频| 亚洲美女少妇无套啪啪呻吟| 伊大人香蕉综合8在线视| 一区二区国产日产| 亚洲人成亚洲人成在线观看图片| 午夜亚洲激情| 久久另类ts人妖一区二区| 亚洲国产高清aⅴ视频| 欧美成人精品h版在线观看| 国产精品久久久久久久第一福利| 欧美激情区在线播放| 国内精品美女在线观看| 一区二区三区毛片| 亚洲日本电影| 能在线观看的日韩av| 免费欧美视频| 国内精品久久久久久影视8| 亚洲视频久久| 午夜精品久久久久久久99黑人| 欧美日韩高清不卡| 亚洲人成在线观看网站高清| 亚洲国产黄色| 女人色偷偷aa久久天堂| 欧美电影专区| 亚洲区第一页| 欧美精品999| 亚洲美女精品成人在线视频| 亚洲精品四区| 欧美成人一区二区在线| 亚洲国产欧美在线人成| 亚洲精品久久7777| 欧美乱妇高清无乱码| 亚洲国产日韩欧美综合久久| 亚洲美女视频网| 欧美全黄视频| 亚洲精品自在久久| 亚洲无人区一区| 亚洲高清免费在线| 国产精品成人观看视频国产奇米| 夜夜嗨av一区二区三区中文字幕| 亚洲精品久久久久中文字幕欢迎你| 久久综合色播五月| 蜜桃av噜噜一区二区三区| 在线免费日韩片| 欧美黄色一区二区| 亚洲影视在线| 猛男gaygay欧美视频| 亚洲欧洲免费视频| 欧美日韩精品免费观看| 亚洲女人小视频在线观看| 久久欧美中文字幕| 亚洲日本乱码在线观看| 欧美三级网址| 久久精品国产久精国产思思| 亚洲高清在线观看| 亚洲欧美国产精品桃花| 国内视频精品| 蜜桃av综合| 一区二区三区波多野结衣在线观看| 午夜欧美精品| 亚洲精品国产精品国产自| 国产精品久久网站| 免费一级欧美片在线观看| 中文精品99久久国产香蕉| 欧美电影免费| 欧美专区在线播放| 99视频精品| 国产主播一区二区| 欧美伦理视频网站| 久久久久国产一区二区三区| 亚洲欧洲精品一区二区| 欧美一级大片在线观看| 亚洲日本电影| 亚洲成人在线| 国产一区二区日韩精品欧美精品| 欧美福利一区| 久久免费的精品国产v∧| 亚洲制服av| 一本一本久久a久久精品综合麻豆| 榴莲视频成人在线观看| 午夜精品一区二区三区四区| 日韩午夜av| 亚洲国产欧美一区二区三区久久 | 亚洲香蕉在线观看| 91久久在线播放| 在线观看成人av|