问题描述:
如题
问题原因:
其实就是保存的帧如果处理成灰度图(单通道)的话,保存为新视频,则新视频读取不了
解决办法:
处理成三通道,保存的新视频即可被读取
代码:
VideoCapture inputVideo("/home/jason/work/01-img/红外/test.mp4");
int width = static_cast<int>(inputVideo.get(CAP_PROP_FRAME_WIDTH));
int height = static_cast<int>(inputVideo.get(CAP_PROP_FRAME_HEIGHT));
double fps = inputVideo.get(cv::CAP_PROP_FPS);
VideoWriter outputVideo("/home/jason/work/01-img/红外/test_DDE.mp4",
VideoWriter::fourcc('m', 'p', '4', 'v'),
double(1000/fps),
cv::Size(width, height));
Mat frame, result;
while (true){
inputVideo >> frame;
if (frame.empty())
break;
cv::cvtColor(frame, frame, cv::COLOR_BGR2GRAY);
DDE(frame, result);
cv::cvtColor(result, result, cv::COLOR_GRAY2BGR);// 必须转为3通道,否则保存的新视频读取不了
outputVideo.write(result);
imshow("input", frame);
imshow("output", result);
if (waitKey(30) == 'q')
break;
}
inputVideo.release();
outputVideo.release();