OpenCV人脸识别detectMultiScale问题

时间:2020-05-06 11:10:52

标签: python opencv face-detection

我正在尝试实现一段代码来检测报纸文章中的面孔。因此,我运行了这段代码,它有些起作用(它也发现了一些错误):

True

这很奏效,但是有很多误报/否定,即使我使用了detectMultiscale参数,但仍然无法获得很好的匹配。因此,我尝试运行一些for循环,以查看是否有任何组合产生了准确的匹配数(仅在数字上-如果某个组合可以精确地找到9张面孔)。我尝试了这段代码:

test_img = imgs["a-0.png"].copy()
opencvImage = cv.cvtColor(np.array(test_img), cv.COLOR_RGB2GRAY)
test_img1 = opencvImage.copy()
thresh, cv_img_bin=cv.threshold(test_img1,180,255,cv.THRESH_BINARY)
cv_img_bin.tolist()
faces = face_cascade.detectMultiScale(cv_img_bin, scaleFactor = 1.20, minNeighbors = 2, minSize=(80,80))
drawing=ImageDraw.Draw(test_img0) # creates a drawing object
for x,y,w,h in faces:
    drawing.rectangle((x,y,x+w,y+h), outline="red", width=4)
display(test_img0)

它不起作用,会向我抛出错误:

test_img1 = opencvImage.copy()
for thr in range(100,240,10):
    thresh, cv_img_bin = cv.threshold(test_img1, thr, 255, cv.THRESH_BINARY)   
    cv_img_bin.tolist()
    for scaleFac in [1,1.05,1.1,1.15,1.20,1.25,1.30]:
        for minNeigh in [1,2,3,4,5,6,7,8,9,10]:
            for w in [30,40,50,60,70,80,90,100,110]:
                faces = face_cascade.detectMultiScale(cv_img_bin, scaleFactor = scaleFac, minNeighbors = minNeigh, minSize =(w,w))
                if len(faces) == 9:
                     print: """Threshold: {}
                            scaleFactor:{}
                            minNeighbours{}:
                            width:{}""".format(thr, scaleFac, minNeigh, w)

我不知道为什么,对我来说,似乎上面的代码相同。我尝试调整for循环,仍然出现相同的错误。这是怎么回事?

0 个答案:

没有答案