简体   繁体   中英

Command prompt in debug mode for Eclipse? (OpenCV + Eclipse + Win7)

I am a beginner for Eclipse. I now have Eclipse C/C++ IDE with OpenCV library running on Windows 7. So far it works after spending hours trying to get it running. But then I realize that Eclipse does not pop up a command prompt as VS2010 does while debugging. And moreover Eclipse's debug mode is just stuck in there and refuse to output anything. But if the code doesn't involve the OpenCV things it works again.

Below is the code I use for testing. It captures images from webcam and output it to the screen. The infinite loop (until you press 'q') makes sure it constantly grabs new inputs from the camera.

I browsed through the workspace and run the exe just compiled and it worked flawlessly. So I don't think there's anything wrong in the code (it's an example code anyway

In brief, can I just pop up a command prompt window in debug mode? And why is Eclipse console stuck when the code involves some OpenCV functions?

#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;

    /* initialize camera */
    capture = cvCaptureFromCAM( 0 );

    /* always check */
    if ( !capture ) {
        printf("Cannot open initialize webcam!\n");
        return 1;
    }

    /* create a window for the video */
    cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );

    while( key != 'q' ) {
        /* get a frame */
        frame = cvQueryFrame( capture );

        /* always check */
        if( !frame ) break;

        /* display current frame */
        cvShowImage( "result", frame );

        /* exit if user press 'q' */
        key = cvWaitKey( 1 );
    }

    /* free memory */
    cvDestroyWindow( "result" );
    cvReleaseCapture( &capture );

    return 0;
}

This is because you have already set the windows 7 system variable PATH to your MinGw/bin and compiled opencv bin directories. So when you run the program from your folder your system automatically take the required binaries from its PATH and the program runs correctly.

I don't know why but Eclipse does not take it directly from the system environment PATH variable. So we have to set it ourself.

     go to Preferences > C/C++ (Expand it) > Environment > Add:

     "Name:PATH"
      "Value:C:\MinGW\bin;C:\opencv_MinGW\bin"

where opencv_MinGW is the folder where I compiled my opencv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM