diff --git a/recipes-vision/visionhellocc/files/src/main.cc b/recipes-vision/visionhellocc/files/src/main.cc index 97de3c813aadb6c11a42164e7dcb50ef59ca55a6..689eb4ccad934ff244a18e93546e5723aa2fb0b5 100644 --- a/recipes-vision/visionhellocc/files/src/main.cc +++ b/recipes-vision/visionhellocc/files/src/main.cc @@ -2,51 +2,122 @@ #include <opencv2/opencv.hpp> #include <iostream> +#include <unistd.h> +#include <getopt.h> +#include <string> + +std::string gst_pipeline = "libcamerasrc ! " + "video/x-raw,framerate=50/1,width=640,height=480 !" + "videoscale ! videoconvert ! appsink"; +std::string output_filename = "out.avi"; +int frames_to_cap = 50; +int fps = 25; +bool quiet = false; int -main(void) { - cv::VideoCapture cap("libcamerasrc ! " - "video/x-raw,framerate=50/1,width=640,height=480 !" - "videoscale ! videoconvert ! appsink", - cv::CAP_GSTREAMER); +main(int argc, char *argv[]) { + + static struct option long_options[] = { + {"output", required_argument, 0, 'o'}, + {"frames", required_argument, 0, 'f'}, + {"fps", required_argument, 0, 'F'}, + {"pipeline", required_argument, 0, 'p'}, + {"quiet", no_argument, 0, 'q'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0 } + }; + int opt, option_index = 0; + while ((opt = getopt_long(argc, argv, "o:f:F:p:vh", long_options, &option_index)) != -1) { + switch (opt) { + case 'o': + output_filename = optarg; + break; + case 'f': + frames_to_cap = std::stoi(optarg); + break; + case 'F': + fps = std::stoi(optarg); + break; + case 'p': + gst_pipeline = optarg; + case 'q': + quiet = true; + break; + case 'h': + case '?': + std::cerr << "Usage: " << argv[0] << " options" << std::endl + << "Options:" << std::endl + << " -o, --output output filename (default: out.avi)" << std::endl + << " -f, --frames frames to capture (default: 50)" << std::endl + << " -F, --fps output frames per second (default: 25)" << std::endl + << " -p, --pipeline gstreamer pipeline (default: <<PipelineEOF " << std::endl + << " libcamerasrc ! " << std::endl + << " video/x-raw,framerate=50/1,width=640,height=480 !" << std::endl + << " videoscale ! videoconvert ! appsink" << std::endl + << " PipelineEOF)" << std::endl + << " -q, --quiet try to keep quiet" << std::endl + << " -h, --help show this help" << std::endl; + return 0; + default: + std::cerr << "Bad argument" << std::endl << "Usage: " << argv[0] + << " [-o output_file] [-f frames_to_capture] [-F output_fps]" << std::endl + << " [-p gst_pipeline] [-q] [-h]" << std::endl; + return 1; + } + } + + cv::VideoCapture cap(gst_pipeline, cv::CAP_GSTREAMER); if (!cap.isOpened()) { std::cerr << "Error: Could not open video stream." << std::endl; - return -1; + return 1; } int frame_width = static_cast<int>(cap.get(cv::CAP_PROP_FRAME_WIDTH)); int frame_height = static_cast<int>(cap.get(cv::CAP_PROP_FRAME_HEIGHT)); cv::Size size(frame_width, frame_height); - std::cout << "Frame size: " << size << std::endl; + if (!quiet) { + std::cout << "Frame size: " << size << std::endl; + } - cv::VideoWriter result("file.avi", - cv::VideoWriter::fourcc('M','J','P','G'), - 10, - size); + cv::VideoWriter result(output_filename, cv::VideoWriter::fourcc('M','J','P','G'), + fps, size); if (!result.isOpened()) { std::cerr << "Error: Could not open the output video file." << std::endl; - return -1; + return 1; } - for (int x = 0; x < 50; ++x) { + if (!quiet) { + std::cout << "Recording..." << std::endl; + std::cout << "Captured frames: "; + } + for (int x = 0; x < frames_to_cap; ++x) { cv::Mat frame; bool ret = cap.read(frame); if (!ret) { - std::cerr << "Error: Could not read frame." << std::endl; + std::cerr << std::endl << "Error: Could not read frame." << std::endl; break; } result.write(frame); - std::cout << "Captured frame " << x << std::endl; + if (!quiet) { + std::cout << x << " "; + } } - std::cout << "Completed." << std::endl; + if (!quiet) { + std::cout << "capture completed." << std::endl; + std::cout << "Releasing output and capture..." << std::endl; + } result.release(); cap.release(); + + if (!quiet) { + std::cout << "Completed." << std::endl; + } return 0; diff --git a/recipes-vision/visionhellocc/files/visionhellocc-1.0.tar.gz b/recipes-vision/visionhellocc/files/visionhellocc-1.0.tar.gz index 17c3352603e038af1b69a73d45348d69c1ab5086..8ed3ea01dc0fe24a55f40c697bfc2ac632c6d795 100644 Binary files a/recipes-vision/visionhellocc/files/visionhellocc-1.0.tar.gz and b/recipes-vision/visionhellocc/files/visionhellocc-1.0.tar.gz differ