title: Using matplotlib on top of opencv image
body: <p>I am having some difficulty combining matplotlib and opencv. I have the following code that shows a video stream and pauses when the space bar is hit. I then want to use matplotlib to draw some annotations on top of the paused image (The user can then hit space to unpause and repeat the process). However, whenever I add any matplotlib functions it opens a separate figure window and I would ideally like to have my annotations directly on the image. I also looked at the available drawing functions in opencv and there is not enough functionality there for me (I am looking to fit a complicated curve to the paused image).  Any help would be greatly appreciated!!!!</p>
  
  <pre><code>import numpy as np
  import cv2
  from matplotlib import pyplot as plt
  
  cap = cv2.VideoCapture(0)
  
  while(True):
      # Capture frame-by-frame
      ret, im = cap.read()
  
      # Our operations on the frame come here
      im_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
      im_g = cv2.GaussianBlur(im_gray,(5,5),0)
      (thresh, im_bw) = cv2.threshold(im_g, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
      cv2.imshow('Window',im)  
  
      k = cv2.waitKey(1)
      if k &gt; 0:
          print k
      if k == 32:
          ##########
          # Plot on top of image using matplotlib
          ##########
          cv2.waitKey(0)
          continue
      elif k == 27:
          break
  
  # When everything done, release the capture
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>