Skip to content

Instantly share code, notes, and snippets.

@garybradski
Created October 4, 2017 23:09
Show Gist options
  • Save garybradski/57a9f76087c698211f2f73b6ed00d77f to your computer and use it in GitHub Desktop.
Save garybradski/57a9f76087c698211f2f73b6ed00d77f to your computer and use it in GitHub Desktop.
Using python matplotlib and opencv cv2 imshow in the same loop using the keyboard to trigger pause or run
import cv2
from matplotlib import pyplot as plt
. . .
#DO PYTHON MATPLOTLIB IMAGE DISPLAY
plt.imshow(image_seg)
plt.draw()
plt.show() # , plt.draw(), plt.show()
plt.pause(0.01)
#DO OPENCV IMSHOW IMAGE DISPLAY
cv2.imshow("video", frame)
#key handling
k = cv2.waitKey(wait_key) & 0xff
if chr(k) == 'r': #start running
wait_key = 30
elif chr(k) == 'p': #pause between frames
wait_key = 0
elif k == 27: #end processing
break
else:
k = 0
@garybradski
Copy link
Author

Now you can use either and step though them in an OpenCv manner or just "r" for run, "p" for pause, "esc" for quit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment