【问题标题】:How to get single bounding box while detecting face using opencv and python如何在使用opencv和python检测人脸时获得单个边界框
【发布时间】:2019-07-09 10:32:08
【问题描述】:

我在使用 opencv 检测人脸时没有得到完美的准确度。

这是我的代码:

import cv2

#create a cascadeclassifier object
face_cascade = cv2.CascadeClassifier("C:/Users/yash/AppData/Local/Programs/Python/Python35/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml")
#create a cascade classifier.it will contain the features of the face

#reading the image as it is
img = cv2.imread("profile.JPG")

#reading the image as gray_scale image
gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #converting colored image to gray scale

#search the co-ordinates of the image
faces = face_cascade.detectMultiScale(gray_img,scaleFactor = 1.05,minNeighbors=5)
#scaleFactor = decreases the shape value by 5%,until the face is found .smaller this value , the greater is the accuracy.
#detectMultiScale = method to search for the face rectangle co-ordinates

#print(type(faces))
#print(faces)

for x,y,w,h in faces:
    img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3)

resized_img = cv2.resize(img,(int(img.shape[1]/2) , int(img.shape[0]/2)))    
cv2.imshow("face detection",resized_img)

cv2.waitKey(0)

cv2.destroyAllWindows()

这里是image,我正在努力获得完美的准确性。

【问题讨论】:

  • 看起来还不错,有什么问题?
  • 点击图片链接。它会看到两个矩形
  • “完美”是什么意思? 100% 准确率还是只有一个边界框?
  • 在任何分类任务中都很难实现“完美的准确性”。您可能需要查看该声明,因为这可能会使人们感到困惑。
  • @Nuzhny 不工作...

标签: python opencv face-detection cascade-classifier


【解决方案1】:

对于一张人脸,使用标志 CV_HAAR_FIND_BIGGEST_OBJECT 作为 detectMultiScale 中的最后一个参数。

但 Haar 级联现在并不是人脸检测的最佳选择。在 OpenCV 4.0 中,开发人员删除了 Haar 级联训练的代码——他们建议使用 DNN。 For example here.

其次:OpenCV 开发人员为 DNN 推理创建了一个开源框架 - OpenVINO 和很多 pretrained models(也用于人脸检测)。如果你想在 CPU 上拥有比 OpenVINO 更快的人脸检测器。

【讨论】:

    【解决方案2】:

    除了@Nuzhny 的推荐,你应该使用Non Maximum Suppression 算法来解决多次检测的问题。

    Pyimagesearch 有一篇非常好的文章以及有关此主题的代码,这将对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-06-18
      • 2011-06-25
      • 1970-01-01
      • 2012-04-17
      • 2016-02-25
      • 1970-01-01
      • 2020-09-20
      • 2015-12-18
      • 2018-09-05
      相关资源
      最近更新 更多