cv::waitKey doesn't respond to keypress (Bug #278)
Description
waitKey(1000) doesn't return after pressing a key (and <cr>).
Associated revisions
Merge pull request #278 from taka-no-me:fix_build_jpeg9
Merge pull request #278 from mshabunin:add_videoio_perf_data
History
Updated by Gary Bradski almost 15 years ago
- Status deleted (
Open)
Updated by Vadim Pisarevsky almost 15 years ago
The following sample works great on Ubuntu x64 9.10 with OpenCV built with GTK+ support.
===
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
using namespace cv;
int main(int, char**)
{
printf("press any key within 1 second\n");
namedWindow("test", 0);
int c = waitKey(1000);
printf("%d\n", c);
return 0;
}
===
I see 2 possible reasons of why you get this problem:
1. no window was created. waitKey() only works when there is at least one highgui window and the window is active.
2. key code of <Return> key is 10 ('\n'), while you might have checked for 13 instead.
If the problem is still there, please, reopen the ticket and, if possible, supply an example or more information.
- Status set to Done
- (deleted custom field) set to worksforme
Updated by Vadim Pisarevsky almost 15 years ago
here is improved sample that proves that the real delay is shorter when a key is pressed:
===
#include "cv.h" // include standard OpenCV headers, same as before
#include "highgui.h"
#include <stdio.h>
using namespace cv; // all the new API is put into "cv" namespace. Export its content
int main(int, char**)
{
printf("press any key within 1 second\n");
namedWindow("test", 0);
double t = (double)getTickCount();
int c = waitKey(1000);
t = (double)getTickCount() - t;
printf("delay = %g msec, key code = %d\n", t*1000./getTickFrequency(), c);
return 0;
}
===
Updated by Anonymous almost 15 years ago
Please add info in the docs that the keypress has to take place when the highgui window is in focus.
Updated by Vadim Pisarevsky almost 15 years ago
the note about the focus has been added in r3013
Updated by Andrey Kamaev over 12 years ago
- Category changed from highgui-images to highgui-gui