Back to blogging in 2020!

OpenCV is whack

After my last blog post questioning the behavior of a certain OpenCV method, a colleague pointed me at the source code for OpenCV and the method in question. Turns out, in addition to supposedly (but not reliably) finding a nice transformation between two matching pairs of points, it can also find a transformation between IMAGES by computing optical flow and finding features and doing RANSAC and A BILLION OTHER RIDICULOUS things. Things I don't want it to do!

Bad computer! BAD OpenCV!! I know exactly what math needs to be done, and I don't know if you noticed, but your documentation for that particular function strongly suggests it does some least squares optimization thing.

Objective: solve for the matrix that lets you transform original grumpy cat image to aligned grumpy cat image.
Now that's what I'm talkin' about! And I even got to put the eyebrow markers by her little cat eyebrows.

So, I finally rewrote the damn alignment code: https://gist.github.com/ktuite/7225703

The secret objective of this post is actually to profess my love for C/C++ libraries like GSL (the GNU Scientific Library). (I also like the Approximate Nearest Neighbor Library ANN.) It's kind of hard to learn, with matrix multiplies looking kinda like this: gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, m_gsl_dst, m_gsl_src, 0.0, A); but it's sooooo reliable! And fast! And educational! OpenCV constantly disappoints me, but these other libraries feel like wielding sharp swords forged by the elders.

I basically learned linear algebra from trying to decode and use that part of GSL. If you look at my alignment code, you'll see my (wo-)man-handling of matrices to get my answer.  I think there's another way to do it with a least-squares solver, but that's something I still need to look into/teach myself/get my hands dirty with.

Comments