Haar Training detectMultiScale does not work very well when size vary

asked 2016-10-07 13:00:11 -0500

Neldar gravatar image


I created my CascadeClassifier in order to find in some images if a parking sign is present. Sadly, it does not work very well. When I analyse the image from my webcam, taking a picture of a parking sign I printed and vary the distance between the image and my webcam, it only work when I am at a quite precise distance. The cascade identifier does not work when the image appear too big or too small.

I played with the scaleFactor but it didn't helped. Could you help me find a way to identify if a parking sign is in the picture, whatever the size of it in the picture?

edit retag flag offensive close merge delete


What method are you using to detect the parking sign? How have you trained the cascade? How many negative or positives ?

Some code would be helpful.

atv gravatar imageatv ( 2016-10-08 03:40:15 -0500 )edit

The code I'm using to test my classifier is the following: import numpy as np import cv2

parking_cascade = cv2.CascadeClassifier('cascadeP2.xml')
cap = cv2.VideoCapture(0)

while 1:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # image, reject levels level weights.
    parkinges = parking_cascade.detectMultiScale(gray, 5, 50)

    for (x,y,w,h) in parkinges:
    k = cv2.waitKey(30) & 0xff
    if k == 27:


I trained my classifier withe 1950 negative, positives images and 30 steps for the haartraining.

Neldar gravatar imageNeldar ( 2016-10-08 09:30:58 -0500 )edit