trained haar classifier could not run properly

Hi, I’ve converted some cascade classifiers trained using opencv to the .cascade for openmv. When the .cascade is loaded with image.HaarCascade, there are some unaligned read but warnings. When I print the loaded classifier, it seems to have correct width, height, stages and feature numbers. However, when it runs to call img.find_feature, the video stops (the frame buffer is not updating) and the green led starts to flash after a short time. I try it on both openMV M4/M7 module with firmware version 2.4.1. In previous discussion, it looks other people also have some problems using hair classifier. I tried the “haardata2.cascade” in the previous post and it can run without the problem. I notice that you are updating the haar cascade classifier part recently to fix the unaligned read buf warnings. If the problem is related to it, could you provide me the schedule for the new firmware updating? Or is it possible to check the .xml and .cascade file for me? Thank you~~
haar_20170619_20x40_s14.zip (31.5 KB)

Ibrahim should be able to help you in this. Someone fixed our has Cascade importer script so you should be able to get this working now.

Hello,
pretty much same problem here, I’ve tried to load many different .cascade files which I downloaded as .xml files from the internet and converted with the python script linked on your website documentation on the matter(I downloaded the script today). Each time I can see the first frame acquired and then the camera freezes, the led starts blinking white and I’m not even able to disconnect the camera.
Seems to me that I’m doing something wrong in the conversion process. How can I fix it? Seems that this problem is common to many users.
Thank you very much

Hi,

The unaligned read issue was fixed in the dev firmware. It’s an issue related to FatFs internal buffers, that causes the SD card code to fall back to non-DMA mode when the read/write buffer is unaligned. So it’s just slower to read/write but it shouldn’t be the problem (you can avoid it for now by using the internal flash).

I downloaded the cascaded attached here and tested with the current dev fw and I saw the same issue, then I used the new converter script and the output was different from your binary cascade, not sure why.

Anyway, I’m attaching the dev fw image + binary cascade + Python converter script. Please test it and let me know if it works.

Note: The new firmware will be released soon, it’s taking longer because I need to finish up all the unit-tests before upgrading MP in v2.6.
haar.zip (1020 KB)

Hi,
First of all thank you for your swift answer, I updated the firmware and tested the new script:
-with the cascade file you generated the camera doesn’t crash and seems to work fine, I cannot be 100% sure that the algorithm works because i don’t know
what it is supposed to recognise
-unluckily I’m still experiencing issues with the cascade file I generate with the new script:
-if I store it in the sd memory same as before: it shows the first frame and then it all freezes, after a few seconds the led also starts blinking white
-if I store it in the internal memory it shows the first frame, then it all freezes and the led lights up in red, still
Seems to me that the problem is in the conversion process, but since yours works maybe I’m doing something wrong, may it be the os? I’ve tried on windows 7 and 10.
Also, could you try to convert the .xml file attached below?

Thanks again
haarcascade_fullbody3.xml (622 KB)

Hi again,
I finally found the problem, the converter doesn’t work on windows, I’ve tried with ubuntu with the same exact files and it works.
Thanks again

Thank you both for the effort. I did the conversion in windows. I will do that in ubuntu instead.

Hi,

That’s great! I’m not sure why the output is different on Windows, but the script will eventually be implemented in the IDE. Thanks for testing the camera and let me know if you find other issues.

Hello iabdalkader ,thank you for your kindly support! when I convert the xml file to cascade in ubuntu 16.04 ,the error information as follow:
python openmv-cascade.py cas2.xml
Converting new XML format…
Traceback (most recent call last):
File “openmv-cascade.py”, line 416, in
main()
File “openmv-cascade.py”, line 413, in main
cascade_binary_universal(args.file, args.stages, args.name)
File “openmv-cascade.py”, line 95, in cascade_binary_universal
cascade_binary(path, n_stages, name)
File “openmv-cascade.py”, line 177, in cascade_binary
rects = feature[idx].getElementsByTagName(‘_’)
IndexError: list index out of range
ubuntu@ip-172-31-16-214:~/xml-models/CAR-DETECTION$ python openmv-cascade.py cas3.xml
Converting new XML format…
Traceback (most recent call last):
File “openmv-cascade.py”, line 416, in
main()
File “openmv-cascade.py”, line 413, in main
cascade_binary_universal(args.file, args.stages, args.name)
File “openmv-cascade.py”, line 95, in cascade_binary_universal
cascade_binary(path, n_stages, name)
File “openmv-cascade.py”, line 164, in cascade_binary
fout.write(struct.pack(‘h’, int(float(t.childNodes[0].nodeValue.split()[3])*4096))) #int16_t
struct.error: short format requires SHRT_MIN <= number <= SHRT_MAX
ubuntu@ip-172-31-16-214:~/xml-models/CAR-DETECTION$ python openmv-cascade.py cas4.xml
Converting new XML format…
Traceback (most recent call last):
File “openmv-cascade.py”, line 416, in
main()
File “openmv-cascade.py”, line 413, in main
cascade_binary_universal(args.file, args.stages, args.name)
File “openmv-cascade.py”, line 95, in cascade_binary_universal
cascade_binary(path, n_stages, name)
File “openmv-cascade.py”, line 164, in cascade_binary
fout.write(struct.pack(‘h’, int(float(t.childNodes[0].nodeValue.split()[3])*4096))) #int16_t
struct.error: short format requires SHRT_MIN <= number <= SHRT_MAX

How to solve this issue?Thank you very much!
CAR-DETECTION-master.zip (34.8 KB)

Use Python2.7.

Yes,I used the python 2.7.6 (GCC 4.8.4)

When you use this:

python openmv-cascade.py cas3.xml

python could be a link to Python3 not 2.7.

So you should try:

python2.7 openmv-cascade.py cas3.xml

Thank you for your kindly support! I had check the version of python.Default is python 2.7.I also try follow command:python2.7 openmv-cascade.py cas1.xml ,the same error show,thank you!

Okay, I see the error now, see this answer:

iabdalkader ,Thank you for your kindley support! The issue can’t be solved from viewtopic.php?f=6&t=246&p=1969&hilit=short#p1969. I found the file is HOG or LBP format train by opencv,there can’t be convert to cascade file by openmv-cascade.py. How to used there in openmv3 .Thanks!

We only support OpenCV’s Haar cascades.

I read the discussion and wonder if the issue of converting under window is fixed? I need the solution
to get my cascade to test. Thanks.

Yes, the current haar Cascade converter script works now. Please see the GitHub. The script will be eventually integrated into OpenMV IDE.

I don’t think it works under Windows.

thanks for the support. if that is the case, would you please convert the xml and
test without freeze and return the cascade bin file to me.
The cascade was intended to detect a weld condition
under industial environment. openmv M7.
cas.zip (4.34 KB)