文章目录
- 1.图像反转
- 2.图像旋转
- 3.摄像头使用
- 4.保存视频
1.图像反转
flip(image, dst, 0)
flip(image, dst, 1)
flip(image, dst, 1)
2.图像旋转
rotate_demo(Mat &image)
{
Mat dst;
double angle = 45;
Size image_size = image.size();
Size dst_sz(image_size.height, image_size.width);
int len = max(image.cols, image.rows);
Point2f center(len/2, len/2);
Mat rot_mat = getRotationMatrix2D(center, ange1, 1.0);
warpAffine(image, dst,rot_mat, dst_sz);
warpAffine(image, dst, rot_mat, dst_sz);
imshow("image",image);
imshow("dst",dst);
}
3.摄像头使用
video_demo_01(Mat &image)
{
VideoCapture capture(0);
Mat frame;
while(true)
{
capture.read(frame);
flip(frame, frame,1);
if(frame.empty())
{
break;
}
imshow("frame", frame);
int c = waitKey(10);
if(c == 27)
{
break;
}
}
}
4.保存视频
video_demo_02(Mat &image)
{
VideoCapture capture("../xx.mp4");
int frame_width = capture.get(CAP_PROP_FRAME_WIDTH);
int frame_height = capture.get(CAP_PROP_FRAME_HEIGHT);
int count = capture.get(CAP_PROP_FRAME_COUNT);
double fps = capture(CAP_PROP_FPS);
cout<<"frame_width:"<<frame_width<<endl;
cout<<"frame_height:"<<frame_height<<endl;
cout<<"frame_fps:"<<fps<<endl;
cout<<"frame_count:"<<count<<endl;
VideoWriter writer("../test.mp4", capture.get(CAP_PROP_FOURCC),fps, Size(frame_width, frame_height), ture);
Mat frame;
while(true)
{
capture.read(frame);
flip(frame, frame, 1);
if(frame.empty())
{
break;
}
imshow("frame", frame);
writer.write(frame);
}
capture.release();
writer.release();
}