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 that caused the above error is like this:
using namespace cv;
using namespace std;
int main(int argc, char *argv)
cap >> frame;
if(waitKey(30) == 27) break;
The error happened when initialising the webcam, but the webcam was working fine even though the errors were given in the console window.
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 paintervoid OpencvWidget::paintEvent(QPaintEvent*)
//m_win is the window size
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.
4 Comments On “ The error of ‘VIDIOC_QUERYMENU: Invalid argument’”