logo

我想实现人脸识别返回画出的框的中心坐标 在这个代码中 报出这个错误

2021-03-02 21:28
7
gfnx
import sensor, time, image

# 重置感光元件
sensor.reset()

# 感光元件设置
sensor.set_contrast(3)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
# HQVGA和灰度对于人脸识别效果最好
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
from image import SEARCH_EX, SEARCH_DS

face_cascade = image.HaarCascade("frontalface", stages=25)

print(face_cascade)

# FPS clock
clock = time.clock()



while (True):
    clock.tick()

    # 拍摄一张照片
    template = sensor.snapshot()


    r = template.find_template(template, 0.70, step=4, search=SEARCH_EX)
 
    for m in r:
        template.draw_rectangle(m)
        x = r[0]
        y = r[1] 
        w = r[2]
        h = r[3]
    print(r[0]+r[2]/2, r[1]+r[3]/2)
48e2ef18-3004-42ab-957a-ca68f6034ce5.png
2021-03-04 17:54
I
网红小智智 星瞳科技

人脸识别用的是find_features,你的代码是find_template。完全不对啊。

参考代码:

https://book.openmv.cc/example/07-Face-Detection/face-detection.html