2

Here is my implementation of HaarCascade where I trained my own classifier.

import cv2
import numpy as np

body_classifier = cv2.CascadeClassifier('C:\\Users\\Nemi\\MasteringComputerVision_V1.00\\Haarcascades\\trainedHuman.xml')
image = cv2.imread("twn2.jpg")
#####HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
bodies,rejectLevels, levelWeights = body_classifier.detectMultiScale3(
    image,
    scaleFactor=1.1,
    minNeighbors=20,
    minSize=(24, 24),
    maxSize=(96,96),
    flags = cv2.CASCADE_SCALE_IMAGE,
    outputRejectLevels = True
    )
print(rejectLevels)
print(levelWeights)
i = 0
font = cv2.FONT_ITALIC
for (x,y,w,h) in bodies:
    cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,255),2)
    font = cv2.FONT_HERSHEY_SIMPLEX
    #cv2.putText(image,str(i)+str(":")+str(np.log(levelWeights[i][0])),(x,y), font,0.5,(255,255,255),2,cv2.LINE_AA)
    cv2.putText(image,str(levelWeights[i][0]),(x,y), font,0.5,(255,255,255),2,cv2.LINE_AA)
    i = i+1

cv2.imshow("Detection",image)
cv2.waitKey(0)
cv2.destroyAllWindows()

The resulting output is as follows: enter image description here

I want to know what does this levelWeights mean and why are the value so small? If this levelWeights could be used in the form of confidence of detection window what I should I do?

Nemi Bhattarai
  • 181
  • 1
  • 4
  • 11

1 Answers1

1

levelWights returns the confidence level of a certain stage. In your case i is the object detected and 0 means the 1st stage. It is very small maybe because the objects are too far away and the classifier is initially trained to capture bigger size objects.

brasofilo
  • 25,496
  • 15
  • 91
  • 179