树莓派相机的python线程

时间:2020-04-26 14:36:42

标签: python raspberry-pi

我对python线程有疑问。

我有3个我想要访问同一资源(相机)的应用程序。我想让相机开始流式传输帧,然后每个过程都根据需要以不同的分辨率拍摄帧(或者,如果效率不高,我可以稍后缩放图像)。我可以使这三个应用程序中的每一个独立运行,但是还没有找到一种成功地将它们线程化的方法。这三个都是从别人那里学到的,我很感激他们的分享。下面的积分。

应用程序1将视频供稿流式传输到Web服务器。

with picamera.PiCamera(resolution='640x480', framerate=16) as camera:    
    output = StreamingOutput()
    camera.start_recording(output, format='mjpeg')
    try:
        address = ('', 8000)
        server = StreamingServer(address, StreamingHandler)
        server.serve_forever()
    finally:
        camera.stop_recording()

应用程序2通常将小帧捕获到内存中以检测运动,然后如果满足某些条件,则将图像保存到磁盘。在这种情况下,我想获取低分辨率的帧以加快分析速度,并将它们仅保留在内存中。对于保存,我有兴趣为磁盘抓取一个更高分辨率的文件

def captureTestImage(settings, width, height):
    command = "raspistill %s -w %s -h %s -t 200 -e bmp -n -o -" % (settings, width, height)
    imageData = io.BytesIO()
    imageData.write(subprocess.check_output(command, shell=True))
    imageData.seek(0)
    im = Image.open(imageData)
    buffer = im.load()
    imageData.close()
    return im, buffer
while True:
    motionState = P3picam.motion()
    if motionState:
        with picamera.PiCamera() as camera:
            camera.resolution = (1920,1080)  
            camera.capture(picPath + picName)

应用程序3从视频流中获取帧,然后对它们使用openCV。

vs = VideoStream(src=0).start()
time.sleep(2.0)
while True:
    frame = vs.read()
    frame = imutils.resize(frame, width=500)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 

应用1个学分:http://picamera.readthedocs.io/en/latest/recipes2.html#web-streaming 应用2个学分:http://pastebin.com/raw.php?i=yH7JHz9w 应用3个学分:https://www.pyimagesearch.com/2018/06/25/raspberry-pi-face-recognition/

0 个答案:

没有答案