i am trying to implement opencv’s canny edge detection on live video from webcam. However, I am getting this error:
OpenCV Error: Unsuported format or combination of formats <> in unknown function, file ……..\ocv\opencv\src\cv\cvcanny.cpp, line 66
I guess this is a format issue. I can convert the 3-channel 8-bit RGB image into a 1-channel grayscale imageframe and then perform edge detection on the result. However, I am unable to implement rgb2grayscale conversion on the image as well; < Incorrect number of channels for this conversion code>
Below is the code that I implemented In VS2008. Any thoughts on how to resolve this error?
#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;
}
The Problem is that you are passing a 3 channel image everywere
Create other two images of single channel and use those:
and use it in:
This works for me: