Okay, so today I wanna talk about this Drake hat thing I messed around with. It was kinda cool, kinda janky, but hey, that’s how we learn, right?
First off, I saw this tutorial online – some dude rambling about using Python and some image processing libraries to make a “Drake hat” filter. Basically, you upload a picture, and it slaps a Drake-style OVO hat on your head. Seemed simple enough, so I figured, why not give it a shot?
I started by installing all the stuff the tutorial said I needed: OpenCV, dlib, all that jazz. Ran into a couple of snags with the dependencies, naturally. Spent a good hour just fixing those. You know how it goes – “DLL missing,” “module not found,” the usual suspects.
Next, I grabbed the Drake hat image from Google. Found a decent PNG with a transparent background. Then, I copy-pasted the code from the tutorial. I know, I know, bad practice, but I was just trying to get something working first.
Ran the code, and… nothing. Well, not nothing, but the hat was like, super tiny and stuck in the corner of the image. Clearly, something was off with the face detection or the hat placement.
Okay, so this is where the “fun” began. I started messing around with the dlib face detection stuff. Tweaked the scaling factors, the confidence thresholds, all that. It kinda worked, but the hat was still all wonky.
Then I realized the problem: the tutorial was using some outdated version of dlib, and the face landmarks were all messed up. I had to dig through the dlib documentation to figure out the new landmark indices. What a pain!
After a bunch of trial and error, I finally got the face detection working properly. The hat was actually on the head now! But it was still too small and rotated at a weird angle.

So, I started messing with the rotation and scaling of the hat. I used some basic trigonometry to calculate the angle between the eyes and then rotated the hat accordingly. That fixed the rotation issue. For the scaling, I just played around with the size until it looked somewhat proportional to the face.
Finally, I had something that looked… okay. It wasn’t perfect, but it was good enough for a laugh. I uploaded a picture of my dog and slapped the Drake hat on him. Looked hilarious!
The whole thing took me like, way longer than I expected. Probably spent a good five or six hours on it. But hey, I learned a bunch about image processing and face detection. Plus, I got a funny picture of my dog wearing a Drake hat. Worth it?
Anyway, that’s the story of my Drake hat adventure. It was a bit of a mess, but I had a good time messing around with it. Maybe I’ll try to make it into a proper web app someday. But for now, it’s just a fun little script that I can use to put hats on pictures of my pets.
Things I Learned:
- Don’t blindly copy-paste code. Understand what it’s doing.
- Dependencies are a pain.
- Face detection is harder than it looks.
- Drake hats make everything better.