gpt4 book ai didi

c++ - 无法绘制棋盘角,因为 cvCvColor 方法中的断言失败

转载 作者:太空宇宙 更新时间:2023-11-03 22:34:20 25 4
gpt4 key购买 nike

我正在从两个相机收集好帧以用于立体相机校准目的。

  #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

此外,我还检查了源图像和目标图像的维度和 nchannel 值是否相等。

提前致谢!!

最佳答案

断言很明确scn == 1意味着您的源图像必须有一个 channel (那是因为您指定了 CV_GRAY2BGR 作为 cvCvtColor 的转换代码)。

关于c++ - 无法绘制棋盘角,因为 cvCvColor 方法中的断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com