Something goes wrong with OpenCV in QtCreator
-
I want to use OpenCV in QtCreator and I edit the .pro file.When I use OpenCV 1.0 lib,code is showed below:
-
IplImage* pFrame = NULL; CvCapture* capture = cvCreateCameraCapture(1); cvNamedWindow("video", 1); while (1){ pFrame = cvQueryFrame(capture); if (!pFrame) break; cvShowImage("video", pFrame); char c = cvWaitKey(33); if(c == 27) break; } cvReleaseCapture(&capture); cvDestroyWindow("video"); return 0;
It could open the camera and show it in a window.But when I use OpenCV 2.x lib,code is showed below:
-
Mat pFrame; VideoCapture capture(1); if (!capture.isOpened()){ cout << "open camera failed!"; return -1; } namedWindow("test", 1); while (1){ capture >> pFrame; if (pFrame.empty()) break; imshow("test", pFrame); char c = cvWaitKey(33); if (c == 27) break; } destroyWindow("test"); return 0;
It just keeps creating new windows,though every window could show one image from the camera.
But when I use VS2013 to do the samething, it all work out fine.
Thank you for reading my question. -
-
Hi and welcome to devnet,
Are you using the exact same code in VS and Qt Creator ?
-
Are you using the same project for Visual Studio and Qt Creator ?
-
Then are you using the same version of OpenCV for both projects ?
-
IIRC, OpenCV has a Qt backend so I was wondering if there was a mix somewhere that could trigger that bug
-
Could you send us the minimum projects which could reproduce the bugs(.hpp, .cpp and your .pro), if you could put it on github, it would be even better(easier for us to download and test it)
I have a long time haven't played with openCV2, but I do have some experience about itBy the way, since you are using Qt, why not just use QLabel or graphicsview framework to show the image?If you need to convert the QImage and cv::Mat, you could look at here.