Webcam and IP cam recording with openCv
i have a problem with capture frames from 2 different cameras in the same time. I know that is probably impossible (or it's quite difficult) to connect in this way 2 USB cams, but connecting one USB cam and one IPcam maybe is easier. Of course if they works separatly i don't have problems. For example this code doesn't work:
int main() {
const std::string videoStreamAddress = "http://........../img/video.mjpeg";
cv::VideoCapture camera0(0);
cv::VideoCapture camera1(1);
camera0.open(videoStreamAddress);
cv::Mat3b frame0;
cv::Mat3b frame1;
while (true) {
camera0 >> frame0;
camera1 >> frame1;
cv::imshow("Video0", frame0);
cv::imshow("Video1", frame1);
int c = cvWaitKey(40);
if (27 == char(c)) break;
}
return 0;
}
I hope that anybody can help me
Doing
cv::VideoCapture camera0(0);
will initialize the capture to reading default camera. See this first and then tell us what is not working.But even i write sth like this:
const std::string videoStreamAddress = "http://.........../img/video.mjpeg";
cv::VideoCapture camera0(0);
cv::VideoCapture camera1(videoStreamAddress);
it still doesn't work. It's compilate, run and working for while but then it crash with this error "Unhandled exception at 0x757EC42D in iptest.exe: Microsoft C++ exception: cv::Exception at memory location 0x003AF768."
Maybe adding a verification before displaying the frames:
if (!frame.empty()) imshow("frame", frame);
It is possible that it does not receive some frames and you will get an empty frame instead...