OpenCV Canny Edge on Live Video-Collection of common programming errors

  • The Problem is that you are passing a 3 channel image everywere

    IplImage* out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 3 );
    

    Create other two images of single channel and use those:

    IplImage* gray_out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
    IplImage* canny_out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
    

    and use it in:

    cvSmooth( frame, out, CV_GAUSSIAN, 11, 11 );
    cvCvtColor(out , gray_out, CV_RGB2GRAY);
    cvCanny( gray_out, canny_out, 10, 10, 3 );
    
    if( !frame ) break;
    cvShowImage( "Edge", canny_out );
    

    This works for me:

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    
    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

Originally posted 2013-11-06 03:16:48.