Learning from Misses

A friend of mine and great radiologist, Dr. Jack McLarney says that the best cases are misses because you learn so much from them if you take the time to understand them.  This is a good example.  I’m presenting the images I got first, which is out of order.  The patient was scanned at midnight and then again at 6 AM.  I got the 6 AM case.

6 AM Scan


Earlier Midnight Scan

OpenCV Cat Face Detection

After trying the built in cat face detection HAAR cascade (you can get the vector xml from github), I decided to try to understand how to build my own cascade for each of my cats.  This is a general guide on the commands needed to go about it.  I’m running OpenCV on an i7 Ubuntu docker container so I do all of this remotely and then have the containerized version do the heavy lifting.

First, I started with my cat Thor because he has a high contrast face.  thor_train

And I used 10k negative samples from an online tut.

opencv_createsamples -img donutface.jpg -bg bg.txt -info info/info.lst -pngoutput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 10000


This generates a bunch of negative samples with thor superimposed on them that look like this.


The image is tiny but you can just see his face transformed and superimposed on the left of center.

opencv_createsamples -info info/info.lst -num 1950 -w 20 -h 20 -vec positives.vec


and finally:

opencv_traincascade -data data -vec positives.vec -bg bg.txt -numPos 1800 -numNeg 900 -numStages 10 -w 20 -h 20


Then I just whipped up a little boilerplate python to use OpenCV locally to find him. Doesn't find him here:

neg arnold

but does find him in some random pics of him with his face showing. Curiously, it didn't find him in an almost identical version of one of the picture.  I can loosen the rigidity of the match but then it finds multiple false positives.