<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gissel Claus</title>
    <description>The latest articles on DEV Community by Gissel Claus (@gissel_claus_f37fa582135d).</description>
    <link>https://dev.to/gissel_claus_f37fa582135d</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3395261%2F20e309f5-f827-4d2c-8e0f-c7c8d9283529.png</url>
      <title>DEV Community: Gissel Claus</title>
      <link>https://dev.to/gissel_claus_f37fa582135d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gissel_claus_f37fa582135d"/>
    <language>en</language>
    <item>
      <title>Creating a Facial Recognition Fence Opening System with Python</title>
      <dc:creator>Gissel Claus</dc:creator>
      <pubDate>Mon, 28 Jul 2025 20:43:56 +0000</pubDate>
      <link>https://dev.to/gissel_claus_f37fa582135d/creating-a-facial-recognition-fence-opening-system-with-python-5clm</link>
      <guid>https://dev.to/gissel_claus_f37fa582135d/creating-a-facial-recognition-fence-opening-system-with-python-5clm</guid>
      <description>&lt;p&gt;So, get this—I was juggling groceries, keys, my phone, and a coffee (because caffeine, duh), when I realized... wouldn’t it be amazing if my gate just &lt;em&gt;knew&lt;/em&gt; it was me and opened on its own?&lt;/p&gt;

&lt;p&gt;Like, &lt;em&gt;hi facial recognition, it’s me&lt;/em&gt;, open sesame.&lt;br&gt;&lt;br&gt;
Turns out—you can actually build that. And it’s not some Black Mirror sci-fi thing. Just a little Python, a dash of hardware, and a weekend of geeking out. Wanna know how? Let’s break it down.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why Bother?
&lt;/h2&gt;

&lt;p&gt;First off, if you’ve ever fumbled with keys in the rain or tried to buzz someone in while stuck on a Zoom call you already &lt;em&gt;get it&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Plus, if you’ve invested in those classy &lt;strong&gt;&lt;a href="https://chicagolandfencepros.com/iron-railings-chicago" rel="noopener noreferrer"&gt;Iron Railings in Chicago&lt;/a&gt;&lt;/strong&gt; that scream both style and security… well, wouldn’t it be cool to match that elegance with tech?&lt;/p&gt;

&lt;p&gt;I mean, don’t get me wrong—buttons and remotes are fine, but face ID is next level. It’s like your fence just &lt;em&gt;knows you&lt;/em&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Let’s Talk Basics—But Make It Casual
&lt;/h2&gt;

&lt;p&gt;Here’s a not-too-geeky breakdown of what you’ll need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Python + OpenCV&lt;/strong&gt;: This combo is your BFF for anything vision-related.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Raspberry Pi (or a laptop if you’re testing)&lt;/strong&gt;: Handles all the backend magic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Camera Module or Webcam&lt;/strong&gt;: Gotta see your face somehow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Servo Motor or Electronic Lock&lt;/strong&gt;: That’s what’ll trigger the gate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A fence worth opening&lt;/strong&gt;—preferably with sleek &lt;strong&gt;&lt;a href="https://chicagolandfencepros.com/iron-railings-chicago" rel="noopener noreferrer"&gt;Iron Railings Chicago IL&lt;/a&gt;&lt;/strong&gt; if you ask me 😉&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don’t need to be a coding wizard. I knew the bare minimum, and still pulled this off with a little trial and error (okay, maybe &lt;em&gt;a lot&lt;/em&gt; of trial and error).&lt;/p&gt;


&lt;h2&gt;
  
  
  How I Did It — No BS Walkthrough
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. &lt;strong&gt;Face Data Collection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I set up a simple Python script using OpenCV to collect images of my face. Just looked into the webcam, moved around a bit bam, dataset built.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;

&lt;span class="n"&gt;cam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;VideoCapture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;face_detector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CascadeClassifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;haarcascade_frontalface_default.xml&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;gray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cvtColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;COLOR_BGR2GRAY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;faces&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;face_detector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;detectMultiScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;faces&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;imwrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dataset/User.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This took me maybe 10 minutes. Not bad, right?&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Training the Recognizer&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Honestly, this step sounds scarier than it is. You just feed your model the images, and it learns what you look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;recognizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;face&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LBPHFaceRecognizer_create&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;recognizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, I skipped the boring parts. But if you've ever trained a puppy, it’s kinda the same vibe except less drool.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Real-Time Detection + Unlocking&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now the fun part: detecting your face and opening the gate.&lt;/p&gt;

&lt;p&gt;Once the camera recognizes you, it sends a signal to a GPIO pin (if you’re using a Pi). That pin then activates the servo motor to swing the gate open. It’s like magic. But real.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;confidence&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome back!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And yeah, I added a cooldown timer because I don’t want my dog triggering it every five seconds.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Even Go This Route?
&lt;/h2&gt;

&lt;p&gt;Besides bragging rights?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hands-Free Access&lt;/strong&gt;: Carry all the groceries. All of them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Super Customizable&lt;/strong&gt;: Want it to text you when someone unauthorized tries to get in? Easy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blends With Your Setup&lt;/strong&gt;: Especially if you’ve already got that premium &lt;strong&gt;&lt;a href="https://chicagolandfencepros.com/iron-railings-chicago" rel="noopener noreferrer"&gt;Chicago Iron Railings&lt;/a&gt;&lt;/strong&gt;, this makes it feel even more high-end.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Some Quick Tips (That I Wish I Knew)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Don’t forget lighting. Bad lighting = poor recognition.&lt;/li&gt;
&lt;li&gt;Train the system with different looks (glasses, no glasses, hat, etc.)&lt;/li&gt;
&lt;li&gt;Keep a manual override. Trust me you’ll thank me when it rains and your Pi glitches out.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real Talk: Is It Worth It?
&lt;/h2&gt;

&lt;p&gt;Short answer? Heck yeah. Long answer? If you're into tech, like solving problems, and you want your fence to feel like something out of a Bond movie this project is seriously fun.&lt;/p&gt;

&lt;p&gt;Also, it makes guests go: “Wait, your fence does &lt;em&gt;what&lt;/em&gt;?”&lt;/p&gt;

&lt;p&gt;So, yeah. Worth it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;If I can do this with a bit of code, some duct tape, and a YouTube tutorial or two you totally can too.&lt;/p&gt;

&lt;p&gt;Give it a shot this weekend. Worst case? You’ll learn something new. Best case? Your fence becomes your new favorite gadget.&lt;/p&gt;

&lt;p&gt;Let me know if you try it. I’d love to hear how it goes!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
