Search code examples
pythonopencvimage-processinghaar-classifier

How to change shape of opencv detected scale


My problem is the width and height of rectangle are equals and I want to change it to rectangle not square (width and height are different)

image sample
and this is my code

img = cv2.imread(pic)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
coils,reject,level = coil_cascade.detectMultiScale3(gray,1.3,5, outputRejectLevels=True)
for (x,y,w,h) in coils:
    cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    cv2.imshow('img',img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

Solution

  • If you train it with squares it will of course output squares. There is only one scale factor for both dimensions.

    To change that either train it with the desired aspect ratio or change the rectangles befor drawing them.