How to process images in real-time and output a real-time video of the result?

前端 未结 1 1320
囚心锁ツ
囚心锁ツ 2021-01-07 05:32

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.

1条回答
  •  清酒与你
    2021-01-07 05:49

    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()
    

    0 讨论(0)
提交回复
热议问题