Ask Your Question
0

Plz Help! Can not debug grogram

asked 2013-08-05 03:58:12 -0600

tynguyen.tech gravatar image

updated 2013-08-05 13:25:03 -0600

Dear pros, i'm the beginner in studying OPENCV. I got stuck in this beginning program, it could not debugged by OPENCV2.4.5.

Pls help me to figure it out. Many thanks.

#include <highgui.h>
#include <stdio.h>
#include <cv.h>
#include <assert.h>

IplImage* doPyrDown(
IplImage* in,
int filter 
)
{
assert(in->width%2 == 0 && in->height%2 == 0);
IplImage * out = cvCreateImage(
    cvGetSize(in),
    IPL_DEPTH_8U,
    3
);
cvPyrDown( in, out);
return(out);
}


 void main() {

    int  filter =  IPL_GAUSSIAN_5x5;
    IplImage* in = cvLoadImage("F:\\chandung.png");
    cvNamedWindow( "Example-in");
    cvNamedWindow( "Example-out");  
IplImage* out  = doPyrDown(in, filter);
cvShowImage( "Example-in", in);
cvShowImage( "Example-out", out);
cvReleaseImage( &out);
cvWaitKey( 0);
cvDestroyWindow( "Example-in");
cvDestroyWindow( "Example-out");

}


When i run it, this error exists: image description


When i debugged it, errors exists while executing CANNY edge detection function. Following is the screenshot that illustrates the issue:

image description

edit retag flag offensive close merge delete

Comments

Thank you. However, i have not gotten the picture. What do you mean by "NEWER C++ STYLE API" ? It is for example new version of Visual Studio or other environment such as Eclipse, right?

tynguyen.tech gravatar imagetynguyen.tech ( 2013-08-05 13:32:45 -0600 )edit

No word can say my appreciation to you, pros. Could you please give me some advice about learning OPENCV with this new C++ API ( such as book, or tutorial for the beginner? - the tutorial on docs.Opencv seems to be too hard to catch up with). Recently, i have been learning "OPENCV- computer vision with the OPENCv libarary" by Gary Bradski & Adrian Kaebler which relies on C-API.

tynguyen.tech gravatar imagetynguyen.tech ( 2013-08-09 02:26:19 -0600 )edit

Copied data to my own answer ;) - comments removed -

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-09 03:25:49 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
1

answered 2013-08-05 16:41:37 -0600

You should link with the debug libraries in debug (opencv_core245d.lib, opencv_...245d.lib, etc.) and the release version in release (opencv_core245.lib, etc.). Visual Studio is quite sensitive to that. For me, if I don't do like this (and their is no good reason to don't do this...) I get error on almost all input/output (reading images and files). Check in your code your image. I put the sample in c++ to help you through the conversion...

cv::Mat in = cv::imload( "F:\\chandung.png");
if( !im.data ) {
    std::cerr << "Error: unable to load image!" << std::endl;
    return -1;
}
edit flag offensive delete link more

Comments

Thank you, Mathieu. I did like you and it worked though i had to changed the whole code into C++ API.

tynguyen.tech gravatar imagetynguyen.tech ( 2013-08-09 02:58:43 -0600 )edit
0

answered 2013-08-05 04:31:05 -0600

vinayverma gravatar image

updated 2013-08-05 06:07:26 -0600

Try using this:

IplImage * out = cvCreateImage( cvSize(in->width/2,in->height/2), in->depth, in->nChannels )

You need a half size image here.

I think this would help.

edit flag offensive delete link more

Comments

Note: Edited to create half size image.

vinayverma gravatar imagevinayverma ( 2013-08-05 06:09:15 -0600 )edit

Thanks. I've tried as your instruction but i has not worked yet. When i tried to debug, it is CANNY edge detection function that program gets stuck. I've edited my question in which a screenshot that illustrates the issue when debugging is inserted. Pls help me crack it. Many thanks.

tynguyen.tech gravatar imagetynguyen.tech ( 2013-08-05 13:19:38 -0600 )edit

The code you posted didn't have canny operation but just cvPyrDown. The fix I mentioned works for that. Even now you didn't post your new code.

Use the following code, it works fine:

IplImage* img = cvLoadImage( "F:\\chandung.png", 0);
cvNamedWindow( "Example4-in" );
cvNamedWindow( "Example4-out" );

// Show the original image
cvShowImage("Example4-in", img);

// Make sure image is divisible by 2
assert( img-&gt;width%2 == 0 &amp;&amp; img-&gt;height%2 == 0);

// Create an image for the output
IplImage* out = cvCreateImage( cvSize(img-&gt;width/2,img-&gt;height/2), img-&gt;depth, img-&gt;nChannels );

// Reduce the image by 2
cvPyrDown( img, out );

// Perform canny edge detection
cvCanny( out, out, 10, 100, 3 );

// Show the processed image
cvShowImage("Example4-out", out);

cvWaitKey(0);
cvReleaseImage( &amp;img );
cvReleaseImage( &amp;out );
cvDestroyWindow( "Example4-in" );
cvDestroyWindow( "Example4-out" );
vinayverma gravatar imagevinayverma ( 2013-08-05 14:44:12 -0600 )edit

Thanks, but above code apparently did not work due to some issues such as: img -&gt

tynguyen.tech gravatar imagetynguyen.tech ( 2013-08-09 03:00:09 -0600 )edit
0

answered 2013-08-09 03:24:33 -0600

Since comments are quite unclear if they get cramped with information, I will copy my comments into a single answer:


A side note: switch to the newer C++ style API. It is way more easier in handling image pointers and stuff like that.


You are using old and depricated openCV instructions, which still rely on the underlying C - API. However, from openCV2.0 they switched to a newer C++ - API which does his own memory management and such. Have a look at docs and type in canny. You will see there is the old C style cvCanny, but it has been replaced by a C++ corresponding function Canny. Functions with cv in front are the old interfaces and they will be removed in the next large release. Also, in stead of using IplImages (which needs carefull pointer handling) use the new C++ Mat type which does all this hard stuff for you :)

For new cpp examples, most of the tutorials use these instructions, have a look there for basic interfacing! Like this canny example.


There is a C++ remake of that book planned. What I suggest my students to do is the following. Go to the tutorials page and start working your way through all the samples. Once you have passed them all, AND you understand the code, you will also get the C++ interface.

Some other related books that could be interesting are :

  1. openCV starter book which was just released.
  2. the RAW C++ remake still with errors and unfinished chapters I think.
  3. the master opencv with projects
  4. And last but not least, the opencv computer vision application cookbook

Also, let the fact that we have a 'high' karma not be switched with the fact we should be pros :) Me myself, I have only been around the community for a single year now, and believe me, you get the hang of it quite fast :) Since the whole community think is based on users helping eachother, the karma just show who contributes alot to that aspect.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-08-05 03:58:12 -0600

Seen: 464 times

Last updated: Aug 09 '13