Ask Your Question
1

imshow() sometimes don't clear previous image

asked 2017-08-29 00:56:57 -0600

salman gravatar image

updated 2017-08-29 10:30:56 -0600

 #include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace cv;
using namespace std;

int main()
{
    String folder = "F:/8TH SEMESTER/Traffic Sign Dectection/30speed/*.ppm";
    //string folder = ("F:/Hammad Profile/FYP/German/GTSDB/FullIJCNN2013/*.ppm");
    vector<String> filenames;

    glob(folder, filenames);

    Mat myImage;

    for (size_t i = 0; i < filenames.size(); i++)
    {
        myImage = imread(filenames[i]);
        imshow("Sample Traffic signs", myImage);
        int c = cv::waitKey(400);
    }

    return 0;
}

"For example if 1st image is display and then 2nd so it display it but some portion of 1st image is show. why this happen.

edit retag flag offensive close merge delete

Comments

"but some portion of 1st image is show. " -- this is unclear

berak gravatar imageberak ( 2017-08-29 03:38:45 -0600 )edit
1

when small images (having different width and height ) displayed in same window consecutively, sometimes some part of previous image still visible on window.question is connected with other question http://answers.opencv.org/question/17... i will merge two questions into one later.

sturkmen gravatar imagesturkmen ( 2017-08-29 09:27:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2017-08-29 09:24:34 -0600

updated 2017-08-29 10:11:14 -0600

this is not a serious problem but you can avoid it by using destroyWindow() or destroyAllWindows() before imshow()

TEST CODE:

#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main()
{   
    Mat m1(50, 100, CV_8UC3, Scalar(255, 0, 0));
    Mat m2(100, 50, CV_8UC3, Scalar(0, 0, 255));

    imshow("test", m1);
    waitKey(0);
    imshow("test", m2);
    waitKey(0); 

    imshow("test", m1);
    waitKey(0);
    destroyWindow("test"); // or    destroyAllWindows();
    imshow("test", m2);
    waitKey(0);

    return 0;
}

image description ......... image description

image description ......... image description

edit flag offensive delete link more

Comments

can someone try this code on linux environment? i wonder if this problem exist on linux

sturkmen gravatar imagesturkmen ( 2017-08-29 10:32:48 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-29 00:56:57 -0600

Seen: 12,435 times

Last updated: Aug 29 '17