About Qt QImage::Format and OpenCV
Environment : Lenovo notepad-PC Y430P, Win10 64bit, Qt5.10.0, Visual Studio2017, OpenCV3.4.0 / Python3.6, opencv_python3.3.1
Scenario: Programming in Python, face recognition in image and video, everything is OK, using notepad-PC's own camera. However programming in Qt, recognition in image is OK, problem occurs in video.
can = cvCreateCameraCapture(-1);return a address pointer, pretend it return right.
pFrame = cvQueryFrame(cam);but this function return NULL! Why can not get frame from video steam? It is a question about opencv, I hope anyone can answer in Qt forum, lucky enough. ^_^
#2 I think it maybe something wrong with the notepad-PC own camera, so I use USB camera, in this way
pFrame = cvQueryFrame(cam);return non-NULL, I display the image in graphics view, but all gray. Code:
pFrame = cvQueryFrame(cam); QImage image((const uchar *)pFrame->imageData, pFrame->width, pFrame->height, QImage::Format_RGB888); QGraphicsScene *scene = new QGraphicsScene; scene->addPixmap(QPixmap::fromImage(image)); ui.graphicsView->setScene(scene); ui.graphicsView->show();
Maybe the format is wrong, but I have trid all the variable
QImage::Format_***no one is right, How to distinguish format of image, in another way, when I use
QImage::Format_RGB888, when I use other? I hope someone can tell me or provide some information link.
Did you check the format of the camera video stream ? You might have to convert it first before doing something with it with Qt.
Sorry, last week I was busy with work, have no time to learn Qt, so even though I saw your comment, I did not respond to you.
Today I have tried the example in Qt install path, the program can find two camera: notepad-PC own camera and USB camera, and successfully show the video when I choose each one.
The USB camera is an old one, I can not find its instructions, how can I get the format of the video stream? Is there any function in Qt can get the video format?
I use the software in Windows 10 - Camera to record, the files of two camera are all .mp4. Is mp4 is the video format? And is right to use
I have so much questions, and hope you can answer patiently, thanks very very very much!
Ok, so now what are you using to get the image from your camera ?
You can operate a colourspace conversion with OpenCV so that you ensure you are using RGB 8bit and then transformed into a QImage/QPixmap as needed.