openCV Error: Assertion failed (scn == 3 || scn == 4)

asked 2015-07-06 00:10:07 -0500

When I try to read the file i got following error.

problem1.png When I try to run the webcam it is working fine for me

here is my code which i got the error

`
#include "opencv2/opencv.hpp"


using namespace cv;



int main(void)
{
    VideoCapture cap("C:/Users/rushikesh/Desktop/video.webm");
//  VideoCapture cap(0); // open the default camera
    if (!cap.isOpened())  // check if we succeeded
        return -1;

Mat edges;
namedWindow("edges", 1);
for (;;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
    cvtColor(frame, edges, CV_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);
    if (waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}

What is the problem with my code. File is there on specify path.

edit retag flag offensive close merge delete

Comments

1

for video from file, you have to add a line:

cap >> frame; // get a new frame from camera
if (frame.empty()) break; // movie is over ?
berak gravatar imageberak ( 2015-07-06 01:14:12 -0500 )edit