OpenCV4下的图像任意角度的旋转

上传人:平*** 文档编号:12268335 上传时间:2017-10-17 格式:DOC 页数:4 大小:27.52KB
返回 下载 相关 举报
OpenCV4下的图像任意角度的旋转_第1页
第1页 / 共4页
OpenCV4下的图像任意角度的旋转_第2页
第2页 / 共4页
OpenCV4下的图像任意角度的旋转_第3页
第3页 / 共4页
OpenCV4下的图像任意角度的旋转_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《OpenCV4下的图像任意角度的旋转》由会员分享,可在线阅读,更多相关《OpenCV4下的图像任意角度的旋转(4页珍藏版)》请在金锄头文库上搜索。

1、/OpenCV 4 下的图像任意角度的旋转/待旋转的图像 IplImage* Img_old/返回的旋转后图像 IplImage* Img_tmp./旋转的角度,单位度./三种不同的方法.其中方法二没有完全测试, 方法一可以满足大部分需要/Vastsky - Nercita 2005 6 12 /vastsky_sun#IplImage * CCropMeasureView:FitRotate (IplImage* Img_old, double angle,int method) IplImage* Img_tmp = NULL; double anglerad = (CV_PI* (ang

2、le/180) ;int newheight =int (fabs( sin(anglerad)*Img_old-width ) + fabs( cos(anglerad)*Img_old-height ) );int newwidth =int (fabs( sin(anglerad)*Img_old-height) + fabs( cos(anglerad)*Img_old-width) );Img_tmp = cvCreateImage(cvSize(newwidth,newheight), IPL_DEPTH_8U, 3);cvFillImage(Img_tmp,0);/目的图像 使用

3、扩展的大小IplImage* dst = cvCloneImage( Img_old );/目的图像 与原图像等大 float m6; CvMat M = cvMat( 2, 3, CV_32F, m );if(1=method)/方法一 提取象素四边形,使用子象素精度int w = Img_old-width;int h = Img_old-height;m0 = (float)(cos(angle*CV_PI/180.);m1 = (float)(sin(angle*CV_PI/180.);m2 = w*0.5f;m3 = -m1;m4 = m0;m5 = h*0.5f;cvGetQuad

4、rangleSubPix( Img_old, dst, &M, 1, cvScalarAll(0); cvGetQuadrangleSubPix( Img_old, Img_tmp, &M, CV_INTER_LINEAR, cvScalarAll(0);/+CV_WARP_FILL_OUTLIERS/方法一 提取象素四边形,使用子象素精度if(2=method)/方法二 使用 二维旋转的仿射变换矩阵 存在问题 要求输入和输出图像一样大 旋转中心不对CvPoint2D32f center;center.x=float (Img_old-width/2.0+0.5);/float (Img_tm

5、p-width/2.0+0.5);center.y=float (Img_old-height/2.0+0.5);/float (Img_tmp-height/2.0+0.5); cv2DRotationMatrix( center, angle,1, &M);cvWarpAffine( Img_old, dst, &M,CV_INTER_LINEAR,cvScalarAll(0) );/小图/小目标图像/对图像进行扩展/ 只能一定角度以内 不同象限的不同对待int dx=int(newwidth -Img_old-width )/2+0.5);int dy=int(newheight-Img

6、_old-height)/2+0.5); uchar* old_ptr,*temp_ptr;for( int y=0 ; yheight; y+) /为了不越界 for (int x=0 ; xwidth; x+)old_ptr = &(uchar*)(Img_old-imageData + Img_old-widthStep*y)(x)*3;temp_ptr = &(uchar*)(Img_tmp-imageData + Img_tmp-widthStep*(y+dy)(x+dx)*3;temp_ptr0=old_ptr0; /green temp_ptr1=old_ptr1; /bluet

7、emp_ptr2=old_ptr2; /Red center.x=float (Img_tmp-width/2.0+0.5);center.y=float (Img_tmp-height/2.0+0.5); cv2DRotationMatrix( center, angle,1, &M);IplImage* temp = cvCloneImage( Img_tmp );/生成输出图像 cvWarpAffine( Img_tmp, temp , &M,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,cvScalarAll(0) );/大图Img_tmp=cvClone

8、Image( temp );/问题/cvWarpAffine( Img_tmp, Img_tmp, &M,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,cvScalarAll(0) );/大图/方法二 使用 二维旋转的仿射变换矩阵if(3=method)/方法三 透视变换CvPoint2D32f src_point4;CvPoint2D32f dst_point4;src_point0.x=0.0; src_point0.y=0.0;src_point1.x=0.0; src_point1.y=(float) Img_old-height; src_point2.

9、x=(float) Img_old-width; src_point2.y=(float) Img_old-height;src_point3.x=(float) Img_old-width; src_point3.y=0.0;dst_point0.x=0; dst_point0.y=(float) fabs( sin(anglerad)*Img_old-width );dst_point1.x=(float) fabs( sin(anglerad)*Img_old-height); dst_point1.y=(float) fabs( sin(anglerad)*Img_old-width

10、)+(float) fabs( cos(anglerad)*Img_old-height);dst_point2.x=(float) fabs( sin(anglerad)*Img_old-height)+(float) fabs( cos(anglerad)*Img_old-width);dst_point2.y=(float) fabs( cos(anglerad)*Img_old-height);dst_point3.x=(float) fabs( cos(anglerad)*Img_old-width);dst_point3.y=0; float newm9; CvMat newM =

11、 cvMat( 3, 3, CV_32F, newm );cvWarpPerspectiveQMatrix(src_point,dst_point,&newM);cvWarpPerspective(Img_old,dst,&newM,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0) );cvWarpPerspective(Img_old,Img_tmp,&newM,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0) );/方法三 透视变换/ cvNamedWindow( dst_litter, 1 );/ cvShowImage( dst_litter, dst );/ cvNamedWindow( dst_big, 1 );/ cvShowImage( dst_big, Img_tmp );return Img_tmp;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号