Python人脸识别范围

2024-05-23 14:19:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个检测人脸的python代码,但是如果我在3米远的地方,它就再也认不出我了。。。我是python新手,如果您能告诉我必须更改的代码,我想我可以做得更多

有人能帮我吗

while True:
    success, img = cap.read()
# img = captureScreen()
    imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25)
    imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)

    facesCurFrame = face_recognition.face_locations(imgS)
    encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)

    for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
        matches = face_recognition.compare_faces(encodeListKnown, encodeFace)
        faceDis = face_recognition.face_distance(encodeListKnown, encodeFace)
        
        matchIndex = np.argmin(faceDis)

        
        name = classNames[matchIndex].upper()
        
        if not matches[matchIndex]:

        else:
            y1, x2, y2, x1 = faceLoc
            y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
            cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
            cv2.rectangle(img, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)  
            cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
            
            

    cv2.imshow('Webcam', img)
    cv2.waitKey(1)
    ```

Tags: 代码imgcv2facex1x2recognitiony1
1条回答
网友
1楼 · 发布于 2024-05-23 14:19:01

我猜问题是在大距离和小脸上,而不是在算法上。 人脸识别。人脸位置()有一个参数: 上采样次数 尝试将其设置为2或更多:与要找到的较小面相同

相关问题 更多 >