Normally, in this code, at the beginning, you declare two variables:
VideoCapture cap; Mat img;
You normally open the camera by invoking
cap.open("http://192.168.0.101:8080/video?x.mjpeg");
method and then perform a loop to retrieve each frame from the camera device storing them into a frame matrix represented by
Mat img
object. During the first iteration of the following loop you just normally retrieve the first frame from the camera stream by using
cap
object handle and store it into the matrix
img
. *BUT* for the next iterations you use the same object
img
which is not empty containing the previous frame's matrix. That's actually why, in my opinion, your application crashes since you need to an empty matrix for each frame fetch during the loop execution. Try to declare the
Mat img
object in the scope of the following loop the way I've shown below:
VideoCapture cap;
cap.open("http://192.168.0.101:8080/video?x.mjpeg");
while(waitKey(33)!=27)
{
try{
Mat img;
cap>>img; if(img.empty())
{
cout<<"camera Closed"<<endl;<!-- newline="" --=""> break;
}
imshow("Video",img);
} catch(...{}
}</endl;<!-->