这里,我们不是加载视频,而是使用相机拍摄视频。如果要使用视频文件,只需正确输入视频文件的地址即可。
以下程序演示了如何使用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中旋转视频?的详细内容。
