Close

OpenCV Exploration: Speeding up the Detect

A project log for Autonomously Shoot My Roommate in the Face.

I want to build a quadcopter that when I push a button, the quadcopter finds and shoots my roommate in the face.

ben-hoffBen Hoff 04/17/2015 at 16:160 Comments

Hey I wanted to spend some time talking about what I did during this stream, but more importantly the logic of what I did. I think as we program some things become intuitive to us that aren't to the casual beginner, and since it's intuitive it's hard to explain using words.

I had a camera class. Towards the beginning of the stream, I mentioned that the camera class was too "smart". What I meant by that was it was responsible for too many things. My camera class at the beginning of this stream was responsible for not only handling the camera feed (whether it be from a webcam or a video file) but also for handling the face detection logic. For what I'm trying to do these are two large pieces of functionality that should not be in the same class. For a smaller project that is scoped narrowly, this would be fine. But because I plan to use this code base to explore the OpenCV libraray, I need all of my classes to be as extensible (which means able to be added to/built upon) as possible.

The problem with having too many large pieces of functionality in the same class is they become intertwined in weird ways that make a lot of sense at the time, but eventually become a chore to add on top of or to swap pieces out. So knowing that the haarcascade method for facial recognition is inherently slow and I'll want to look at different methods for doing the facial recognition, it becomes imperative to isolate the facial recognition logic in it's own class so that I don't have to untangle that logic out of a bloated camera class later down the road.

This doesn't make sense all the time. If you're writing a quick script, or a program that is going to do one thing and one thing only, you're better off not breaking up your program because it's only going to make the logic harder to follow. So keep that in mind!

Anywho... here's the first commit: https://github.com/benhoff/opencv/commit/086bf8c50d598db147dae5466c3484fc4586ba42

and the second: https://github.com/benhoff/opencv/commit/edbe725800ffc730f589562ebaec12bc215fb36a

and you can browse the files up to the end of this commit here: https://github.com/benhoff/opencv/tree/edbe725800ffc730f589562ebaec12bc215fb36a

https://www.youtube.com/watch?v=hj62oqVSQcQ

Discussions