test own Haar-Cascade

Discussion related to "under the hood" OpenMV topics.
scnuelc
Posts: 2
Joined: Sun May 20, 2018 9:06 am

test own Haar-Cascade

Postby scnuelc » Thu May 24, 2018 11:44 pm

Hi,

currently I am trying to creat a trafficsign-recognition haarcascade to my MV-cam. I used data from GTSRB(http://benchmark.ini.rub.de/?section=gt ... on=dataset) and after using openCV and (https://github.com/openmv/openmv/blob/m ... cascade.py) script I have get the trafficsign-recognition.cascade. but Then I import in MV-cam

# the cascade script is on the internal flash drive
trafficsign_cascade = image.HaarCascade("/trafficsign.cascade", stages=15)

...

while (True):
clock.tick()

# Capture snapshot
img = sensor.snapshot()

# Find objects.
# Note: Lower scale factor scales-down the image more and detects smaller objects.
# Higher threshold results in a higher detection rate, with more false positives.
objects = img.find_features(trafficsign_cascade, threshold=1, scale_factor=1.35)

# Draw objects
for r in objects:
img.draw_rectangle(r)


But my script just does nothing. It gets the snapshots, but recognized nothing. Does anyone have any experience in making MV-cam own haar-cascades?
What's more ,I use the opencv own data(for example: haarcascade_eye.xml) transform to haarcascade_eye.cascade and also test again,but just like the above that recognized nothing. So,I might be something wrong but I don't realize.
Should I used the data that snapshots from MV-cam to train xml again? Or just because the parameter I choose to use opencv train is inapposite.(the image size,-nstages .etc )

best regards
Attachments
cascade_made.zip
Here is the data after I preconditioning and the xml I trained and the cascade I made
(3.48 MiB) Downloaded 4 times
User avatar
iabdalkader
Posts: 465
Joined: Sun May 24, 2015 3:53 pm

Re: test own Haar-Cascade

Postby iabdalkader » Fri May 25, 2018 7:53 pm

Hi, your cascade has only 2 stages I expected much more, which makes think it probably won't work so I tested it with OpenCV on a pos image and it doesn't detect it:

Code: Select all

import numpy as np
import cv2 as cv

cascade = cv.CascadeClassifier('trafficsign/trafficsign.xml')
img = cv.imread('trafficsign/pos/00000_00000.jpg')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
objs = cascade.detectMultiScale(gray, 1.05, 1)

for (x,y,w,h) in objs:
    cv.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]

cv.imshow('img',img)
cv.waitKey(0)
cv.destroyAllWindows()
Also it's probably best to use a window where w == h (ex. 30x30).
scnuelc
Posts: 2
Joined: Sun May 20, 2018 9:06 am

Re: test own Haar-Cascade

Postby scnuelc » Fri May 25, 2018 10:02 pm

iabdalkader wrote:
Fri May 25, 2018 7:53 pm
Hi, your cascade has only 2 stages I expected much more, which makes think it probably won't work so I tested it with OpenCV on a pos image and it doesn't detect it:

Code: Select all

import numpy as np
import cv2 as cv

cascade = cv.CascadeClassifier('trafficsign/trafficsign.xml')
img = cv.imread('trafficsign/pos/00000_00000.jpg')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
objs = cascade.detectMultiScale(gray, 1.05, 1)

for (x,y,w,h) in objs:
    cv.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]

cv.imshow('img',img)
cv.waitKey(0)
cv.destroyAllWindows()
Also it's probably best to use a window where w == h (ex. 30x30).
Really thanks a lot,I will try again

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 10 guests