如何实时处理图像并输出结果的实时视频? [英] How to process images in real-time and output a real-time video of the result?

查看:382
本文介绍了如何实时处理图像并输出结果的实时视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带相机的Rasberry Pi,并且正在使用RPi Cam Web界面将视频流式传输到我的浏览器中。我运行脚本以读取图像并按如下方式处理它们。运行代码将打开一个窗口,其中包含当前时间的已处理图像。关闭窗口时,我得到了更新的处理过的图像。

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. Running the code opens a window with the processed image at the current time. When I close the window, I get an updated processed image.

我想做的是输出处理后图像的连续视频。 。我应该采取哪种方法?

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


推荐答案

您可能想看一下这个问题:使用实时摄像机预览更新matplotlib中的帧,直接使用VideoCapture。相反,如果您想从http读取图像,则可以将其更改为以下内容之一。

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.

交互模式

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

这篇关于如何实时处理图像并输出结果的实时视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