我有一台带摄像头的Rasberry Pi,并使用RPi Cam Web界面将视频流式传输到我的浏览器。我运行一个脚本来读取图像并像下面一样处理它们。运行代码会在当前时间打开一个包含已处理图像的窗口。当我关闭窗口时,我得到一个更新的处理过的图像。
然而,我想要做的是输出已处理图像的连续视频。我应该采取什么方法来做到这一点?
while True:
image = io.imread('http://[ip-address]/cam_pic.php')
image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
faces = detect(image_gray)
image_with_detected_faces = faces_draw(image, faces)
plt.imshow(image_with_detected_faces)
plt.show()
答案 0 :(得分:2)
您可能需要查看以下问题:https://cloud.google.com/monitoring/api/metrics直接使用VideoCapture。如果您想要从http读取图像,可以将其更改为以下之一。
互动模式
import cv2
import matplotlib.pyplot as plt
def grab_frame():
image = io.imread('http://[ip-address]/cam_pic.php')
image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
faces = detect(image_gray)
return faces_draw(image, faces)
#create axes
ax1 = plt.subplot(111)
#create image plot
im1 = ax1.imshow(grab_frame())
plt.ion()
while True:
im1.set_data(grab_frame())
plt.pause(0.2)
plt.ioff() # due to infinite loop, this gets never called.
plt.show()
<强> FuncAnimation 强>
import cv2
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
def grab_frame():
image = io.imread('http://[ip-address]/cam_pic.php')
image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
faces = detect(image_gray)
return faces_draw(image, faces)
#create axes
ax1 = plt.subplot(111)
#create axes
im1 = ax1.imshow(grab_frame())
def update(i):
im1.set_data(grab_frame())
ani = FuncAnimation(plt.gcf(), update, interval=200)
plt.show()