I\'ve got a Rasberry Pi with a camera and am streaming video to my browser using the RPi Cam Web interface. I run a script to read in the images and process them like below.
You may want to look at this question: update frame in matplotlib with live camera preview which directly uses VideoCapture. If instead you want to read the images from http you can change this to one of the following.
Interactive mode
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()