title: openCV Error: Assertion failed (scn == 3 || scn == 4)
body: <p>I am having Assertion failed error at the last frame , while reading and writing a video frame by frame. The errors only shows at the last frame, don't know why. saw this answer <a href="https://stackoverflow.com/questions/15972059/assertion-failed-in-unknown-function">here</a>, whichs suggests to give waitkey, my code already have wait key on it.</p>
  
  <p>my simple code is as follows</p>
  
  <pre><code>int main()
  {
    CvCapture *capture=cvCaptureFromFile("C:\\vid\\op.mp4");
    if(capture==NULL)
     {
   printf("can't open video");
     }
     Mat frame, first_frame,current_frame;
    char buffer[100];
    int frame_count=1,p=1;
    while(1)
     {
     /*Getting the current frame from the video*/
      frame=cvQueryFrame(capture);
      cv::cvtColor(frame,current_frame,1);   //saving current frame 
      sprintf(buffer,"C:\\frames\\image%u.jpg",p);    
      imwrite(buffer,current_frame);
      p++;
  
       waitKey(1);
     }
     return 0;
  }  
  </code></pre>
  
  <p>Anybody please help</p>
  
  <p>Solution: I added a check just after reading every file as-</p>
  
  <pre><code>if(frame.empty()){
      fprinf("cannot access frame");
      return -1;
  }
  </code></pre>