Assertion failed (size.width>0 && size.height>0)

前端 未结 3 1752
灰色年华
灰色年华 2020-11-30 13:27

I\'m using Visual Studio Express 2013 with OpenCV 2.4.7, following this tutorial.

I have spent hours searching the web for solutions, including all of t

相关标签:
3条回答
  • 2020-11-30 14:11

    I tried your code and for me it works (it visualizes the current webcam input)!
    I ran it on Visual Studio 2012 Ultimate with OpenCV 2.4.7.
    ...
    The error occurs because the image is empty, so try this:

    while (true) {
        cap >> image;
    
        if(!image.empty()){
            imshow("window", image);
        }
    
    // delay 33ms
    waitKey(33);        
    }
    

    Maybe the first image you receive from your webcam is empty. In this case imshow will not throw an error. So hopefully the next input images are not empty.

    0 讨论(0)
  • 2020-11-30 14:11

    Do this:

    VideoCapture cap;
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    int camOpen = cap.open(CV_CAP_ANY);
    

    Or you can try changing this:

    while (true) {
            cap >> image;
    
            imshow("window", image);
    
        // delay 33ms
        waitKey(33);        
        }
    

    to

    try
    {
         cap >> image;
         imshow("window", image);
         waitKey(33); 
    }
    catch (Exception& e)
    {
        const char* err_msg = e.what();
        std::cout << "exception caught: imshow:\n" << err_msg << std::endl;
    }
    
    0 讨论(0)
  • 2020-11-30 14:27
    int i=0;
    
    while(i<4)
    
    {
    
    VideoCapture cap(0); // force camera to open 4 tiMEs
    
    i++;
    
    }
    
    waitKey(5000); 
    VideoCapture cap(0);
    int camOpen = cap.open(CV_CAP_ANY);
    
    namedWindow("window", CV_WINDOW_AUTOSIZE);
    
    while (true) {
        cap >> image;
    
        imshow("window", image);
    waitKey(33);        
    }
    

    Do this it will work for you for sure.

    0 讨论(0)
提交回复
热议问题