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

  • Home
  • SEARCH
  • 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 776821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:30:43+00:00 2026-05-14T19:30:43+00:00

I am working through the book Learning OpenCV from the O’Reilly series and am

  • 0

I am working through the book “Learning OpenCV” from the O’Reilly series and am trying to perform a canny edge detection sample.

Any grayscale image I choose seems to come up as having 3 channels, and to the best of my knowledge, canny only works with single channel images, so this always fails. I am even using the images provided by OpenCV.

Here is my code..

IplImage* doCanny(IplImage* in, double lowThresh, double highThresh, double aperture)
{
    if(in->nChannels != 1)
        return(0); //canny only handles gray scale images
    IplImage* out = cvCreateImage(cvSize(in->width, in->height), IPL_DEPTH_8U, 1);
    cvCanny(in, out, lowThresh, highThresh, aperture);
    return(out);
};

IplImage* img = cvLoadImage("someGrayscaleImage.jpg");
IplImage* out = doCanny(img, 10, 100, 3);

Why might this always give me 3-channel images? How can I solve this?

  • 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-14T19:30:43+00:00Added an answer on May 14, 2026 at 7:30 pm

    You can use this method with another parameter

    IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR)
    
    #define CV_LOAD_IMAGE_COLOR       1
    
    #define CV_LOAD_IMAGE_GRAYSCALE   0
    
    #define CV_LOAD_IMAGE_UNCHANGED  -1
    

    The default parameter is load image with color. What you have to do is to load it with grayscale

    Here is an example

    cvLoadImage("yourimage.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    

    Here is the detail explanation for that method. You can look at here for more details:
    Open CV 2.0 References

    scolor – Specific color type of the loaded image: if $ > 0 $, the loaded image is forced to be a 3-channel color image; if 0, the loaded image is forced to be grayscale; if $ < 0 $, the loaded image will be loaded as is (note that in the current implementation the alpha channel, if any, is stripped from the output image, e.g. 4-channel RGBA image will be loaded as RGB).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working through the book Learning WCF by Michele Bustamante, and trying to
I'm learning objective-c, working through Aaron Hillegass' book Cocoa Programming for Mac OS X
I've been learning Objective-C and Cocoa by working my way through the Hillegass book
I am working through the book Learning WCF and on the first tutorial lab
So right now I'm learning Ruby on Rails, and I'm working through the book
I'm working through the book Pro WF Windows Workflow in .NET 3.5 and on
I am working through the examples in a Django book that I have, but
I'm working through previous years ACM Programming Competition problems trying to get better at
I'm currently working my way through this book: http://www1.idc.ac.il/tecs/ I'm currently on a section
I've been working through a fantastic book (Pro ASP.net MVC 2 Framework, Steven Sanderson)

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.