如何使用C++在OpenCV中旋转视频?

2023年 9月 7日 37.3k 0

旋转视频与旋转图像类似。唯一的区别是我们不是将静态图片加载到图像矩阵中,而是加载了视频或从相机获取视频流。

这里,我们不是加载视频,而是使用相机拍摄视频。如果要使用视频文件,只需正确输入视频文件的地址即可。

以下程序演示了如何使用C++在OpenCV中旋转视频。

示例 H2>

#include
#include
#include
using namespace std;
using namespace cv;
int main(int argc, char* argv[]) {
VideoCapture loadvideo(0);//capture video from default camera//
namedWindow("OriginalVideo");//declaring window to show original video stream//
namedWindow("RotatedVideo");//declaring window to show rotated video stream//
int rotating_angle = 180;//initial rotation angle//
createTrackbar("Rotation", "RotatedVideo", &rotating_angle, 360);//creating trackbar for rotation//
while (true) {
Mat before_Rotating;//declaring matrix for image before rotation//
bool temp = loadvideo.read(before_Rotating);//load frames from video source to matrix//
imshow("OriginalVideo", before_Rotating);//show image frames before rotation//
Mat for_Rotation = getRotationMatrix2D(Point(before_Rotating.cols / 2, before_Rotating.rows / 2), (rotating_angle - 180), 1);//affine transformation matrix for the 2D rotation//
Mat after_Rotating;//declaring matrix for image after rotation//
warpAffine(before_Rotating, after_Rotating, for_Rotation, before_Rotating.size());//applying affine transformation//
imshow("RotatedVideo", after_Rotating);//show image after rotating//
if (waitKey(30) == 27){ //wait till Esc key is pressed from keyboard//
break;
}
}
return 0;
}

登录后复制

输出

如何使用C++在OpenCV中旋转视频?

以上就是如何使用C++在OpenCV中旋转视频?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论