Ask Your Question
0

waitkey() does not return the value of the character pressed

asked 2015-07-09 06:52:40 -0500

Katrina_V gravatar image

The code below does not pause indefinitely. Instead prints the '-1' indefinitely. Please help.

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;

int main(){

    int ch;

    while (1)
    { 
        ch = waitKey(0);
        cout << ch << endl;
    }
    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2015-07-09 07:22:33 -0500

LBerger gravatar image

updated 2015-07-09 07:22:59 -0500

I think problem is written in doc

Note

The function only works if there is at least one HighGUI window created and the window is active. If there are several HighGUI windows, any of them can be active.

edit flag offensive delete link more

Comments

Thanks a lot! :) !! It works when I create a window using namedWindow() beforehand.

Katrina_V gravatar imageKatrina_V ( 2015-07-09 08:03:16 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-07-09 06:52:40 -0500

Seen: 2,232 times

Last updated: Jul 09 '15