Rolling Your Own Haarcascade

In my last blog I said that my cat ruined (did me in) my last haarcascade training session. The session was on the 25th stage of a 25 stage haartraining session. I restarted the session, and my cat left it alone this time. After all 25 stages were produced, the session ran for another 4 days; this was a long process. I replaced the haarcascade_smile.xml with my new smiles.xml file in the script I used for the blog, Sticking With Eyes And Mouths. I ran the script and it immediately abended with the error:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupport ed array type) in cvGetMat, file C:\builds\master_PackSlaveAddon-win64-vc12-stat ic\opencv\modules\core\src\array.cpp, line 2494 Traceback (most recent call last): File "video_streamer11.py", line 57, in eye_smile = smile_cascade.detectMultiScale(roi_eye, 1.01, 0); cv2.error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core \src\array.cpp:2494: error: (-206) Unrecognized or unsupported array type in fun ction cvGetMat

I immediately thought this error was caused by my low number of images used in producing smiles.xml ...but I thought the immediate workaround was to wrap the offending line of code in a try/except structure, and that I probably should have done that when I first wrote the script in the first place. That got rid of the problem (I also had to wrap the for loop that used eye_smile) with smiling eyes, but I also had to do the same for smiling mouth; I now had a running program. Unfortunately it didn't find any smiles at all.

Once again, I could've blamed my low number of positive images (700, versus the claimed 7000 images in haarcascade_smile.xml) on the lack of smile detections, but I thought I'd compare what I produced with haarcascade_smile.xml. smiles.xml was 2981 KBytes whereas haarcascade_smile.xml was just 191 KBytes. When I was researching how to create a haarcascade xml file, I read the more stages the merrier; i.e., the more (accurate) detections you'd get. Apparently I used too many stages in my haartraining session, and reduced it to 15. Instead of taking another two weeks to run, it only took a few hours. I then used my new xml file and I started getting smile hits. In fact, I got more smile hits then I did with haarcascade_smile.xml

Unfortunately, I didn't get an output file from running the scripts. At that point I remembered that I had to use an avi file to get an output file (it had been a while since I got to run my program). This time I got an output file, but no longer got all of the smile hits I had gotten before (using an mp4 file) on Lana Lang (Kristin Kreuk) or the lady in the yellow bikini (she's in the video). Hopefully I'll get all of those smiles back (and more) when I add more positive images to my next haartraining session. For anybody interested in Python coding, click on the link below for Streaming Video Script.

Notes from one day after uploading this blog (02/14/2017; just a coincidence that it was on Valentine's Day): First off, smiles.xml (actually, smiles15Stages.xml) doesn't really have 700 images; there are only 626 of the images being used by the xml file (that haarTraining.bat processed for smiles15Stages.xml). I tried using opencv_createsamples.exe and opencv_traincascade to create the xml file, but they wouldn't even accept 700 for the number of positive images (actually, it was opencv_traincascade that wouldn't accept 700 because opencv_createsamples only created 626 samples). I went back to using the executables I'd downloaded from https://www.cs.auckland.ac.nz/~m.rezaei/Tutorials/Creating_a_Cascade_of_Haar-Like_Classifiers_Step_by_Step.pdf because the defaults it used for some of the values (argument values) I wasn't supplying seemed more forgiving then the defaults used by the executables supplied in the opencv package; opencv_createsamples, and opencv_traincascade. Anyway, my point is, I'm going to replace the 74 images that didn't work out, before adding onto the 700 positive images I've already collected. I probably need to replace some more images then the ones that failed to process; e.g., I showed the images this morning to my wife, and she told me some of the images weren't actually smiles (she doesn't have my Alexithymia - I need to talk her into going through all of my images, and tell me which ones to replace with "real" smiles).

Return To My Blog Page       Streaming Video Script       Return To My Programming Page