【发布时间】:2017-08-23 07:24:11
【问题描述】:
我正在尝试使用 openCV 组合来自网络摄像头的提要,然后使用 matplotlib 更新图形。
获取和显示框架的基本示例:
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
cv2.imshow('frame',frame)
# When to exit loop - terminate program
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
使用 matplotlib 不断更新图形(随机绘制)的示例:
import numpy as np
import matplotlib.pyplot as plt
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# x goes from 0-9 numbers
# y goes from 0-100%
fig = plt.figure()
ax = plt.axes(xlim=(0, 9), ylim=(0, 100))
# line, = ax.plot([], [], lw=2)
rects = plt.bar(x, y, color='b')
def animate(i):
y = random.sample(xrange(100), 10)
for rect, yi in zip(rects, y):
rect.set_height(yi)
return rects
anim = animation.FuncAnimation(fig, animate,
frames=200, interval=20, blit=True)
plt.show()
所以我想要将两者结合在一起。应该通过传递我从框架中获得的结果来更新图表。我面临的主要问题是让两个窗口同时更新。 plt.show() 似乎阻止了其他一切。
你知道如何解决吗?
干杯
【问题讨论】:
-
你可以用 matplotlib 显示
frame...我想那样会更容易
标签: python opencv matplotlib