开发者

Storing images and pointers in OpenCV

开发者 https://www.devze.com 2022-12-28 21:10 出处:网络
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 wit

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 lo开发者_开发技巧op 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? :)


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();

0

精彩评论

暂无评论...
验证码 换一张
取 消