Ask Your Question
0

problem in cv::capture

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

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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

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

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

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-18 06:41:35 -0600

Wael gravatar image

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-03-17 15:57:52 -0600

Seen: 325 times

Last updated: Mar 17 '17