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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:31:48+00:00 2026-05-20T00:31:48+00:00

I have used cvCanny function to detect Edges. cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size

  • 0

I have used cvCanny function to detect Edges.

cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size ); 

But in run time it gives runtime error. The error msg not clear at all. It refers some memory location. Please help me..!!

code:

void switch_callback_h( int position ){
 highInt = position;
}
void switch_callback_l( int position ){
 lowInt = position;
}

int _tmain(int argc, _TCHAR* argv[])
{

 const char* name = "Edge Detection Window";
 // Kernel size
 int N = 7;
CvCapture* capture = cvCaptureFromCAM(1);
IplImage* frame;

while(1) {
frame = cvQueryFrame( capture );

// Add convolution boarders
 CvPoint offset = cvPoint((N-1)/2,(N-1)/2);
 cvCopyMakeBorder(frame, img_b, offset, IPL_BORDER_REPLICATE, cvScalarAll(0));

 // Make window
 cvNamedWindow( name, 1 );

 // Edge Detection Variables
 int aperature_size = N;
 double lowThresh = 20;
 double highThresh = 40;

 // Create trackbars
 cvCreateTrackbar( "High", name, &high_switch_value, 4, switch_callback_h );
 cvCreateTrackbar( "Low", name, &low_switch_value, 4, switch_callback_l );
 highThresh = 800;
        lowThresh = 100;

     cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size );  

        cvShowImage(name, out);
 cvReleaseImage( &frame );
 cvReleaseImage( &img_b );
 cvReleaseImage( &out );
 cvDestroyWindow( name );

   if( cvWaitKey( 15 ) == 27 ) 
 break;

  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-20T00:31:49+00:00Added an answer on May 20, 2026 at 12:31 am

    You were very close to making this work. Basically, here are your problems:

    • You’re creating a window inside the loop. Since the window has the same name every time, you only to create it once.
    • You’re destroying your images before you’re able to show them. Your images will be shown not when you called cvShowImage, but when you call cvWaitKey. By that time you’ve already freed the image, so nothing will be shown.
    • You’re freeing frames loaded from CvCapture. The documentation explicitly says not to do this:

    The function cvQueryFrame grabs a
    frame from a camera or video file,
    decompresses it and returns it. This
    function is just a combination of
    GrabFrame and RetrieveFrame , but in
    one call. The returned image should
    not be released or modified by the
    user
    . In the event of an error, the
    return value may be NULL.

    • You’re not initializing image_b or out anywhere. They’re not even declared in the code you posted. I don’t know how your code even compiled, let alone ran.
    • You’re specifying image_b as the source to the canny edge detection, when it should really be frame
    • You’re not freeing the video capture struct

    Like I said, a number of tiny points. Here’s code that works:

    #include <stdlib.h>
    #include <cv.h>
    #include <highgui.h>
    //
    // Comment this out to use the webcam.
    //
    #define LOAD_IMAGE "/home/misha/Desktop/Lenna.png"
    int main(int argc, char **argv)
    {
        const char *name = "Edge Detection Window";
        int N = 7;
    #ifndef LOAD_IMAGE
        CvCapture *capture = cvCaptureFromCAM(1);
    #endif
        IplImage *frame = NULL;
        IplImage *out = NULL;
    
        cvNamedWindow(name, 1);
    
        while (1) 
        {
    #ifdef LOAD_IMAGE
            frame = cvLoadImage(LOAD_IMAGE, 0);
    #else
            frame = cvQueryFrame(capture);
    #endif
            out = cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);
    
            int aperature_size = N;
            double lowThresh = 20;
            double highThresh = 40;
    
            highThresh = 800;
            lowThresh = 100;
    
            cvCanny(frame, out, lowThresh * N * N, highThresh * N * N,
                    aperature_size);
    
            cvShowImage(name, out);
    #ifndef LOAD_IMAGE
            if (cvWaitKey(15) == 27)
                break;
    #else
            cvWaitKey(0);
            break;
    #endif
            }
        cvReleaseImage(&out);
        cvDestroyWindow(name);
    #ifdef LOAD_IMAGE
        cvReleaseImage(&frame);
    #else
        cvReleaseCapture(&capture);
    #endif
        return 0;
    }
    

    Compiles with:

    gcc -ggdb -Wall -o devan.out devan.c `pkg-config --cflags --libs opencv`
    

    Standard image and output:

    lenna output

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

Sidebar

Related Questions

I have used the silverlight control in CRM 2011.It also published on form but
I have used a plugin that uses prototype js, it's working fine but the
I have used NSSets many times in my apps, but I have never created
I have used geocoder in my ruby on rails application for a while but
I have used split function to split the string in javascript. which is as,
I have used microsoft system.security.cryptography to make md5 in c# application but I need
I have used following code to add three variables but instead of adding these
I have used initialization lists a great deal in my C++ programs but wasn't
i have used filter to get the gradient and border-radius for round border but
I have used the signalR chat app (as laid out in this tutorial http://sergiotapia.com/2011/09/signalr-with-mvc3-chat-app-build-asynchronous-real-time-persistant-connection-websites/

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.