将Opencv Matrix旋转90,180,270度 [英] Rotate Opencv Matrix by 90, 180, 270 degrees
本文介绍了将Opencv Matrix旋转90,180,270度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从网络摄像头捕获图像,我需要旋转它的直角。我发现自己的函数:
-
getRotationMatrix2D
- 创建旋转矩阵is) -
transform
- 通过旋转矩阵将一个矩阵转换为另一个矩阵
但是,除了黑色区域,我别无选择。这是我的代码:
if(rotate_button.click%4> 0){
double angle =(rotate_button。点击%4)* 90; //按钮每点击增加1点击
Mat transform_m = getRotationMatrix2D(Point(cam_frame_width / 2,cam_frame_height / 2),angle,1); //创建旋转矩阵
Mat current_frame;
transform(cam_frame,current_frame,transform_m); //将捕获的图像转换为新的图像
cam_frame = Mat((int)current_frame.cols,(int)current_frame.rows,cam_frame_type)= Scalar(0,128,0); //调整捕获的矩阵大小,所以我可以复制调整大小的一个
current_frame.copyTo(cam_frame); // Copy size to original
}
只输出黑屏。
解决方案
使用warpAffine:
尝试:
Point2f src_center(source.cols / 2.0F,source.rows / 2.0F);
Mat rot_mat = getRotationMatrix2D(src_center,angle,1.0);
Mat dst;
warpAffine(source,dst,rot_mat,source.size());
dst
>
I'm capturing image from webcam and I need to rotate it by right angle. I found myself theese functions:
getRotationMatrix2D
- to create rotation matrix (whatever it is)transform
- transform one matrix to another by rotation matrix
But, I don't get anything but black area. This is my code:
if(rotate_button.click%4>0) {
double angle = (rotate_button.click%4)*90; //button increments its click by 1 per click
Mat transform_m = getRotationMatrix2D(Point(cam_frame_width/2, cam_frame_height/2), angle, 1); //Creating rotation matrix
Mat current_frame;
transform(cam_frame, current_frame, transform_m); //Transforming captured image into a new one
cam_frame = Mat((int)current_frame.cols,(int)current_frame.rows, cam_frame_type) = Scalar(0,128,0); //resizing captured matrix, so I can copy the resized one on it
current_frame.copyTo(cam_frame); //Copy resized to original
}
Outputs just black screen.
解决方案
Use warpAffine.:
Try:
Point2f src_center(source.cols/2.0F, source.rows/2.0F);
Mat rot_mat = getRotationMatrix2D(src_center, angle, 1.0);
Mat dst;
warpAffine(source, dst, rot_mat, source.size());
dst
is the final image
这篇关于将Opencv Matrix旋转90,180,270度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文