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 6047057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:18:34+00:00 2026-05-23T07:18:34+00:00

I am trying to do the examples in the OpenCV book and I got

  • 0

I am trying to do the examples in the OpenCV book and I got to the part regarding cvCanny. I am trying to use it, but I keep getting a memory exception error of

Unhandled exception at 0x75d8b760 in Image_Transform.exe: Microsoft C++ exception: cv::Exception at memory location 0x0011e7a4..

I have also looked at another post that was similar to this question, but it did not help for me as I got the same error each time. Any help is greatly appreciated and the source code for the function is located below.

void example2_4(IplImage* img)
{
// Create windows to show input and ouput images
cvNamedWindow("Example 2-4 IN", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Example 2-4 OUT", CV_WINDOW_AUTOSIZE);

// Display out input image
cvShowImage("Example 2-4 IN", img);

// Create an image to hold our modified input image
IplImage* out = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);

// Do some smoothing
//cvSmooth(img, out, CV_GAUSSIAN, 3, 3);

// Do some Edge detection
cvCanny(img, out, 10, 20, 3);

// Show the results
cvShowImage("Example 2-4 OUT", out);

// Release the memory used by the transformed image
cvReleaseImage(&out);

// Wait for user to hit a key then clean up the windows
cvWaitKey(0);
cvDestroyWindow("Example 2-4 IN");
cvDestroyWindow("Example 2-4 OUT");
}

int main()
{
// Load in an image
IplImage* img = cvLoadImage("images/00000038.jpg");

// Run the transform
example2_4(img);

// clean the image from memory
cvReleaseImage(&img);

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-23T07:18:35+00:00Added an answer on May 23, 2026 at 7:18 am

    You forgot to say if you are able to see the original image being displayed on the screen.

    I never get tired of telling people that checking the return of functions is a must!

    Consider IplImage* img = cvLoadImage("images/00000038.jpg"); , how can you tell if this function succeeded or not? As far as I can tell, the error you are having might be from a function failing prior to cvCanny() being called.

    Anyway, I recently posted a code that uses cvCanny to improve circle detection. You can check that code and see what you are doing differently.

    EDIT:

    Your problem in this case is that you are passing to cvCanny input and output as a 3 channel image, when it takes only a single channel image. Check the docs:

    void cvCanny(const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size=3)

    Implements the Canny algorithm for edge detection.
    Parameters: 
    
        * image – Single-channel input image
        * edges – Single-channel image to store the edges found by the function
        * threshold1 – The first threshold
        * threshold2 – The second threshold
        * aperture_size – Aperture parameter for the Sobel operator (see Sobel)
    

    So, change your code to:

    // Create an image to hold our modified input image
    IplImage* out = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); 
    
    // Do some smoothing
    //cvSmooth(img, out, CV_GAUSSIAN, 3, 3);
    
    IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); 
    cvCvtColor(img, gray, CV_BGR2GRAY);
    
    // Do some Edge detection
    cvCanny(gray, out, 10, 20, 3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use OpenCV on my Ubuntu machine but I am having
I was playing around with Python's subprocess module, trying a few examples but I
I'm trying to compile beej's guide to network programming examples, but Windows XP doesn't
I am trying to use the Python opencv function Moments() on a grayscale image,
I'm trying to learn how to use OpenCV's new C++ interface. How do I
I've picked up 'Learning OpenCV' and have been trying some of the code examples/exercises.
i'l learning opencv with c++ and so i'm trying to use new c++ interface.
i'm trying to connect to ip camera from java using openCV. I see examples
I am trying to compile/build OPenCV 2.3 with the help of CMake/Mingw. I got
I'm currently trying to play around with OpenCV but I ran into a bit

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.