opencv video delay

Solutions on MaxInterview for opencv video delay by the best coders in the world

showing results for - "opencv video delay"
Finn
30 Jun 2017
1#include <chrono>
2#include <thread>
3
4#include <opencv4/opencv2/highgui.hpp>
5
6static constexpr const char * const WINDOW = "1";
7
8void video_test() {
9    // It doesn't work properly without `drop=true` option
10    //make sure to have appsink buffer-list = false
11    cv::VideoCapture video("v4l2src device=/dev/video0 ! videoconvert ! videoscale ! videorate ! video/x-raw,width=640 ! appsink drop=true", cv::CAP_GSTREAMER);
12
13    if(!video.isOpened()) {
14        return;
15    }
16
17    cv::namedWindow(
18        WINDOW,
19        cv::WINDOW_GUI_NORMAL | cv::WINDOW_NORMAL | cv::WINDOW_KEEPRATIO
20    );
21    cv::resizeWindow(WINDOW, 700, 700);
22
23    cv::Mat frame;
24    const std::chrono::seconds sec(1);
25    while(true) {
26        if(!video.read(frame)) {
27            break;
28        }
29        std::this_thread::sleep_for(sec);
30        cv::imshow(WINDOW, frame);
31        cv::waitKey(1);
32    }
33}
34
similar questions
queries leading to this page
opencv video delay