Using cv::waitKey without having to call cv::namedWindow or cv::imshow first
I am writing a GUI program using Qt and doing some video processing with OpenCV. I am displaying the result of the OpenCV process (which is in a separate thread) in a label in the main GUI thread.
The problem I am having is cv::waitKey doesn't work unless I open a native OpenCV window opened using cv::namedWindow or cv::imshow. Does anybody know how to solve this?
Short example:
void Thread::run()
{
//needed variables
cv::VideoCapture capture(0);
cv::Mat image;
//main loop
//cv::namedWindow("test");
forever
{
capture>> image;
if(!image.data)
break;
emit paintToDisplay(convertToQImage(image));
cv::waitKey(40);
}
}
With //cv::namedWindow("test");
ie commented, the program crashes with access violation error.
With cv::namedWindow("test");
ie uncommented, the program displays perfect but there's a window (named test) I don't want or need. Anybody?
cv::waitKey()
only works with OpenCV windows, which is not what you are using right now.
I suggest you investigate a QT alternative, most probably qSleep()
, which is provided by the QTest module:
QTest::qSleep(40);
I found a solution to use msleep()
. It's easy to use since it's a member of the class QThread
.
Just thought i'd update this in case someone with a similar problem finds this thread.
链接地址: http://www.djcxy.com/p/95060.html上一篇: cvWaitKey()显着减缓捕获过程