python - 将 PiCamera 图像阵列从一个 Raspberry Pi 流式传输到另一个
问题描述
我正在使用 Raspberry Pi 和 OpenCv 构建家庭监控系统。基本上,我的设置将包括两个设备,第一个是安全摄像头,它是一个树莓派零和一个 pi 摄像头。另一个设备将是一个主集线器(Raspberry Pi 3),它将完成所有繁重的工作,例如面部识别、语音识别和其他操作。
我想做的是将安全摄像头的镜头流式传输到主集线器,以便它可以处理图像。所以基本上我想从 pi 相机捕获帧,将其转换为 numpy 数组(如果默认情况下没有这样做)并将该数据发送到主集线器,然后转换回要分析的图像帧通过 Opencv。
我将操作分开,因为我的安全摄像头在树莓派零上运行,它不是很快并且无法处理繁重的工作。这也是因为我的安全摄像头连接到电池,我正试图降低 Pi 的使用率,因此我将主集线器专用于繁重的操作。
我在两个设备上都使用了 python v3 环境。对mqtt、TCP等物联网通信技术了如指掌。但是,为了满足我的需求,我想帮助我在 python 脚本中实际实现这些技术。
解决方案
我认为分解你的任务会更好。1. 从 pi0 捕获图像流并进行流式传输。2. 从 pi1 获取流并在 pi3 中处理
帮助您开始图像捕获的示例代码,您可以在此处找到:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
你需要自己找到这个。将视频流式传输到 URL :: IP.Add.ress.OF_pi0/cam_read
然后使用此 URL 处理此处的 pi3 示例代码中的视频:
import numpy as np
import cv2
# Open a sample video available in sample-videos
vcap = cv2.VideoCapture('IP.Add.ress.OF_pi0/cam_read')
#if not vcap.isOpened():
# print "File Cannot be Opened"
while(True):
# Capture frame-by-frame
ret, frame = vcap.read()
#print cap.isOpened(), ret
if frame is not None:
# Display the resulting frame
cv2.imshow('frame',frame)
# use other methods for object face or motion detection
# OpenCV Haarcascade face detection
# Press q to close the video windows before it ends if you want
if cv2.waitKey(22) & 0xFF == ord('q'):
break
else:
print "Frame is None"
break
# When everything done, release the capture
vcap.release()
cv2.destroyAllWindows()
print "Video stop"
这个答案不是您问题的直接解决方案。相反,它是您入门的骨架。人脸检测可以在这里找到
推荐阅读
- z3 - Z3中是否有测试数字是否有理的功能?
- unit-testing - 错误:ENOENT:没有这样的文件或目录,stat '/.VolumeIcon.icns'
- python - 如何查看员工选择的特定日期每位客户下的订单数量?
- .net-core - asp.net webapi 2 post 参数值始终为 null(string) 或 0(int)
- swift - 为什么我在 Xcode 调试控制台中收到错误消息“无法识别的选择器”
- html - 我正在尝试将图像放在导航选项卡下方
- django - /admin/pizza/topping/add/ 'NoneType' 对象的 AttributeError 没有属性 'attname'
- javascript - HTML上的按钮调用谷歌脚本
- python - 从 pandas .apply 过渡到矢量化方法
- reactjs - React - 更改导入组件的值