Ask Your Question

Error loading xml file.

asked 2013-08-28 01:23:14 -0600

Michael Vance gravatar image

updated 2013-08-28 01:42:30 -0600

Siegfried gravatar image

An xml file could not be loaded when running the project on Visual Studio but the .exe of the project runs perfectly.

const char *cascade_name="output.xml";
int lastX = -1;
int lastY = -1;
void detect_and_draw( IplImage* img )

    // Create memory for calculations
    static CvMemStorage* storage = 0;
    // Create a new Haar classifier
    static CvHaarClassifierCascade* cascade = 0;
    // Sets the scale with which the rectangle is drawn with
    int scale = 1;
    // Create two points to represent the hand locations
    //CvPoint pt1, pt2;
    // Looping variable
   // int i;
    // Load the HaarClassifierCascade
    cascade = (CvHaarClassifierCascade*)cvLoad(cascade_name,0,0,0);
    // Check whether the cascade has loaded successfully. Else report and error and quit  

    // Allocate the memory storage
    storage = cvCreateMemStorage(0);
    // Create a new named window with title: result
    cvNamedWindow( "result", 1 );
    // Clear the memory storage which was used before
    cvClearMemStorage( storage );
        fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
    if( cascade )

        // There can be more than one hand in an image. So create a growable sequence of hands.
        // Detect the objects and store them in the sequence
        CvSeq* hands = cvHaarDetectObjects( img, cascade, storage,
                                            1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
                                            cvSize(40, 40) );

        // Loop the number of hands found.
        for( i = 0; i < (hands ? hands->total : 0); i++ )
           // Create a new rectangle for drawing the hand
            CvRect* r = (CvRect*)cvGetSeqElem( hands, i );

            // Find the dimensions of the hand,and scale it if necessary
            pt1.x = r->x*scale;
            pt2.x = (r->x+r->width)*scale;
            pt1.y = r->y*scale;
            pt2.y = (r->y+r->height)*scale;

            // Draw the rectangle in the input image
            cvRectangle( img, pt1, pt2, CV_RGB(230,20,232), 3, 8, 0 );

    // Show the image in the window named "result"
    cvShowImage( "result", img );


can somebody tell me what went wrong?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-08-28 01:39:32 -0600

Siegfried gravatar image

You should check the working directory in Visual Studio and use from this directory a relative path to the "output.xml" file. An other solution is to use an absolute path.

edit flag offensive delete link more


+1 Always use absolute paths when possible, expecially when testing stuff out :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-28 02:06:06 -0600 )edit

I have actually placed or stored all the necessary files in the the folder where the project is created. The xml is placed together within the projects folder. I have followed a certain tutorial I found in the internet and somehow i can't identify the problem. I even tested the xml's that came pre-installed in the opencv, but still it can't load the xml. If you could share some links on how to fix this or other examples where I can test it, please let me know.

Michael Vance gravatar imageMichael Vance ( 2013-08-28 21:38:24 -0600 )edit

I would recommend you to use the C++ API instead of the old C API, even if it should work with the old C API. If you decide to use C++ API, you can take a look at the OpenCV object detection tutorial.

Also if you use this example you have to check that your paths are correct.

Siegfried gravatar imageSiegfried ( 2013-08-29 02:21:30 -0600 )edit

@Siegfried, I have executed the example on the link you gave, but this time the error is stating "Native' has exited with code -1 (0xffffffff)". This is the error upon running the example. The problem is similar but this time, the error message did not show up instead it automatically terminates the project. Also when I execute the .exe it runs and produces output similar to the links example.

Michael Vance gravatar imageMichael Vance ( 2013-08-29 05:35:51 -0600 )edit

Question Tools


Asked: 2013-08-28 01:23:14 -0600

Seen: 2,544 times

Last updated: Aug 29 '13