From db5b22e89549687dfd28dc3f9005545df4c96f9b Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 17 Jun 2022 12:48:30 +0100 Subject: [PATCH] Merge pull request #22065 from cpoerschke:3.4-apps-visualisation-configurable-codec * apps/opencv_visualisation: configurable video codec * Update apps/visualisation/opencv_visualisation.cpp --- apps/visualisation/opencv_visualisation.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/visualisation/opencv_visualisation.cpp b/apps/visualisation/opencv_visualisation.cpp index be540efa62..85e9697aad 100644 --- a/apps/visualisation/opencv_visualisation.cpp +++ b/apps/visualisation/opencv_visualisation.cpp @@ -86,6 +86,9 @@ int main( int argc, const char** argv ) "{ image i | | (required) path to reference image }" "{ model m | | (required) path to cascade xml file }" "{ data d | | (optional) path to video output folder }" + "{ ext | avi | (optional) output video file extension e.g. avi (default) or mp4 }" + "{ fourcc | XVID | (optional) output video file's 4-character codec e.g. XVID (default) or H264 }" + "{ fps | 15 | (optional) output video file's frames-per-second rate }" ); // Read in the input arguments if (parser.has("help")){ @@ -96,7 +99,9 @@ int main( int argc, const char** argv ) string model(parser.get("model")); string output_folder(parser.get("data")); string image_ref = (parser.get("image")); - if (model.empty() || image_ref.empty()){ + string fourcc = (parser.get("fourcc")); + int fps = parser.get("fps"); + if (model.empty() || image_ref.empty() || fourcc.size()!=4 || fps<1){ parser.printMessage(); printLimits(); return -1; @@ -166,11 +171,19 @@ int main( int argc, const char** argv ) // each stage, containing all weak classifiers for that stage. bool draw_planes = false; stringstream output_video; - output_video << output_folder << "model_visualization.avi"; + output_video << output_folder << "model_visualization." << parser.get("ext"); VideoWriter result_video; if( output_folder.compare("") != 0 ){ draw_planes = true; - result_video.open(output_video.str(), VideoWriter::fourcc('X','V','I','D'), 15, Size(reference_image.cols * resize_factor, reference_image.rows * resize_factor), false); + result_video.open(output_video.str(), VideoWriter::fourcc(fourcc[0],fourcc[1],fourcc[2],fourcc[3]), fps, visualization.size(), false); + if (!result_video.isOpened()){ + cerr << "the output video '" << output_video.str() << "' could not be opened." + << " fourcc=" << fourcc + << " fps=" << fps + << " frameSize=" << visualization.size() + << endl; + return -1; + } } if(haar){