繁体   English   中英

为什么我的 dlib.get_frontal_face_detector() 的输出(rectangles[]) 是空的?

[英]why my dlib.get_frontal_face_detector()'s output(rectangles[]) is empty?

我尝试使用Dlib shape_predictor_68_landmark来标记我的照片。 我使用 OpenCV 读取和调整照片大小(所有照片都是从视频中捕获的肖像照片)。 然后我使用这些处理过的照片来运行函数dlib.get_frontal_face_detector()

这是我的代码:

detector=dlib.get_frontal_face_detector()
for filename in os.listdir("/content/drive/MyDrive/new"):
  frame = cv2.imread("/content/drive/MyDrive/new/" + filename)
  frame = cv2.resize(frame, (720, 720), interpolation=cv2.INTER_NEAREST)
  faces = detector(frame, 0) 
  print('File name:',filename)
  print('Face=',faces)

faces = detector(frame, 0)应该输出一个rectangles[] ,但是当我打印它进行检查时,它的输出结果是一个空的rectangles[] 结果(部分)如下:

File name: frame_484.jpg
Face= rectangles[]

我不知道如何让它输出正确的输出(换句话说,不是空的矩形 [])。

模型不输出矩形,这意味着模型无法检测到给定图像中的任何人脸,但您可以尝试改进结果:

  • 在使用rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)进行预测之前将图像转换为 RGB
  • 尽量不要将图像大小调整为(720,720)或以这样的方式调整大小,以使原始图像的纵横比保持不变

如果所有这些都不起作用,那么您可以尝试 dlib 的 CNN 模块,它比 frontal_face 模块dlib.cnn_face_detection_model_v1具有更好的准确性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM