Author Topic: another Code::Blocks and opencv question - SOLVED  (Read 6146 times)

Offline r.stiltskin

  • Multiple posting newcomer
  • *
  • Posts: 48
another Code::Blocks and opencv question - SOLVED
« on: January 24, 2009, 12:27:41 am »
I'm just beginning a project that will use some opencv functions so I wrote some simple code to verify that my linking, etc., was correct.

I put opencv under "Libraries used in project" under Project/Properties/Libraries; under Build options/Linker settings/Link libraries I listed cv and highgui; and under Project/Set programs' arguments/Release - Program arguments I have ../../lena.bmp

(lena.bmp is in the project root directory.)

Compiles OK, and if I open a Konsole window, cd to the Release directory and run it with ../../lena.bmp as a command line argument everything is good -- the openCv window displaying the image opens & waits for a keypress (any key) to close it.  This is as it should be.

But if I run it within Code::Blocks, a terminal window opens saying
"Process returned 0 (0x0)  execution time : 0.000 s
 Press ENTER to continue."
and no image is displayed.

Or, maybe the image is displayed but closes too quickly to be visible.   Why does the Code::Blocks terminal report "Process returned ..."?   The program shouldn't return until a key is pressed.

This is the code:
Code
#include <cv.h>
#include <highgui.h>

int main( int argc, char* argv[] ) {
  IplImage *img;
  if ( (img = cvLoadImage( argv[1], 0)) != 0) {
    cvNamedWindow( "Original image", 1 );
    cvShowImage( "Original image", img );
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow( "Original image" );

  }
  return 0;
}

Edit: I forgot to mention that I also used LibraryFinder (under Project/Properties/Libraries clicked "Add Manual Build Script") to get it to compile.  That worked beautifully.   But the problem described above still remains.
« Last Edit: January 24, 2009, 04:38:34 pm by r.stiltskin »

Offline r.stiltskin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: another Code::Blocks and opencv question
« Reply #1 on: January 24, 2009, 04:37:41 pm »
Solved -- dumb error.

I didn't realize that when the program runs, the current directory is the project root.  I had set up the path for the program argument (image to be loaded) as if the current directory would be bin/Release.