waitKey(1) freezes display output, is there a fix?

asked 2019-12-12 02:39:08 -0600

Glychee gravatar image

updated 2019-12-12 03:21:17 -0600

I'm using opencv(4.1.2) with ubuntu(18.04), as I understand my build uses GTK, so it uses that libraries function for reading the keypresses?

My problem now is that when you hold a key down, the frames no longer get drawn on screen. I suspect this has to do with waitkey not getting enough time to do the drawing, but how do you go about solving this?

The reason I want this is to control parameters using key inputs but having a freeze happen when sending many inputs is not preferable.

The code is as follows:

//basic needed classes
#include <iostream>
#include <string>

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/opencv.hpp>
#include "opencv2/imgcodecs.hpp"


using namespace cv;

Mat currentFrame; 

int main(){
    //create gstreamer rtspsrc pipe
    std::string pipe =  "rtspsrc location=rtsp://192.168.1.113:554/user=admin_password=_channel=1_OSD_stream=1.sdp latency=0 ! decodebin ! videoconvert ! appsink "; 
    VideoCapture cap = cv::VideoCapture(pipe, cv::CAP_GSTREAMER);

    while(true){
        cap.grab();
        cap.retrieve(currentFrame);
        cv::imshow("out", currentFrame);
        waitKeyEx(1);
    }
    return 0;
}
edit retag flag offensive close merge delete

Comments

could you show your code ?

berak gravatar imageberak ( 2019-12-12 02:43:47 -0600 )edit
1

I've distilled my code down to the basic things i do and added it, when i hold the keypress down it seems to stop on the current frame and then takes a while to clear the buffer(?) before it can resume

Glychee gravatar imageGlychee ( 2019-12-12 02:50:27 -0600 )edit

I've updated it again to make it compilable. this is the full code with which i can generate an executable and get the behaviour.

Glychee gravatar imageGlychee ( 2019-12-12 03:06:33 -0600 )edit
1

And finally, here's my build-info in case you needed that too https://pastebin.com/THtLdTBd

Glychee gravatar imageGlychee ( 2019-12-12 03:21:10 -0600 )edit
supra56 gravatar imagesupra56 ( 2019-12-12 04:20:07 -0600 )edit

I'm already using waitKeyEx(), if I use waitKeyEx(0) the frames won't get drawn unless I hold down a keypress, but holding down a keypress for too long freezes the display.

Glychee gravatar imageGlychee ( 2019-12-12 04:48:58 -0600 )edit