How to show an image in opencv when in a loop?
I have IplImage *
structures, and I am trying to have a loop to show an Image to a user, and ask them if the shown image is OK.
Basically, when displaying an ima开发者_StackOverflow中文版ge in passing this method of using cvShowImage
works. However, since it is looped it doesn't seem to be working. I only see a gray screen until I hit y
. If I hit y
and it breaks, it then shows me the images.
Here is the gist of what I have.
char response;
int showing_img = 1;
SaveImage1(); // these methods just save the IplImage structure.
SaveImage2();
cvShowImage("Image 1", img_1);
cvShowImage("Image 2", img_2);
while (1)
{
if (!showing_img)
{
cvShowImage("Image 1", img_1);
cvShowImage("Image 2", img_2);
showing_img = 1;
}
printf("Are these good? y/n please\n");
scanf("%c", &response);
if (response == 'y')
{
break;
}
if (response == 'n')
{
cvReleaseImage(&img_1);
cvReleaseImage(&img_2);
showing_img = 0;
SaveImage1(1);
SaveImage2(1);
}
}
How should I be doing this, instead?
You have to let the system update the images. Insert a call to cvWaitKey in the loop, that should fix your problem.
精彩评论