Lokesh Kumar
Lokesh Kumar

Reputation: 682

Unable to draw Chessboard Corners because assertion failed in cvCvColor Method

i am collecting Good frames from two cameras for stereo camera calibration purpose.

  #include <iostream>
  #include <cv.h>
  #include <highgui.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <sstream>

  using namespace std;

  int main() {

  CvCapture* videocapture_CAM0=cvCreateCameraCapture(0);    
  CvCapture* videocapture_CAM1=cvCreateCameraCapture(1);

  IplImage* img_0;    
  IplImage* img_1;

  int nx=4,ny=3;

  int i, j, nframes, n = nx*ny;

  vector<CvPoint2D32f> temp_0(n);    
  vector<CvPoint2D32f> temp_1(n);

  CvSize imageSize_0 = {0,0};    
  CvSize imageSize_1 = {0,0};

  while(1)  
  {
      int count_0 = 0,count_1 = 0;
      int result_0 = 0,result_1 = 0;

      img_0=cvQueryFrame(videocapture_CAM0);
      img_1=cvQueryFrame(videocapture_CAM1);

      imageSize_0 = cvGetSize(img_0);
      imageSize_1 = cvGetSize(img_1);    

      cvShowImage("camera 1", img_0);
      cvShowImage("camera 2", img_1);

      IplImage* timg_0 = img_0;
      IplImage* timg_1 = img_1;

      result_0 = cvFindChessboardCorners(timg_0, cvSize(nx, ny), &temp_0[0], &count_0,
                            CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);

      result_1 = cvFindChessboardCorners(timg_1, cvSize(nx, ny), &temp_1[0], &count_1, 
                            CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);

      if(result_0&&result_1)
      {
            cout<<"Found"<<endl;

            IplImage* cimg_0 = cvCreateImage(imageSize_0, 8, 3);            

            IplImage* cimg_1 = cvCreateImage(imageSize_1,8,3);

            cvCvtColor(img_0, cimg_0, CV_GRAY2BGR);
            cvCvtColor(img_1, cimg_1, CV_GRAY2BGR);

            cvDrawChessboardCorners(cimg_0, cvSize(nx, ny), &temp_0[0], count_0, 
                                    result_0);

            cvDrawChessboardCorners(cimg_1, cvSize(nx, ny), &temp_1[0], count_1,
                                    result_1);

            cvShowImage("corners", cimg_0);
            cvShowImage("corners", cimg_1);

            cvReleaseImage(&cimg_0);
            cvReleaseImage(&cimg_1);

            cvWaitKey(5);

       }
       char c=cvWaitKey(30);
       if(c==27)
        break;
     }
     return 0;
  }

but i'm getting a weird error at run time :-

OpenCV Error: Assertion failed (scn == 1 && (dcn == 3 || dcn == 4)) in cvtColor,
 file C:\opencv\modules\imgproc\src\color.cpp, line 3234

also, i have checked that Dimension and nchannel values of both source and destination images are equal.

thanks in advance!!

Upvotes: 1

Views: 2025

Answers (1)

Mohammad
Mohammad

Reputation: 1252

The assertion is very clear scn == 1 means your source image must have one channel (thats beacuse you specified CV_GRAY2BGR as conversion code for cvCvtColor).

Upvotes: 2

Related Questions