# test own Haar-Cascade

**URL:** <https://forums.openmv.io/t/test-own-haar-cascade/715>\
**Category:** OpenMV Boards\
**Created:** [May 25, 2018, 3:44am UTC](https://forums.openmv.io/t/test-own-haar-cascade/715 "2018-05-25T03:44:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scnuelc](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@scnuelc](https://forums.openmv.io/u/scnuelc)\
**Post date:** [May 25, 2018, 3:44am UTC](https://forums.openmv.io/t/test-own-haar-cascade/715/1 "2018-05-25T03:44:43Z")

</div>

Hi,

currently I am trying to creat a trafficsign-recognition haarcascade to my MV-cam. I used data from GTSRB([German Traffic Sign Benchmarks](http://benchmark.ini.rub.de/?section=gtsrb&subsection=dataset)) and after using openCV and ([https://github.com/openmv/openmv/blob/m](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  
[cascade\_made.zip](https://forums.openmv.io/uploads/short-url/lXKhGP7NQmiauA6vAZHiyBnpHuO.zip) (3.48 MB)

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [May 25, 2018, 11:53pm UTC](https://forums.openmv.io/t/test-own-haar-cascade/715/2 "2018-05-25T23:53:25Z")

</div>

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:

```python
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).

---

<div class="post-metadata">

**Author:** ![scnuelc](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@scnuelc](https://forums.openmv.io/u/scnuelc)\
**Post date:** [May 26, 2018, 2:02am UTC](https://forums.openmv.io/t/test-own-haar-cascade/715/3 "2018-05-26T02:02:00Z")

</div>

> [@](#):
>
> 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:
> 
> ```python
> 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
