您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/11/11 2:07:06发布12次查看
旋转视频与旋转图像类似。唯一的区别是我们不是将静态图片加载到图像矩阵中,而是加载了视频或从相机获取视频流。
这里,我们不是加载视频,而是使用相机拍摄视频。如果要使用视频文件,只需正确输入视频文件的地址即可。
以下程序演示了如何使用c++在opencv中旋转视频。
示例 h2>#include<iostream>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>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中旋转视频?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product