Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6550583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:13:59+00:00 2026-05-25T12:13:59+00:00

i am trying to implement opencv’s canny edge detection on live video from webcam.

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:14:00+00:00Added an answer on May 25, 2026 at 12:14 pm

    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 <stdio.h>
    #include <iostream>
    #include <iomanip>
    #include <cv.h>
    #include <cvaux.h>
    #include <cxcore.h>
    #include <highgui.h>
    #include <math.h>
    #include <string.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 );
            IplImage* gray_out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
            IplImage* canny_out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
            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 );
            char c = cvWaitKey(33);
            if( c == 27 ) break;
        }
        cvReleaseCapture( &capture );
        cvDestroyWindow( "Edge" );
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an edge map extracted from edge detection module in OpenCV (canny edge
Im trying to implement this code: http://wcf.codeplex.com/wikipage?title=Getting%20started:%20Building%20a%20simple%20web%20api and want to add it to my
Am trying to implement a generic way for reading sections from a config file.
im trying to implement a custom error page, what i want to be able
Trying to implement simple error handling without adding buku try / except statements to
Trying to implement the decorator pattern in C# from the code in the Head
I am trying to grab consecutive frames from android using opencv VideoCapture class. Actually
I am trying implement Unblock me Puzzle. i want to change image position from
I've a webbrowser control and I'm trying implement IDocHostUIHandler in the container. However since
Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.