惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - wqj1212

形态学处理 halcon学习笔记——(11)Image,region,xld初步 Halcon相机标定 Halcon标定步骤 Halcon学习标定助手 halcon学习之产品检测 halcon中variation_model_single实例注释. vc 实现打印功能 用VisualC++建立SOAP客户端应用(一) 第六章 - 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine) OpenCV】透视变换 Perspective Transformation(续) OpenCV仿射变换+投射变换+单应性矩阵 【最新图文教程】WinCE5.0中文模拟器SDK(VS2008)的配置 Visual Studio 2008 使用 WinCE 5.0 Emulator fff http://www.tugexing.com/Ad_doN.aspx?mmd=upM9swloFctgVHJiJa%2fj1w%3d%3d - wqj1212 VS2003打包時加入卸载功能 gggg C++日志库,log4cplus,log4cpp使用资料手册
第六章 - 图像变换 - 图像拉伸、收缩、扭曲、旋转[2] - 透视变换(cvWarpPerspective)
wqj1212 · 2014-08-15 · via 博客园 - wqj1212

透视变换(单应性?)能提供更大的灵活性,但是一个透视投影并不是线性变换,因此所采用的映射矩阵是3*3,且控点变为4个,其他方面与仿射变换完全类似,下面的例程是针对密集变换,稀疏图像变换则采用cvPerspectiveTransform函数来处理。

------------------------------------------------------------------------------------------------

WarpPerspective

对图像进行透视变换

void cvWarpPerspective( const CvArr* src, CvArr* dst,const CvMat* map_matrix,

                       int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,

                       CvScalar fillval=cvScalarAll(0) );

src

输入图像.

dst

输出图像.

map_matrix

3×3 变换矩阵

flags

插值方法和以下开关选项的组合:

·       CV_WARP_FILL_OUTLIERS- 填充所有缩小图像的象素。如果部分象素落在输入图像的边界外,那么它们的值设定为 fillval.

·       CV_WARP_INVERSE_MAP- 指定 matrix 是输出图像到输入图像的反变换,因此可以直接用来做象素插值。否则, 函数从 map_matrix 得到反变换。

fillval

用来填充边界外面的值

函数 cvWarpPerspective 利用下面指定矩阵变换输入图像:

  • 如果没有指定 CV_WARP_INVERSE_MAP , 
  • 否则, 

要变换稀疏矩阵,使用 cxcore 中的函数 cvTransform 。

-----------------------------

GetPerspectiveTransform

由四对点计算透射变换

CvMat* cvGetPerspectiveTransform( const CvPoint2D32f*src, const CvPoint2D32f* dst,

                                  CvMat*map_matrix );

#define cvWarpPerspectiveQMatrixcvGetPerspectiveTransform

src

输入图像的四边形顶点坐标。

dst

输出图像的相应的四边形顶点坐标。

map_matrix

指向3×3输出矩阵的指针。

函数cvGetPerspectiveTransform计算满足以下关系的透射变换矩阵:

这里,dst(i)= (x'i,y'i),src(i)= (xi,yi),i = 0..3.

------------------------------------------------------------------------------------------------

/*code*/

  1. #include <highgui.h>   
  2. #include <cv.h>   
  3.   
  4. int main(int argc, char** argv)  
  5. {  
  6.     CvPoint2D32f srcTri[4], dstTri[4]; 
  7.     
  8.     CvMat* warp_mat = cvCreateMat( 3, 3, CV_32FC1 );  
  9.     IplImage *src, *dst;  
  10.   
  11.     if( argc == 2 && ( ( src = cvLoadImage( argv[1], 1 ) ) != 0 ) )  
  12.     {  
  13.         dst = cvCloneImage( src );  
  14.         dst ->origin = src ->origin;    
  15.         
  16.         cvZero( dst );  
  17.   
  18.         
  19.         srcTri[0].x = 0;  
  20.         srcTri[0].y = 0;  
  21.         srcTri[1].x = src -> width - 1;  
  22.         srcTri[1].y = 0;  
  23.         srcTri[2].x = 0;  
  24.         srcTri[2].y = src -> height - 1;  
  25.         srcTri[3].x = src -> width - 1;  
  26.         srcTri[3].y = src -> height - 1;  
  27.   
  28.         
  29.         dstTri[0].x = src -> width * 0.05;  
  30.         dstTri[0].y = src -> height * 0.33;  
  31.         dstTri[1].x = src -> width * 0.9;  
  32.         dstTri[1].y = src -> height * 0.25;  
  33.         dstTri[2].x = src -> width * 0.2;  
  34.         dstTri[2].y = src -> height * 0.7;  
  35.         dstTri[3].x = src -> width * 0.8;  
  36.         dstTri[3].y = src -> height * 0.9;  
  37.   
  38.         cvGetPerspectiveTransform( srcTri, dstTri, warp_mat );  
  39.         cvWarpPerspective( src, dst, warp_mat );  
  40.   
  41.         
  42.         cvNamedWindow( "Perspective Warp", 1 );  
  43.         cvShowImage( "Perspective Warp", dst );  
  44.         cvWaitKey();  
  45.     }  
  46.     cvReleaseImage( &dst );  
  47.     cvReleaseMat( &warp_mat );  
  48.   
  49.     return 0;  
  50. }