OpenCV Tutorials —— Remapping

來源:互聯網
上載者:User

標籤:des   style   http   io   ar   os   sp   for   strong   

重新導向,也就是把映像中的像素從一個地方對應到另一個地方

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.

會涉及到插值 ~~ 可能像素點不是一一對應

 

程式中的四種處理方式

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

    for all pairs such that: and   縮放一半並將映像置於視窗中心

  2. 2,Turn the image upside down:

  3. 3,Reflect the image from left to right:

  4. 4,Combination of b and c:

 

remap

void remap(InputArray src, OutputArray dst, InputArray map1, InputArray map2, int interpolation, intborderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())

Parameters:

  • src – Source image.
  • dst – Destination image. It has the same size as map1 and the same type as src .
  • map1 – The first map of either (x,y) points or just x values having the type CV_16SC2 , CV_32FC1, or CV_32FC2 . See convertMaps() for details on converting a floating point representation to fixed-point for speed.
  • map2 – The second map of y values having the type CV_16UC1 , CV_32FC1 , or none (empty map ifmap1 is (x,y) points), respectively.
  • interpolation – Interpolation method (see resize() ). The method INTER_AREA is not supported by this function.
  • borderMode – Pixel extrapolation method (see borderInterpolate() ). WhenborderMode=BORDER_TRANSPARENT , it means that the pixels in the destination image that corresponds to the “outliers” in the source image are not modified by the function.
  • borderValue – Value used in case of a constant border. By default, it is 0.

 

 

Code

#include "stdafx.h"#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( "zanxin.jpg", 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++;}

 

重點是構造 x,y座標的map,用來映射像素點 ~~

OpenCV Tutorials —— Remapping

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.