博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
旋转测试
阅读量:7105 次
发布时间:2019-06-28

本文共 1928 字,大约阅读时间需要 6 分钟。

#include 
#include
#include
#include "opencv2/opencv.hpp"using namespace std;using namespace cv;bool rotation(Mat &in, Mat &out, const Size rect_size, const Point2f center, const double angle) { if (1) { imshow("in", in); waitKey(0); //destroyWindow("in"); } Mat in_large; in_large.create(int(in.rows * 1.5), int(in.cols * 1.5), in.type()); float x = in_large.cols / 2 - center.x > 0 ? in_large.cols / 2 - center.x : 0; float y = in_large.rows / 2 - center.y > 0 ? in_large.rows / 2 - center.y : 0;//相对于in_large in的tl点坐标 float width = x + in.cols < in_large.cols ? in.cols : in_large.cols - x; float height = y + in.rows < in_large.rows ? in.rows : in_large.rows - y; /*assert(width == in.cols); assert(height == in.rows);*/ if (width != in.cols || height != in.rows) return false; Mat imageRoi = in_large(Rect_
(x, y, width, height)); addWeighted(imageRoi, 0, in, 1, 0, imageRoi); Point2f center_diff(in.cols / 2.f, in.rows / 2.f); Point2f new_center(in_large.cols / 2.f, in_large.rows / 2.f); Mat rot_mat = getRotationMatrix2D(new_center, angle, 1); imshow("in_copy", in_large); waitKey(0); Mat mat_rotated; warpAffine(in_large, mat_rotated, rot_mat, Size(in_large.cols, in_large.rows), CV_INTER_CUBIC); imshow("mat_rotated", mat_rotated); waitKey(0); Mat img_crop; getRectSubPix(mat_rotated, Size(rect_size.width, rect_size.height), new_center, img_crop); out = img_crop; if (0) { imshow("out", out); waitKey(0); //destroyWindow("out"); } imshow("img_crop", img_crop); waitKey(0); return true;}int main(){ Mat test = imread("./t.png"); //imshow("test", test); Mat out; Point2f center_diff(test.cols / 2.f, test.rows / 2.f); rotation(test, out, test.size(), center_diff, -30.f); return 0;}

  

转载于:https://www.cnblogs.com/fdd566/p/6519448.html

你可能感兴趣的文章
linux网络相关配置
查看>>
他们如何利用微信赚钱
查看>>
安装配置cacti
查看>>
oracle linux6操作系统oracle11.2.0.4数据库从一台主机A(ora11g)到另一台主机B(ora02)的迁移过程...
查看>>
分享21个超棒的单页面网站设计
查看>>
HTML5发展历史信息图 - 帮助你更形象化的了解HTML5历史
查看>>
我的思科之路
查看>>
Android Design
查看>>
使用pure-ftpd搭建ftp服务
查看>>
交换机相关
查看>>
RSA的数学及算法实现
查看>>
Spark中narrow dependency和wide dependency
查看>>
【尖端干货】H.264编码下直播视频添加水印的优化
查看>>
maildir 邮件文件名 记录
查看>>
在线模拟HTTP请求
查看>>
如何对压缩文件设置解压密码
查看>>
Linux运维学习之LNMP搭建"小米商城"
查看>>
#if #ifdef使用小记
查看>>
2.1/2.2系统目录结构 2.3 ls命令 2.4文件类型 2.5 alias命令
查看>>
KVM虚拟机管理程序(转)
查看>>