title: Show different images in OpenCV imshow
body: <p>I want to show images to emulate some animation with OpenCV imshow. Currently, I have the below codes:</p>
  
  <pre><code>int display_avatar(int idx){  
      Mat image;
      char* imagepath = new char[128];
      switch (idx){
          case 0:
              strcpy(imagepath, "c:\\images\\a.png");
              break;
          case 1:
              strcpy(imagepath, "c:\\images\\b.png");
              break;
          default:
              break;
      }
      image = imread(imagepath, IMREAD_COLOR);
  
      if (!image.data){
          cout &lt;&lt; "Could not open or find the image" &lt;&lt; std::endl;
          return -1;
      }
  
      namedWindow("Display window", WINDOW_AUTOSIZE);
      imshow("Display window", image);
      waitKey(0);
      return 0;
  }
  
  int main(){
      display_avatar(0);
      getchar();
      display_avatar(1);
      getchar();
      return 0;
  }
  </code></pre>
  
  <p>Now I use <code>getchar()</code> to trigger the animation. But I find the program will popout two windows (a console window and a <code>namedWindow</code>). Only after I close the <code>namedWindow</code>, another window will appear. How can I do the image change within the same window?</p>