Ask Your Question

Revision history [back]

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

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.