Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:52:22+00:00 2026-05-28T16:52:22+00:00

I am doing on a project for searching through an image database, and when

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:52:23+00:00Added an answer on May 28, 2026 at 4:52 pm

    For testing purposes, the application below does exactly what you stated in the question: it loads 7 images through the command line, one by one, and creates a new window for each image to be display.

    It works flawlessly with OpenCV 2.3.1 on Linux.

    #include <cv.h>
    #include <highgui.h>
    
    #define NUM_IMGS 7
    
    int main(int argc, char* argv[])
    {
        if (argc < 8)
        {
            printf("Usage: %s <img1> <img2> <img3> <img4> <img5> <img6> <img7>\n", argv[0]);
            return -1;
        }
    
        // Array to store pointers for the images
        IplImage* images[NUM_IMGS] = { 0 };
    
        for (int i = 0; i < NUM_IMGS; i++)
        {
            // load image
            images[i] = cvLoadImage(argv[i+1], CV_LOAD_IMAGE_UNCHANGED);
            if (!images[i])
            {
                printf("!!! failed to load: %s\n", argv[i+1]);
                continue;
            }
    
            // display image in a window
            cvNamedWindow(argv[i+1], CV_WINDOW_AUTOSIZE); // creating a new window each time
            cvShowImage(argv[i+1], images[i]);
    
            // wait for keypress
            cvWaitKey(0);
    
            // close the window
            cvDestroyWindow(argv[i+1]);
            cvReleaseImage(&images[i]);
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im doing this project where i need to download files through a webservice (images,
I did some fairly thorough reading and searching through SO and didn't find anything
I am doing a project which searches a specific member from my database searching
Hey there! I'm doing this project and right now I'm trying to: create some
I'm doing a project where I need to either find or build an RSA
I find myself doing the following a lot: C:\Code>hg pull pulling from http://server/FogBugz/kiln/Repo/Project/Rebuild/trunk searching
I'm doing a Unity-iPhone project, but want to automatically add some native code and
We are using state_machine ( https://github.com/pluginaweek/state_machine ) in a project and would like to
I am doing project euler question 33 and have divised a refactor to solve
After doing a project with WPF and getting very much attached to it's excellent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.