python - 树莓派相机的python线程
问题描述
我对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/
解决方案
推荐阅读
- c# - 使用上下文更新多条记录,ASP.NET C#
- mysql - MYSQL 查询中 SUM 与 LEFT JOIN 和 GROUP BY 混合
- java - 是否可以在 Gradle 中创建原型?
- netsuite - 链接到原始交易的任务字段
- javascript - 使用 PostMessage 获取元素
- java - 为什么将 BST 中的 aa 节点的键与 0 进行比较时不能使用 .compareTo()?
- python - 获取错误参数必须是字符串、类似字节的对象或数字,而不是“NoneType”
- sql - Hadoop - Hive - Impala - 重写查询以提高性能
- nuxt.js - Nuxt 在 `yarn generate` 时忽略 proxy.pathRewrite
- arrays - 如何将动态可选命名参数传递给颤动的数组?