waitKey function TX1

Hello everybody,

I’m trying to use the waitKey function in an openCV program on my TX1. The program is very simple:

#include "opencv2/opencv.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;
 
int main(int, char**)
{
	
	VideoCapture video(0);

	Mat frame;
		
	while(1){

		video >> frame;

		imshow("video",frame);

		if(waitKey(1)=='q')
			break;
		
		}
    return 0;
}

It works normally on my PC, but not on the TX1, when I press ‘q’ nothing happens. Any Suggestion?

McSka,
When you press ‘q’, do you also hit ‘return’? Work for my test code.

Hello, McSka:
You need attach a USB keyboard to Jetson board, and run the openCV test program in the terminator with your keyboard, and keep the ‘video’ window as current active window. Then waitKey can get the key press event from your USB keyboard.

If you run the opencv app from terminal like SSH client, this will not work.

br
ChenJian

On my PC when I hit ‘q’ the program will be immediately interrupted, it is not necessary to hit also ‘return’, while on the TX1 even if I hit ‘q’ and then ‘return’ nothing happens.

I am using a keyboard, and I am aware that it is necessary to keep the “video” window as current active window. Anyway if you say that it does not work running the app fromm SSH I need to change direction. I start a new thread, thank you very much

Perhaps it is requiring a type cast. Because of other character encodings (such as UTF-8 or UTF-16) this function uses “int” as type. Many of the character handling functions also use “int”. However, ‘q’ is type const char. Try comparing to something like “static_cast(‘q’)” (I haven’t tried it, you may get the compiler complaining about const, in which case reinterpret_cast might work…YMMV).