opencvC++图片旋转任意角度

更新时间:2023-06-23 06:36:36 阅读: 评论:0

aa.gif
}//end el
return 0;
郑州室内设计学校}
int rotateImage2(const cv::Mat &src, cv::Mat &dst, const double angle, const int mode)
{
//mode = 0 ,Keep the original image size unchanged
//mode = 1, Change the original image size to fit the rotated scale, padding with zero
if (pty())
{
std::cout << "Damn, the input image is empty!\n";
return -1;
暑期班
和风日语论坛}
if (mode == 0)
{
cv::Point2f center((ls - 1) / 2.0, (ws - 1) / 2.0);
cv::Mat rot = cv::getRotationMatrix2D(center, angle, 1.0);
cv::warpAffine(src, dst, rot, src.size());//the original size
}
el {
double alpha = -angle * CV_PI / 180.0;//convert angle to radian format
cv::Point2f srcP[3];
cv::Point2f dstP[3];
srcP[0] = cv::Point2f(0, ws);
srcP[1] = cv::ls, 0);
srcP[2] = cv::ls, ws);
//rotate the pixels
for (int i = 0; i < 3; i++)
dstP[i] = cv::Point2f(srcP[i].x*cos(alpha) - srcP[i].y*sin(alpha), srcP[i].y*cos(alpha) + srcP[i].x*sin(alpha));        double minx, miny, maxx, maxy;
minx = std::min(std::min(std::min(dstP[0].x, dstP[1].x), dstP[2].x), float(0.0));
miny = std::min(std::min(std::min(dstP[0].y, dstP[1].y), dstP[2].y), float(0.0));
maxx = std::max(std::max(std::max(dstP[0].x, dstP[1].x), dstP[2].x), float(0.0));
maxy = std::max(std::max(std::max(dstP[0].y, dstP[1].y), dstP[2].y), float(0.0));
中英文字典
int w = maxx - minx;
int h = maxy - miny;
cv::Mat warpMat =cv::Mat::zeros(cv::Size(3,2),CV_64F);//rows=2,cols=3
std::cout << pe() << std::endl;
std::cout << warpMat.size()<<std::endl;
warpMat.at<double>(0, 0) = cos(alpha);
exoticwarpMat.at<double>(0, 1) = 0- sin(alpha);
warpMat.at<double>(1, 0) = sin(alpha);
warpMat.at<double>(1, 1) = cos(alpha);
warpMat.at<double>(0, 2) =0- minx;
toastmaster
warpMat.at<double>(1, 2) =0-miny;
//std::cout << warpMat;
cv::warpAffine(src, dst, warpMat, cv::Size(w, h));//extend size
}//end el
return 0;
}
int main()
{
アップデート
overallstd::cout << "Hello World!\n";remilia
std::string filePath = "K:\\imageData\\lena\\images.png";
cv::Mat src = cv::imread(filePath);
cv::Mat dst1,dst2;
for (double i = -360; i <= 360; i++)
{
int flg1 = rotateImage(src, dst1, i, 0);
int flg2 = rotateImage(src, dst2, i, 1);
lesbians

本文发布于:2023-06-23 06:36:36,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1019153.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:郑州   室内设计   学校
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图