Thursday, January 19th, 2012, 34 days ago
The error of ‘VIDIOC_QUERYMENU: Invalid argument’
When I was writing a simple example of OpenCV below, an repeating error happened as ‘VIDIOC_QUERYMENU:Invalid argument’.
Is this because the Qt for drawing the output of openCV?
The code
The code that caused the above error is like this:
#include “opencv2/core/core.hpp”
#include “opencv2/imgproc/imgproc.hpp”
#include “opencv2/video/video.hpp”
using namespace cv;
//
#include
using namespace std;
//
int main(int argc, char *argv[])
{
VideoCapture cap(0);
Mat frame;
for(;;)
{
cap >> frame;
imshow(“frame”,frame);
if(waitKey(30) == 27) break;
}
return 0;
}
The error happened when initialising the webcam, but the webcam was working fine even though the errors were given in the console window.
The fix
From a post from stackoverflow, this problem was
with Qt handling its own event loop and thus the event loop of OpenCV is starved and never get run.
The way to get them to work together is quite simple: Display your OpenCV as a QPixmap (by convert your image to QImage then use QLabel to display it). Then add this QLabel to your QWidget. Your QWidget can either be embedded or become the main widget of your QApplication.
But it may not be so easy to get rid of, as other posts also mentioned that
You can’t mix openCV’s control of the event loop and qt’s app.exec
Either use the Qt flavour of the cvNamedWindow, or simple grab images from openCV and display them in a QLabel. Or better inherit from QWidget and write your own QImage painter
void OpencvWidget::paintEvent(QPaintEvent*)
{
//m_win is the window size
QPainter p(this);
p.drawImage(m_win,m_image,m_image.rect());}
The best way to fix ‘VIDIOC_QUERYMENU:Invalid argument’
I have faced a similar problem recently (displaying webcam information using OpenCV and Qt as the final GUI). The best way that I find out to play the video (which is basically a set of images) is to use a GLWidget.
POSTS MAY BE OF INTEREST
- Happy Chinese New Year of Dragon!!!
- Breaking Asus Xtion pro into parts
- Installing OpenNI for Linux-ARM in Ubuntu Pandaboard
- Merry Xmas and Happy New Year 2012
- A successful way to disable all WordPress’s auto-saves and revisions
- Say goodbye to slow-(Go)daddy
- The sun set
- Backyard’s flowers
- Mapping object positions to mouse coordinates in openCV
- Cherry trees flowering
- New office new start
- An example of detecting object motions using openCV
- Another open library for object detections and recognitions – aforge.net
- Happy new year 2011
- Building projects in openCV 2.0
