将PiCamera图像阵列从一台Raspberry Pi传输到另一台

时间:2018-11-17 10:28:49

标签: python opencv raspberry-pi raspberry-pi3

我正在使用Raspberry Pi和OpenCv构建家庭监视系统。 基本上,我的设置将包括两个设备,第一个是安全摄像机,这将是一个树莓派零和一个pi摄像机。另一个设备将是主集线器(Raspberry Pi 3),它将完成所有繁重的工作,例如面部识别,语音识别和其他操作。

我要做的是将安全摄像机的镜头传输到主集线器,以便它可以处理图像。所以从本质上讲,我想从pi相机捕获帧,将其转换为numpy数组(如果默认情况下未完成),然后将该数据发送到主集线器,然后转换回为要分析的图像帧通过Opencv。

我正在分开操作,因为我的安全摄像机在覆盆子pi 0上运行,该速度不是很快,并且无法处理重物。这也是因为我的监控摄像头已连接到电池,并且我试图降低Pi的使用率,因此为什么我要为繁琐的操作指定一个主集线器。

我在两个设备上都使用python v3环境。我非常了解IoT通信技术,例如mqtt,TCP等。但是,我想帮助您在python脚本中实际实现这样的技术,从而满足我的需求。

1 个答案:

答案 0 :(得分:0)

我认为最好分手。 1.从pi0捕获图像流并将其流化。 2.从pi1中获取流,并在pi3中进行处理

让您开始进行图像捕获的示例代码,您可以找到here

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

Live Video Streaming Python Flask

然后使用此URL处理pi3中的视频 here中的示例代码:

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"

此答案并非直接解决您的问题。相反,它是您入门的基础。可以找到人脸检测here

相关问题