how include haarcascade file in program

Discussion related to "under the hood" OpenMV topics.
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

how include haarcascade file in program

Postby chrisPyres66 » Thu Oct 04, 2018 6:13 am

Dear all,

I did my own haarcascade file and i want to include into program not to use SDCard.
Both main.py and haarcascade files work either from openIDE and SDCarrd, or only with SDCard.

I converted both main.py to ascii array and binary haardcascade file to hex array which are dynamically created in the program.
I compared both haarcascade files (original and created) without finding difference.

Unfortunately, image.HaarCaarcascade does not seem to work when the file is dynamically created...

Do i misunderstand something, or do i use wrong method ?

Thanks for help,
User avatar
iabdalkader
Posts: 552
Joined: Sun May 24, 2015 3:53 pm

Re: how include haarcascade file in program

Postby iabdalkader » Thu Oct 04, 2018 10:50 am

You mean you want to embed the cascade ? like the embedded face and eye cascades ? If so you'll need to generate the C headers and rebuild the firmware. The image.HaarCaarcascade function can only load binary cascades from storage.
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: how include haarcascade file in program

Postby chrisPyres66 » Fri Oct 05, 2018 3:35 am

Yes, i embed the binary cascade.cascade by creating an hex array and create file with make_flash_fs().
I dont know how to gerenate the C headers.

But my problem is still the same when i debug the program during the flash mount, it is not ever well mounted (file permission ?)...
In this case, when i try to load the file with image.HaarCascade(), the program debugger reboots.
PS: I debug with gdb, baremetal and stlink device.

I did not solve this problem, but the method works, sorry.
I should open another post about this flash mount but i am not sure if it is not due to my configuration.

Thanks,
User avatar
iabdalkader
Posts: 552
Joined: Sun May 24, 2015 3:53 pm

Re: how include haarcascade file in program

Postby iabdalkader » Fri Oct 05, 2018 10:24 am

chrisPyres66 wrote:
Fri Oct 05, 2018 3:35 am
Yes, i embed the binary cascade.cascade by creating an hex array and create file with make_flash_fs().
I dont know how to gerenate the C headers.
To embed the cascade you need to pass -c to cascade_convert.py

Code: Select all

parser.add_argument("-c", "--header",   action = "store_true",  help = "generate a C header")
It will generate a header with C code, add it to cascade.h. And then you need to handle loading the new cascade from flash in imlib_load_cascade:
https://github.com/openmv/openmv/blob/m ... aar.c#L250

Finally rebuild the fw.

Note if your cascade is generic and useful I could add it to the built-in cascades, what does it detect ?
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: how include haarcascade file in program

Postby chrisPyres66 » Tue Oct 09, 2018 4:46 am

Thanks, it is very helpfull.

I try to detect "OK" like this http://thefanzine.com/wp-content/upload ... 4/2436.jpg
I think a CNN would be better to detect letters, but i dont have gpu in my computer right now to check it.

I used your method to create headers with different xml haarcascade files with success.
Except for the 64x64-20 stages file although i can convert to cascade.cascade.

The conversion to header stops to line 335

Code: Select all

# read cascade size
size = (map(int, xmldoc.getElementsByTagName('size')[0].childNodes[0].nodeValue.split()))
with indexError: list index out of range

I dont understand why the conversion works to binary and not to header...
Thanks for your light.
Last edited by chrisPyres66 on Thu Oct 11, 2018 11:49 am, edited 1 time in total.
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: how include haarcascade file in program

Postby chrisPyres66 » Wed Oct 10, 2018 4:03 am

I can see the xml haar cascade file headers are different if i did haar cascade file with
  • opencv under linux
    cascade trainer gui soft under microsoft
The differences are about tag: [Opencv] , [cascade trainer gui] like
  • size: [height, width] , [size]
    stage threshold: [stageThreshold], [stage_threshold]
    tree threshold: [internaltnode(3)] , [threshold]
    Alpha1: [leafValue(0)] , [leftValue]
    Alpha2: [leafValue(1)] , [rightValue]
    ....
I tried to correct it but the converted header file does not give me same result as converted cascade file.

Thanks for help
Last edited by chrisPyres66 on Thu Oct 11, 2018 11:49 am, edited 1 time in total.
User avatar
iabdalkader
Posts: 552
Joined: Sun May 24, 2015 3:53 pm

Re: how include haarcascade file in program

Postby iabdalkader » Wed Oct 10, 2018 7:02 pm

I don't quite understand the issue, but note the cascade needs to be the old format and the most basic cascade.
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: how include haarcascade file in program

Postby chrisPyres66 » Thu Oct 11, 2018 11:51 am

Ok i removed the wrong files (new format) from this post, i will try to convert this new to old format and convert it again for openmv camera.
Thanks,

Return to “Technical Discussion”

Who is online

Users browsing this forum: kidswong999 and 2 guests