implement own Haar-Cascade

Discussion related to "under the hood" OpenMV topics.
fabianhummel
Posts: 6
Joined: Thu Feb 02, 2017 10:56 am

implement own Haar-Cascade

Postby fabianhummel » Fri Feb 03, 2017 4:17 am

Hi,

currently I am trying to implement my own hardhat-recognition to my MV-cam. For the Cascade classifier I used openCV and with my webcam it is working. Then I created a new .xml-classifier-file with the additional parameters "-SaveBaseFormat" and "-FeatureType HAAR" in order to make it usable for the MV-cam. Then I used this (https://github.com/openmv/openmv/blob/m ... cascade.py) script to transform it into a .cascade-file which I included like this into my micropython sript:

# the cascade script is on the internal flash drive
hat_cascade = image.HaarCascade("/cascade_scenario4.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(hat_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 including own haar-cascades?
Did I implement it right?

best regards
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Fri Feb 03, 2017 10:55 am

I've altered Ibrahim to this issue. Not sure how to start the debugging process for this as I don't know this part of the code.
Nyamekye,
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Fri Feb 03, 2017 11:11 am

Can you print the Haar Cascade object to see if it was loaded without issues?

Code: Select all

print hat_cascade
Nyamekye,
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Fri Feb 03, 2017 11:20 am

Hi, I'm not sure why it's not working, try to remove the stages argument to test all stages. If you can you attach the xml and binary cascades I'll test them for you.
fabianhummel
Posts: 6
Joined: Thu Feb 02, 2017 10:56 am

Re: implement own Haar-Cascade

Postby fabianhummel » Fri Feb 03, 2017 11:55 am

Hi :)

yes the print(hat_cascade) works. It prints values like:
20.13845
20.13423
20.13026
20.12651
20.12297
20.11963
...

I attached the XML, but I can't attach the .cascade-file due to the filetype..?

Best regards
Attachments
cascade_scenario4.xml
(67.04 KiB) Downloaded 101 times
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Fri Feb 03, 2017 6:12 pm

Zip it up.
Nyamekye,
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Fri Feb 03, 2017 7:41 pm

It seems to be working on some hats and not others:

Image

Note it has 16 stages (the script prints cascade info) you should use them all.

Update:
I used all cascade stages by just leaving out the stages arg:

Code: Select all

hat_cascade = image.HaarCascade("/cascade_scenario4.cascade")
Also used a 0.85 threshold and 1.15-1.25 scaling factor.
fabianhummel
Posts: 6
Joined: Thu Feb 02, 2017 10:56 am

Re: implement own Haar-Cascade

Postby fabianhummel » Mon Feb 06, 2017 3:20 am

Thanks for the replies :)
In the attachment ist the zipped up XML & Cascade

best regards
Attachments
d-shop.zip
(10.15 KiB) Downloaded 110 times
fabianhummel
Posts: 6
Joined: Thu Feb 02, 2017 10:56 am

Re: implement own Haar-Cascade

Postby fabianhummel » Mon Feb 13, 2017 4:49 am

Sorry for asking again, but can someone tell me wheather this .cascade-file is working?

Currently, when I run this code:

import sensor, time, image, pyb

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

greenLed = pyb.LED(2) # define green LED.

# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
hat_cascade = image.HaarCascade("/cascadesc22.cascade")
print(hat_cascade)
# frontalface
# /cascade_scenario4.cascade
# FPS clock
clock = time.clock()

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(hat_cascade, threshold=0.85, scale_factor=1.2)

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

greenLed.on()
time.sleep(10)
greenLed.off()

# Print FPS.
# Note: Actual FPS is higher, streaming the FB makes it slower.
print(clock.fps())


I just get the line: width:36 height:36 n_stages:17 n_features:150 n_rectangles:260
And the red-LED turns on and I can't do anything, not even disconnecting :/

What am I doing wrong?
attached the cascade-file

