I am doing on a project for searching through an image database, and when I find the results to some query - 5 database images, I would like to display the results visually. I do not keep all the images in memory, so I have do load the image first in order to display it.
I had something simple in mind, in pseudocode:
for image 1..5
load images
display image in a window
wait for any keypress
close the window
Here's a snippet of my code in C++
using OpenCV
for this purpose:
IplImage *img;
for (int i=0; i < 5; ++i){
img = cvLoadImage(images[i].name.c_str(),1);
cvShowImage(("Match" + images[i].name).c_str(), img);
cvWaitKey(0);
cvDestroyWindow(("Match" + images[i].name).c_str());
// sleep(1);
cvReleaseImage(&img);
}
The images
array used here does not as such exist in my code, but for the sake of the question, it contains the File Names of the images relative to the current program running point if its name
member. I store the image names a bit differently in my project.
The code above almost works: I can iterate through 4/5 images OK, but when last image is displayed and a key is pressed, the image goes gray and I can not close the image window withouth crashing the rest of my application.
My first idea was that becouse of compile-time optimizations, cvReleaseImage
releases the image before cvDestroyWindow
is finished, and that somehow makes it freeze. But, I've tried adding some waiting time (hence the commented out sleep(1)
line of my code) and it didn't help.
I am calling this display functionality from my console application, and when the image freezes, the control returns back to my application and I can keep using it (but the image window is still frozen in the background).
Can you give me any suggestions on how to fix this?
EDIT
I have talked to some people dealing with computer vision and OpenCV on a regular basis since asking the question, and still no ideas.
I have also found a similar stackoverflow question, but there is still no accepted answer. Googleing just gives similar questions as a result, but no answers.
Any ideas on what to try (even if they are not the complete solution) are very much appreciated.