Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I'm using IP webcam android app(It converts mobile camera into IP web camera).
I'm running below code in Visual Studio 2015 with OpenCV 3.1.


C++
VideoCapture cap; Mat img;
    cap.open("http://192.168.0.101:8080/video?x.mjpeg");
    while(waitKey(33)!=27)
    {
        try{
            cap>>img;  //code crashes here
            if(img.empty())
            {
             cout<<"camera Closed"<<endl;
             break;
            }
             imshow("Video",img);
          } catch(...{}    
    }
Getting below error.cIf the internet connection is slow or if the Wi-Fi is disconnected in my android device the program crashes

Error:

Exception thrown at 0x0BF2F6F0 (opencv_ffmpeg310.dll) in test.exe:<br />
 0xC0000005: Access violation reading location 0x00000020.<br />
 <br />
 If there is a handler for this exception, the program may be safely<br />
 continued.


even if the code is wrapped within try catch block, it crashes!


Should I use try {} catch (...) block in source file, if yes, then where should I use this?


What I have tried:

I referred this link link but did not find the right answer.
Posted
Updated 27-Nov-16 18:56pm
Comments
Arthur V. Ratz 28-Nov-16 0:33am    
I hope that using try {} catch(...) exception handling mechanism will not help you in this case. Read my solution below.

1 solution

Normally, in this code, at the beginning, you declare two variables:
C++
VideoCapture cap; Mat img;
You normally open the camera by invoking
C++
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
C++
Mat img
object. During the first iteration of the following loop you just normally retrieve the first frame from the camera stream by using
C++
cap
object handle and store it into the matrix
C++
img
. *BUT* for the next iterations you use the same object
C++
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
C++
Mat img
object in the scope of the following loop the way I've shown below:

C++
VideoCapture cap;
    cap.open("http://192.168.0.101:8080/video?x.mjpeg");
    while(waitKey(33)!=27)
    {
        try{
            Mat img;
            cap>>img;  //code crashes here
            if(img.empty())
            {
             cout<<"camera Closed"<<endl;<!-- newline="" --="">             break;
            }
             imshow("Video",img);
          } catch(...{}    
    }</endl;<!-->
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900