best reards
Attachments
cascadesc22.zip
(1.86 KiB) Downloaded 79 times
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Mon Feb 13, 2017 11:43 am

Hi, I've asked Ibrahim for help.
Nyamekye,
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Mon Feb 13, 2017 5:48 pm

No this one doesn't work, when I run the script my cam hangs, if you can attach the xml file for this cascade I'll regenerate it and test again.
fabianhummel
Posts: 6
Joined: Thu Feb 02, 2017 10:56 am

Re: implement own Haar-Cascade

Postby fabianhummel » Tue Feb 14, 2017 4:23 am

Hi,

I attached the XML-file.
Hope this helps solving my problem :)

best regards
Attachments
cascade.xml
(67.2 KiB) Downloaded 71 times
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Wed Feb 15, 2017 11:00 am

fabianhummel wrote:
Tue Feb 14, 2017 4:23 am
Hi,

I attached the XML-file.
Hope this helps solving my problem :)

best regards
Hi,

This one works (doesn't crash the camera) it's different from the one you sent before (cascadesc22.cascade) I'm attaching the binary cascade I made with the script
Attachments
cascade.zip
(1.69 KiB) Downloaded 90 times
fabianhummel
Posts: 6
Joined: Thu Feb 02, 2017 10:56 am

Re: implement own Haar-Cascade

Postby fabianhummel » Thu Feb 16, 2017 8:48 am

Hi all,

thanks for the replies!

I have another question:
I created the XML-file with openCV. In order to run it on my Laptop (using it's webcam) I created the new version of the XML-file (without the parameter -SaveBaseFormat).
The result is very good an it detects a lot of hardhats.
Now, in order to run it on the openMV-Cam I need the old format of the XML-file (created by using the parameter -SaveBaseFormat). But then I use the script (https://github.com/openmv/openmv/blob/m ... cascade.py) in order to convert it into a .cascade-file and it detects almost nothing. How ist this possible: I used the same parameters as I did for the new format. :/

Is this a common issue=?

best regards

Fabian
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Thu Feb 16, 2017 3:33 pm

Have you tired playing with the threshold and scale ratio?
Nyamekye,
Charlie
Posts: 1
Joined: Tue Jan 16, 2018 6:43 am

Re: implement own Haar-Cascade

Postby Charlie » Tue Jan 16, 2018 7:05 am

Hi iabdalkader,
I tried to replace the eye detection cascade with a new one. I converted the .xml file to .cascade file using the provided tool. But the video stream stuck and I think the camera cracked . I read the thread above and bascially the problem is the same as Fabianhummel's. You created a new binary cascade (cascade.zip) for him and it also works on my machine. I want to know how you did that. I also attached my xml file. It'll be great help if you create a binary cascade for me.

Best regards,
Attachments
eye_det.zip
(25.42 KiB) Downloaded 40 times
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Tue Jan 16, 2018 2:44 pm

Hi, it seems the cascade tool only works on Linux.
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Sat Feb 24, 2018 7:37 am

iabdalkader wrote:
Tue Jan 16, 2018 2:44 pm
Hi, it seems the cascade tool only works on Linux.
hi @iabdalkader
i want to create a cascade file from xml file
xml file is a opencv sample (haarcascade_fullbody)
i try to convert xml file to cscsde file whit openmv-cascade.py but it return


usage: conver [-h] [-i] [-n NAME] [-s STAGES] [-c] file
conver: error: too few arguments

Traceback (most recent call last):
File "C:\Users\azaduni\Desktop\conver", line 288, in <module>
main()
File "C:\Users\azaduni\Desktop\conver", line 272, in main
args = parser.parse_args()
File "C:\Python27\lib\argparse.py", line 1656, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "C:\Python27\lib\argparse.py", line 1688, in parse_known_args
return self._parse_known_args(args, namespace)
File "C:\Python27\lib\argparse.py", line 1901, in _parse_known_args
self.error(_('too few arguments'))
File "C:\Python27\lib\argparse.py", line 2311, in error
self.exit(2, _('%s: error: %s\n') % (self.prog, message))
File "C:\Python27\lib\argparse.py", line 2299, in exit
_sys.exit(status)
SystemExit: 2

its my xml file
and its openmv-cascade.py whit path chenged
Attachments
haarcascade_fullbody.xml
(465.65 KiB) Downloaded 49 times
conver.py
(10.07 KiB) Downloaded 44 times
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Sat Feb 24, 2018 3:34 pm

I don't know what conver.py is, please use our script:

./openmv-cascade.py haarcascade_fullbody.xml

Also Note it doesn't work on Windows.
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Mon Feb 26, 2018 7:34 am

iabdalkader wrote:
Sat Feb 24, 2018 3:34 pm
I don't know what conver.py is, please use our script:

./openmv-cascade.py haarcascade_fullbody.xml

Also Note it doesn't work on Windows.
thank you for answer to my question
i use your script and now had this problem
Attachments
ac.jpg
ac.jpg (122.39 KiB) Viewed 11587 times
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Mon Feb 26, 2018 12:09 pm

Please post the steps of what exactly you did.
Nyamekye,
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Mon Feb 26, 2018 3:43 pm

kwagyeman wrote:
Mon Feb 26, 2018 12:09 pm
Please post the steps of what exactly you did.
i download openmv-cascade.py and insert path of xml file in script
when i want run script in raspbian return this error
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Mon Feb 26, 2018 7:36 pm

Can you run it from the terminal so we can see the error ?
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Mon Feb 26, 2018 7:37 pm

here I converted the file for you.
Attachments
haarcascade_fullbody.cascade.zip
(12.92 KiB) Downloaded 68 times
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Tue Feb 27, 2018 12:36 pm

iabdalkader wrote:
Mon Feb 26, 2018 7:37 pm
here I converted the file for you.
Is there any tutorial to learn this topic like this??



https://www.youtube.com/watch?v=I8s4PDrIV4E
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Tue Feb 27, 2018 3:26 pm

No the script should work out of the box though, anyway we're going to add a built-in cascade converter to the IDE it's just a matter of time.
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Fri Mar 02, 2018 6:53 am

iabdalkader wrote:
Mon Feb 26, 2018 7:36 pm
Can you run it from the terminal so we can see the error ?
Attachments
Screenshot from 2018-03-02 03-49-18.png
Screenshot from 2018-03-02 03-49-18.png (1.19 MiB) Viewed 10708 times
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Fri Mar 02, 2018 10:48 pm

It looks like you have html in your script... i.e. you didn't download it right...
Nyamekye,
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Sat Mar 03, 2018 6:19 am

kwagyeman wrote:
Fri Mar 02, 2018 10:48 pm
It looks like you have html in your script... i.e. you didn't download it right...
Attachments
Screenshot from 2018-03-03 03-11-31.png
Screenshot from 2018-03-03 03-11-31.png (192.32 KiB) Viewed 10690 times
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Sat Mar 03, 2018 6:53 am

SADEGHRAHMANI1374 wrote:
Sat Mar 03, 2018 6:19 am
kwagyeman wrote:
Fri Mar 02, 2018 10:48 pm
It looks like you have html in your script... i.e. you didn't download it right...
thanks for replying

How to write the xml file to the script or in the other words how to Introduce xml file to script?
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Sat Mar 03, 2018 1:24 pm

Hi, you pass the xml file after the script name.
Nyamekye,
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Sat Mar 03, 2018 1:45 pm

kwagyeman wrote:
Sat Mar 03, 2018 1:24 pm
Hi, you pass the xml file after the script name.
I put the xml name in the script or in the terminal ?
if i must put in script
It is possible to place the modified file?
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Sat Mar 03, 2018 7:51 pm

Hi download the script like so:

Code: Select all

wget https://raw.githubusercontent.com/openmv/openmv/master/usr/openmv-cascade.py
Then run it like this:

Code: Select all

python2.7 openmv-cascade.py cascade_file.xml
SADEGHRAHMANI1374
Posts: 10
Joined: Sat Feb 24, 2018 7:11 am

Re: implement own Haar-Cascade

Postby SADEGHRAHMANI1374 » Sat Mar 03, 2018 10:48 pm

iabdalkader wrote:
Sat Mar 03, 2018 7:51 pm
Hi download the script like so:

Code: Select all

wget https://raw.githubusercontent.com/openmv/openmv/master/usr/openmv-cascade.py
Then run it like this:

Code: Select all

python2.7 openmv-cascade.py cascade_file.xml
Thank you so much
aqeelyaacob
Posts: 7
Joined: Fri Apr 06, 2018 11:05 pm

Re: implement own Haar-Cascade

Postby aqeelyaacob » Tue Apr 10, 2018 9:01 pm

hai,i got a problem here,when i try to convert the xml file using converter as here : https://github.com/openmv/openmv/blob/m ... cascade.py
i got an error. So here i attach the xml file.Seem i stuck to convert to cascade file.After that,does the cascade embedded directly to camera or i need to transfer the cascade into internal memory to load on another script.
Attachments
myhaar.xml
(1.75 KiB) Downloaded 26 times
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Wed Apr 11, 2018 11:24 am

aqeelyaacob wrote:
Tue Apr 10, 2018 9:01 pm
hai,i got a problem here,when i try to convert the xml file using converter as here : https://github.com/openmv/openmv/blob/m ... cascade.py
i got an error. So here i attach the xml file.Seem i stuck to convert to cascade file.After that,does the cascade embedded directly to camera or i need to transfer the cascade into internal memory to load on another script.
The converter doesn't work on Windows, try the attached cascade.

You need to copy the cascade to flash or sd card, see examples and replies to this post.
Attachments
myhaar.cascade.zip
(222 Bytes) Downloaded 47 times
aqeelyaacob
Posts: 7
Joined: Fri Apr 06, 2018 11:05 pm

Re: implement own Haar-Cascade

Postby aqeelyaacob » Fri Apr 13, 2018 1:15 am

iabdalkader wrote:
Wed Apr 11, 2018 11:24 am
aqeelyaacob wrote:
Tue Apr 10, 2018 9:01 pm
hai,i got a problem here,when i try to convert the xml file using converter as here : https://github.com/openmv/openmv/blob/m ... cascade.py
i got an error. So here i attach the xml file.Seem i stuck to convert to cascade file.After that,does the cascade embedded directly to camera or i need to transfer the cascade into internal memory to load on another script.
The converter doesn't work on Windows, try the attached cascade.

You need to copy the cascade to flash or sd card, see examples and replies to this post.
it all done,thanks to you.But the detection still low rate,does i need to add more positive image during making a cascade?.here i attach the video and also coding



import sensor, time, image

lens_mm = 2.8 # Standard Lens.
average_spool_height_mm = 360.0 #
image_height_pixels = 240.0 # QVGA
sensor_h_mm = 2.952 # For OV7725 sensor - see datasheet.
offest_mm = 100.0 # Offset fix...

# https://photo.stackexchange.com/questio ... in-a-photo
def rect_size_to_distance(r): # r == (x, y, w, h) -> r[3] == h
return ((lens_mm * average_spool_height_mm * image_height_pixels) / (r[3] * sensor_h_mm)) - offest_mm

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
spool_cascade = image.HaarCascade("myhaar.cascade", stages=1)
print(spool_cascade)

# FPS clock
clock = time.clock()

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(spool_cascade, threshold=0.75, scale_factor=1.25)

# Draw objects
for i in range(len(objects)):
img.draw_rectangle(objects)
img.draw_string(objects[0] - 16, objects[1] - 16, "Distance %d mm" % rect_size_to_distance(objects))

img.draw_cross(img.width()//2, img.height()//2, size = min(img.width()//5, img.height()//5))

# Print FPS.
# Note: Actual FPS is higher, streaming the FB makes it slower.
print("FPS %f" % clock.fps())
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Sun Apr 15, 2018 9:22 pm

aqeelyaacob wrote:
Tue Apr 10, 2018 9:01 pm
it all done,thanks to you.But the detection still low rate,does i need to add more positive image during making a cascade?.here i attach the video and also coding
I'm not sure, maybe try a lower scaling factor (1.15).
aqeelyaacob
Posts: 7
Joined: Fri Apr 06, 2018 11:05 pm

Re: implement own Haar-Cascade

Postby aqeelyaacob » Sun Apr 29, 2018 7:56 pm

iabdalkader wrote:
Sun Apr 15, 2018 9:22 pm
aqeelyaacob wrote:
Tue Apr 10, 2018 9:01 pm
it all done,thanks to you.But the detection still low rate,does i need to add more positive image during making a cascade?.here i attach the video and also coding
I'm not sure, maybe try a lower scaling factor (1.15).
it's done.thanks..Now i'm designing alignment algorithm for AGV.Openmv camera as input,then arduino as controller also encoder for each mecanum wheels as feedback for positioning agv.Btw can i make that openmv determine the spool position either left or right side plus with distance from camera(already done) to tell AGV position(Camera) against spool(target) ?
Attachments
WhatsApp Image 2018-04-30 at 07.50.31.jpeg
WhatsApp Image 2018-04-30 at 07.50.31.jpeg (66.25 KiB) Viewed 7480 times
Screenshot (16).png
Screenshot (16).png (261.62 KiB) Viewed 7480 times
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Tue May 01, 2018 6:38 pm

@aqeelyaacob Please post a new topic for that with as much details as possible.
Mars
Posts: 5
Joined: Tue Jun 12, 2018 2:11 am

Re: implement own Haar-Cascade

Postby Mars » Tue Jun 12, 2018 5:32 am

iabdalkader wrote:
Fri Feb 03, 2017 11:20 am
Hi, I'm not sure why it's not working, try to remove the stages argument to test all stages. If you can you attach the xml and binary cascades I'll test them for you.
I use my own haarcascade_eye.cascade to detect eye
Error: unaligned read buf:10004fd6 count3


best wishes
Thankyou
Falong
Posts: 8
Joined: Fri Jun 01, 2018 2:28 am

Re: implement own Haar-Cascade

Postby Falong » Tue Jun 19, 2018 11:35 pm

iabdalkader wrote:
Sat Mar 03, 2018 7:51 pm
Hi download the script like so:

Code: Select all

wget https://raw.githubusercontent.com/openmv/openmv/master/usr/openmv-cascade.py
The link above seems not existed any longer. I get it from https://github.com/openmv/openmv/blob/m ... convert.py
but when I ran it with attached xml file on ubuntu, it printed below error message:

Converting new XML format..
Traceback (most recent call last):
File "cascade_convert.py", line 422, in <module>
main()
File "cascade_convert.py", line 419, in main
cascade_binary_universal(args.file, args.stages, args.name)
File "cascade_convert.py", line 101, in cascade_binary_universal
cascade_binary(path, n_stages, name)
File "cascade_convert.py", line 183, in cascade_binary
rects = feature[idx].getElementsByTagName('_')
IndexError: list index out of range
Attachments
haarcascade_frontalface_alt2.xml
(527.95 KiB) Downloaded 28 times
-Falong
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Wed Jun 20, 2018 2:26 pm

Falong wrote:
Tue Jun 19, 2018 11:35 pm
iabdalkader wrote:
Sat Mar 03, 2018 7:51 pm
Hi download the script like so:

Code: Select all

wget https://raw.githubusercontent.com/openmv/openmv/master/usr/openmv-cascade.py
The link above seems not existed any longer. I get it from https://github.com/openmv/openmv/blob/m ... convert.py
but when I ran it with attached xml file on ubuntu, it printed below error message:

Converting new XML format..
Traceback (most recent call last):
File "cascade_convert.py", line 422, in <module>
main()
File "cascade_convert.py", line 419, in main
cascade_binary_universal(args.file, args.stages, args.name)
File "cascade_convert.py", line 101, in cascade_binary_universal
cascade_binary(path, n_stages, name)
File "cascade_convert.py", line 183, in cascade_binary
rects = feature[idx].getElementsByTagName('_')
IndexError: list index out of range
Hi, support for the new Haar cascade format is somewhat limited, we only support 1 feature and 2 alpha per weak classifier. This cascade has 2 features and 3 alpha per weak classifier so it's not going to work. See the haarcascade_frontalcatface.xml for an example of a supported new format cascade, or use the old format.
latheefth
Posts: 3
Joined: Sat Oct 13, 2018 6:46 pm

Re: implement own Haar-Cascade

Postby latheefth » Sat Oct 13, 2018 6:52 pm

Hi,
Does the cascade converter work on macos?I couldnt find the eye cascade binary in the Github directory, so had to generate it but it doesnt detect. I used the frontalface cascade binary provided and it works.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: implement own Haar-Cascade

Postby kwagyeman » Sat Oct 13, 2018 10:58 pm

Hi, I'll put some effort into updating the docs for all that in the future. Um, but, yest, it works on Mac if you have all the required libs.
Nyamekye,
latheefth
Posts: 3
Joined: Sat Oct 13, 2018 6:46 pm

Re: implement own Haar-Cascade

Postby latheefth » Sun Oct 14, 2018 3:13 am

Thanks for the reply. If the binary generated from the provided eye cascade xml doesn't detect the eye, what could be the problem? i pass roi from the frontalface detect. I have attached my files. Could you please share me a working eye cascade binary, i am confused?
Attachments
eye.zip
eye cascade
(63.82 KiB) Downloaded 1 time
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Tue Oct 16, 2018 2:18 pm

latheefth wrote:
Sat Oct 13, 2018 6:52 pm
Does the cascade converter work on macos?
Haven't tested it before on Mac.
latheefth wrote:
Sat Oct 13, 2018 6:52 pm
I couldnt find the eye cascade binary in the Github directory
The eye and face cascades are built-in the firmware because they are very common. To load a built-in cascade, just use its name without a path, ex:

Code: Select all

c = load('eye.cascade')
. Also, you can re-generate any cascade from xml using the script.

latheefth wrote:
Sat Oct 13, 2018 6:52 pm
If the binary generated from the provided eye cascade xml doesn't detect the eye, what could be the problem? i pass roi from the frontalface detect. I have attached my files. Could you please share me a working eye cascade binary, i am confused?
Could you try the example first using the built-in cascades, and see if it works ?

Examples->08-Eye-Tracking->face_eye_detection.py
latheefth
Posts: 3
Joined: Sat Oct 13, 2018 6:46 pm

Re: implement own Haar-Cascade

Postby latheefth » Tue Oct 16, 2018 4:35 pm

Hi,
face_eye_detection.py looks fine but it doesnt work with the eye cascade generated by me. I have attached the cascade in my previous post, could you please regenerate and try?
Thanks for the support. Much appreciated!
User avatar
iabdalkader
Posts: 550
Joined: Sun May 24, 2015 3:53 pm

Re: implement own Haar-Cascade

Postby iabdalkader » Wed Oct 17, 2018 2:14 pm

latheefth wrote:
Tue Oct 16, 2018 4:35 pm
Hi,
face_eye_detection.py looks fine but it doesnt work with the eye cascade generated by me. I have attached the cascade in my previous post, could you please regenerate and try?
Thanks for the support. Much appreciated!
The script should generate an identical cascade. Note I never tested the converted on Mac (and it doesn't work on Windows) I can only confirm it works on Linux, you could try to run the script on Linux VM and compare the output.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests