1

I have about 300 images which I want to process in a loop. In every iteration I want to compare an image with an image from the previous loop.

I am trying to hold the current image in:

fIplImageHeader 

The image from the previous iteration is stored in:

lastFIplImageHeader 

This is how I am doing it and it is giving me an exception:

for ( int i = 0; i < 300; i++ )
{
        // get the path to an image (images are named 0.jpg, 1.jpg etc)
        // filePath.c_str() contains the path to an image

        // load the current image to an IplImage object
        IplImage* fIplImageHeader = cvLoadImage( filePath.c_str() );

        // create a header for te previous image
        IplImage* lastFIplImageHeader = cvCreateImageHeader( 
            cvSize( fIplImageHeader->width, fIplImageHeader->height ),
            fIplImageHeader->depth, fIplImageHeader->nChannels 
        );

        if ( NULL != lastFIplImageHeader->imageData )
        {
            // COMPARE IMAGES HERE
            // only if we are already in 2nd + iteration
        }

        // copy the current image to the lastFIplImageHeader
        // which will hold it in the next iteration
        if ( lastFIplImageHeader )
        {
            cvReleaseImage( &lastFIplImageHeader );
        }
        cvCopy(fIplImageHeader , lastFIplImageHeader);

        // do stuff

        if ( fIplImageHeader )
        {
            cvReleaseImage( &fIplImageHeader );
        }

}

The exception:

First-chance exception at 0x753cb727 in Client.exe: Microsoft C++ exception: cv::Exception at memory location 0x0036ef5c.. 
Unhandled exception at 0x753cb727 in Client.exe: Microsoft C++ exception: cv::Exception at memory location 0x0036ef5c..
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
  • 1
    Any chance of getting more info about the exception? Not sure how to get it in the Microsoft world, but I am used to seeing a much fuller exception description from opencv (e.g. if it was an assert that failed, you can see what was asserted). – Josh Bleecher Snyder Dec 29 '10 at 21:28
  • @Josh Bleecher Snyder I cannot really get any more information from that exception... just a disassembly and I don't understand assembly code at all. But I have uploaded a project for Visual Studio 2010: http://www.mediafire.com/?dmidxzuv3fddbof – Richard Knop Dec 29 '10 at 22:13
  • I have removed most images from the project so I could upload it to mediafire. But there are still 5 images which should be enough to debug. – Richard Knop Dec 29 '10 at 22:14
  • 1
    I don't have VS (or Windows), so just eyeballing it a little (which is why this is a comment, not an answer)...it looks like perhaps you're creating an IplImage header (cvCreateImageHeader), but releasing it as a full IplImage (cvReleaseImage). That'd definitely cause a crash. Looks like maybe the intent is cvCreateImage? Also, instead of cvCopy, why not just trade the IplImage* pointers around? – Josh Bleecher Snyder Dec 29 '10 at 22:36
  • @Josh Bleecher Snyder Well, I just tried trading pointers but that caused another anomaly (no exception though): http://stackoverflow.com/questions/4550458/opencv-compare-two-images-and-get-different-pixels – Richard Knop Dec 29 '10 at 22:55

1 Answers1

1

I suggest you load the first image outside the loop and iterate from i=1. You did not show how (if at all) you initialized lastFIplImageHeader and fIplImageHeader outside the loop.
In the line if ( NULL != lastFIplImageHeader->imageData ) there is no test that lastFIplImageHeader itself is not null.
I suggest you add a whole bunch of assert()s to verify that the data you use is actually valid when you try to operate on it.

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137