Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于树莓pi3的人脸识别与跟踪_Python_Opencv_Raspberry Pi3 - Fatal编程技术网

Python 基于树莓pi3的人脸识别与跟踪

Python 基于树莓pi3的人脸识别与跟踪,python,opencv,raspberry-pi3,Python,Opencv,Raspberry Pi3,我在用树莓皮3项目做人脸跟踪机器人。我已经用树莓pi上的opencv完成了人脸检测部分。我需要有关电机控制的帮助我们可以使用识别的实时人脸调整电机控制。在识别过程中,将摄像头的帧划分为多个部分,然后简单地对其进行标记,并根据标记部分中检测到的人脸的位置更改电机控制代码。 例如 while(True): ret,img=cam.read() 灰色=cv2.CVT颜色(img,cv2.COLOR\U BGR2GRAY) 高度、宽度、通道=img.shape reg=宽度/4 面=检测器。检测器多尺度

我在用树莓皮3项目做人脸跟踪机器人。我已经用树莓pi上的opencv完成了人脸检测部分。我需要有关电机控制的帮助

我们可以使用识别的实时人脸调整电机控制。在识别过程中,将摄像头的帧划分为多个部分,然后简单地对其进行标记,并根据标记部分中检测到的人脸的位置更改电机控制代码。 例如

while(True):
ret,img=cam.read()
灰色=cv2.CVT颜色(img,cv2.COLOR\U BGR2GRAY)
高度、宽度、通道=img.shape
reg=宽度/4
面=检测器。检测器多尺度(灰色,1.3,5)
对于面中的(x,y,w,h):
中心_x=x+w/2
中心y=y+w/2
cv2.矩形(img,(x,y),(x+w,y+h),(255,0,0),2)
如果面不是无:
如果中心_x((宽度+间隙)/2):
打印('右')
右转()
其他:
打印('中心')
前进()
其他:
停止()
框架分为4个部分(reg=宽度/4)
希望,这可能会有所帮助

欢迎来到Stack Overflow!请参观并阅读帮助中心,尤其是您在这里的最佳选择是做您的研究,搜索相关主题,并尝试一下。如果你在做了更多的研究和搜索后陷入困境,无法摆脱困境,请发布一个你尝试的例子,并具体说明你陷入困境的地方。人们会乐意帮忙的。
while(True):
    ret, img = cam.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    height, width, channels = img.shape
    reg=width/4

    faces = detector.detectMultiScale(gray, 1.3, 5)
    for (x,y,w,h) in faces:
        centre_x = x + w/2
        centre_y = y + w/2
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        if faces is not None:
            if centre_x<((width-reg)/2):
                print('left')
                leftturn()
            elif centre_x>((width+reg)/2):
                print('right')
                rightturn()
            else:

                print('center')
                forward()
        else:
            stop()