我在使用matplotlib和opencv时遇到了一些困难。我有以下代码显示视频流并在空格键被点击时暂停。然后我想使用matplotlib在暂停的图像上绘制一些注释(然后用户可以点击空格以取消暂停并重复该过程)。但是,每当我添加任何matplotlib函数时,它会打开一个单独的图形窗口,我希望我的注释直接在图像上。我还查看了opencv中可用的绘图功能,但是我没有足够的功能(我希望在暂停的图像中使用复杂的曲线)。任何帮助将不胜感激!!!!
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 > 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()