我从两台相机收集好的相框,用于立体相机校准。
#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;
}
但是我在运行时遇到了一个奇怪的错误: -
OpenCV Error: Assertion failed (scn == 1 && (dcn == 3 || dcn == 4)) in cvtColor,
file C:\opencv\modules\imgproc\src\color.cpp, line 3234
另外,我已经检查过源图像和目标图像的Dimension和nchannel值是否相等。
提前感谢!!
答案 0 :(得分:2)
断言非常明确scn == 1
表示您的源图片必须有一个频道(因为您指定CV_GRAY2BGR
为cvCvtColor
的转换代码)。