C++视频读取与视频保存
VideoCapture cap("E:\\122.avi"); //计算视频帧数 int VedioFPS = cap.get(CV_CAP_PROP_FPS); //cout << "视频帧率" << VedioFPS << endl; // 保存视频 VideoWriter writer("LoadBeltTear.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, "LoadBelt", 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("拼接", conbine); writer << conbine; char c = (char)waitKey(1); if (c == 27) break; } cap.release(); destroyAllWindows();
从视频文件中读取视频,对单帧图像进行相关处理,将处理后的图像整理成视频
posted on 2019-12-02 09:11 wangxiaobei2019 阅读(4077) 评论(0) 编辑 收藏 举报