您可能需要看一下这个问题:使用直接使用VideoCapture的实时摄像机预览来更新matplotlib中的帧。相反,如果您想从http中读取图像,则可以将其更改为以下内容之一。
互动模式
import cv2import matplotlib.pyplot as pltdef 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 axesax1 = plt.subplot(111)#create image plotim1 = 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()
功能动画
import cv2import matplotlib.pyplot as pltfrom matplotlib.animation import FuncAnimationdef 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 axesax1 = plt.subplot(111)#create axesim1 = ax1.imshow(grab_frame())def update(i): im1.set_data(grab_frame())ani = FuncAnimation(plt.gcf(), update, interval=200)plt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)