Hello,
I’m trying to handle USB camera with opencv 2.4.11 VIdeoCapture. (With Visual Studio 2013, Windows 10)
I use 2 USB cameras, and switching them every time to time. However the program crashes quite often.
I’ve connected 2 USB Camera to USB ss(super speed) slots on the behind of my PC directly, via USB3.0 cable (less then 1 meter long).
I want to solve this problem and set switching duration as 10 seconds.
Here is the error message:
*On the command prompt of my program:
OpenCV Error: Assertion failed (size.width)>0 && size.height>0) in cv::imshow, file C:\builds\2_4_PackSlave-win64-vc12-shared\opencv\modules\highgui\srd\windows.cpp, line 261
*pop-up window on VS2013:
Unhandled exception at ‘somewhere’ in ‘my program.exe’:
Microsoft C++ exception: cv::Exception at memory location ‘somewhere’.
Breakpoint is where I use imshow.
Here is a part of my code.
#include <iostream>
#include <time.h>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
int runTime = 10; // sec
bool flag = true;
while (flag==true) {
time_t startTime = time(NULL);
VideoCapture cap0(CV_CAP_DSHOW);
if (!cap0.isOpened()) {
printf("Can't open the camera.");
return -1;
}
printf("Camera0 opened.");
Mat img;
while (true) {
cap0 >> img;
imshow("Camera0", img);
if (waitKey(1) == 27) {
flag = false;
break;
}
if ((time(NULL) - startTime) >= runTime) {
break;
}
}
cap0.release();
destroyAllWindows();
startTime = time(NULL);
// same thing for the other camera, with VideoCapture cap0(CV_CAP_DSHOW + 1);
}
return 0;
}
I tried to check window.cpp line 261:
#ifndef HAVE_OPENGL
CV_Assert(size.width>0 && size.height>0); // this is line 261
{
Mat img = _img.getMat();
CvMat c_img = img;
cvShowImage(winname.c_str(), &c_img);
}
Well, but I don’t have any idea right now…
Is there any way instead of using try & catch but solve this problem fundamentally?
And please let me know if you need any further information.
Thank you in advance!
Best regards,
JESuh