打标记后视频保存
VideoCapture cap(“D:\rec.avi”);
//计算视频帧数
int VedioFPS = cap.get(CV_CAP_PROP_FPS);
//cout << “视频帧率” << VedioFPS << endl;
// 保存视频
VideoWriter writer(“alarm.mp4”, CV_FOURCC(‘M’, ‘J’, ‘P’, ‘G’), VedioFPS, Size(ROI_Weidth, ROI_Height * 2));
if (!cap.isOpened())
{
cout << “Error opening video stream or file” << endl;
return -1;
}
Mat frame;
while (1) {
// Capture frame-by-frame
cap >> frame;
// If the frame is empty, break immediately
if (frame.empty()) break;
if (frame.channels() == 3) cvtColor(frame, frame, CV_RGB2GRAY);
//******************
// 处理图像
//******************
//在图像上打上标记
cvtColor(frame(roi_rect), ROIimg, CV_GRAY2RGB);
std::string str2 = “OriginalImage”;
cv::putText(ROIimg, str2, Point(roi_rect.width *0.5 - 20, 20), cv::FONT_HERSHEY_SIMPLEX, 0.3, cv::Scalar(0, 255, 255), 1);
cv::putText(ROIimg, “Load”, Point(0, 20), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 255), 1);
std::string str1 = “ImageProcessing”;
cv::putText(tempImg, str1, Point(roi_rect.width *0.5 - 30, 20), cv::FONT_HERSHEY_SIMPLEX, 0.3, cv::Scalar(0, 255, 255), 1);
vconcat(ROIimg, tempImg, conbine);
imshow(“Image”, conbine);
writer << conbine;
char c = (char)waitKey(1);
if (c == 27)
break;
}
cap.release();
destroyAllWindows();