当未找到人脸时,如何处理 deepFace.analyze() 中的错误?

mep*_*mba 0 python error-handling face-detection deepface

img=cv2.imread(face.jpg)
predictions= DeepFace.analyze(img)
Run Code Online (Sandbox Code Playgroud)

Error: Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False.

设置enforce_detectionFalse会导致即使图像中没有面部,它也会读取情绪

我们如何处理这个错误,让它告诉我们没有人脸?

Gre*_*F.R 5

解决此问题的最佳方法是读取错误,其中显示:“考虑将 enforce_detection 参数设置为 False。”

所以你可以通过不强制进行面部检测来简单地解决这个问题。

return DeepFace.verify(img1, img2 , enforce_detection=False)['verified']
Run Code Online (Sandbox Code Playgroud)

我的代码有错误,您的代码可能是

DeepFace.analyze(img1 , enforce_detection=False)
Run Code Online (Sandbox Code Playgroud)

编辑回复:

这是一个不同的问题,您可以首先尝试使用以下方法检测照片上是否有脸部:

https://www.digitalocean.com/community/tutorials/how-to-detect-and-extract-faces-from-an-image-with-opencv-and-python

只分析情绪,知道有一张脸!