problem in cv::capture

asked 2017-03-17 15:57:52 -0500

Wael gravatar image

Hello, I have a problem in project visual studio 2015 opencv 3.2 Same code code works without any problem in opencv 2.4

void Example_video1()
{
    //const std::string videoStreamAddress = "http://<username:password>@<ip_address>/video.cgi?.mjpg";
    const std::string videoStreamAddress = "http://<username:password>@<ip_address>/video.cgi?.mjpg";

    cv::namedWindow("Example3", cv::WINDOW_AUTOSIZE);

    cv::VideoCapture cap;
    cap.open(string("c:\\one.mp4"));



    //cout << frame .total()<< endl;
    int i = 1;
    Mat frame;
    for (;;)
    {


        cap >> frame; // get a new frame from file

        //cap.read(frame);
        if (frame.empty())
        {
            cout << "Empty" << endl;
            break;
        }
        else
            cout << "Frame: " << i << endl;
        i++;
        imshow("Example3", frame);
        if (waitKey(30) >= 0) break;


    }

    waitKey(0);
}

i get this exception in this line cap >> frame; // get a new frame from file Exception thrown at 0x00007FF8004368D8 in ConsoleApplication2.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000ABBB00EA40.

Kindly advice

edit retag flag offensive close merge delete

Comments

Check if file is opened :

cap.open(string("c:\\one.mp4"));
if (!cap.isOpened())
{
cout<<"File is not opened!";
exit(-1);
}
LBerger gravatar imageLBerger ( 2017-03-17 16:21:57 -0500 )edit

File is opened success First frame is only displayed success After first frame exception happen i tried the code with OpenCV 2.4 without any problem

Regards

Wael gravatar imageWael ( 2017-03-17 21:47:26 -0500 )edit

Check in vs2015 if you link release lib with release configuration and debug lib with debug configuration

LBerger gravatar imageLBerger ( 2017-03-18 04:34:17 -0500 )edit

Problem is solved The crash was in below line using waitKey is like below is the problem

if (waitKey(30) >= 0) break;

Replaced with this line

char c = waitKey(30);
if (c == 27) break;
Wael gravatar imageWael ( 2017-03-18 05:19:23 -0500 )edit

may be your problem is solved but that's not a good explantion

LBerger gravatar imageLBerger ( 2017-03-18 06:27:51 -0500 )edit

Yes i don't know why this line give an exception and it is still give exception (opencv 3.2) only

if (waitKey(30) >= 0) break; //exception

Regards

Wael gravatar imageWael ( 2017-03-18 06:41:35 -0500 )edit