views:

65

answers:

1

I have a loop which goes through a video with some processing/calculations of the images. I want to save the image in the loop with the highest value from the processing, but I'm struggling a bit with storing the image temporally while the loop finishes.

The images/frames are initialized like this

IplImage* frame = 0;
IplImage* maxframe = 0;

While looping the maxframe is found by

if( currentvalue > maxvalue ) {
    maxvalue = currentvalue;
    maxframe = frame;
}

I'm aware that what I am storing in the maxframe variable is the same pointer to the frame currently loaded in the frame pointer. When a new frame is loaded into the frame variable, this will also be pointed to by the maxframe pointer. So when I save the image pointed to by maxframe, I save the last image in the loop no matter what its calculated value is.

I have tried a lot of different solutions, but I can't seem to solve this problem. Can anyone help me? :)

+1  A: 

Hi, probably the frame IplImage* gets recycled by OpenCv internal referencing system. Have you tried to do a deep copy of the image, using IplImage* cvCloneImage(const IplImage* image)? By the way, with openCv 2.0 and up it's better if you use a cvMat (or cv::Mat) to hold images... Use then cv::Mat image, then image.clone();

DavideRizzi
Thanks, that worked! I'll look into updating my code to the later versions later.. That's the problem with using old examples. ;)
BackstreetStruts