title: opencv: saving images on mouseclick
body: <p>So I've been messing around with opencv, and am trying to figure out how to capture an image on a mouse click. I've looked around a bit, but I just can't seem to find an answer. Here's the code that I have so far.</p>
  
  <pre><code>import numpy as np
  import cv2
  
  
  def captureFrame(event,frame):
      if event == cv2.EVENT_LBUTTONDBLCLK:
          cv2.imwrite('pictures/testFrame.png',frame) # want to save frame here   
  
  def main():
      cv2.setMouseCallback('frame',captureFrame)
      cap = cv2.VideoCapture(0)
      cv2.namedWindow('frame',cv2.CV_WINDOW_AUTOSIZE)
  
      while(True):
          ret, frame = cap.read()
  
          if ret:
              cv2.imshow('frame',frame)
              if cv2.waitKey(1) &amp; 0xFF == ord('q'):
                  break
  
      cap.release()
      cv2.destroyAllWindows()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>The problem is that I want to pass the frame to the callback function captureFrame, but I'm not sure how to do that. Thanks! </p>