【发布时间】:2011-11-13 04:21:43
【问题描述】:
我正在尝试对来自网络摄像头的实时视频实施 opencv 的精明边缘检测。但是,我收到此错误:
OpenCV 错误:不支持的格式或格式组合 在未知函数中,文件 ........\ocv\opencv\src\cv\cvcanny.cpp,第 66 行
我猜这是格式问题。我可以将 3 通道 8 位 RGB 图像转换为 1 通道灰度图像帧,然后对结果进行边缘检测。但是,我也无法在图像上实现 rgb2grayscale 转换;
以下是我在 VS2008 中实现的代码。有关如何解决此错误的任何想法?
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <cv.h>
#include <cvaux.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>
#include <string.h>
#include <cxtypes.h>
using namespace std;
using namespace cv;
int main(int, char**)
{
cvNamedWindow("Edges", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCaptureFromCAM(0);
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
int depth_img =frame->depth;
int height_img =frame->height;
int width_img =frame->width;
int size_img =frame->imageSize;
int nchan_img =frame->nChannels;
int nsize_img =frame->nSize;
cout << setw(15) << "depth" << depth_img << endl;
cout << setw(15) << "height" << height_img << endl;
cout << setw(15) << "width" << width_img << endl;
cout << setw(15) << "size" << size_img << endl;
cout << setw(15) << "nchan" << nchan_img << endl;
cout << setw(15) << "nsize" << nsize_img << endl;
IplImage* out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 3 );
cvSmooth( frame, out, CV_GAUSSIAN, 11, 11 );
cvCvtColor(out ,out, CV_RGB2GRAY);
cvCanny( out, out, 10, 10, 3 );
if( !frame ) break;
cvShowImage( "Edge", out );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Edge" );
return 0;
}
【问题讨论】: