<?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>Forem: Jacob Woods</title>
    <description>The latest articles on Forem by Jacob Woods (@jacobwoods45).</description>
    <link>https://forem.com/jacobwoods45</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%2F800893%2Fe6128dbb-e87e-4d7a-bc71-1284c2054465.jpeg</url>
      <title>Forem: Jacob Woods</title>
      <link>https://forem.com/jacobwoods45</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jacobwoods45"/>
    <language>en</language>
    <item>
      <title>Dorm Room Doorbell: Web Sockets &amp; Detection</title>
      <dc:creator>Jacob Woods</dc:creator>
      <pubDate>Tue, 25 Jan 2022 07:06:21 +0000</pubDate>
      <link>https://forem.com/jacobwoods45/dorm-room-doorbell-1b3i</link>
      <guid>https://forem.com/jacobwoods45/dorm-room-doorbell-1b3i</guid>
      <description>&lt;h2&gt;
  
  
  Detection Stabilization
&lt;/h2&gt;

&lt;p&gt;First things first, we needed to keep the face detector from doing some sort of action every time the loop runs. So to keep the detector from continuing to detect faces I used two tricks: 1.) Use an array to look at previous frames and see if it detected a face. If we see that the last 40 or so frames detected a face then we can determine that there is in fact a face there. The Cascade Classifier that comes with OpenCV can be a bit buggy and I didn't want a new event happening should the detection not detect a person in one frame. 2.) If we detected a face in the last pass of the frame loop then we don't want to do a new event because we know a face is already there. Super neat stuff!&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Socket Server
&lt;/h2&gt;

&lt;p&gt;I knew for this project I would need to pickup web sockets so I started up on that. I have never used web sockets so I used a Tech With Tim &lt;a href="https://www.youtube.com/watch?v=3QiPPX-KeSc"&gt;video&lt;/a&gt; Still learning and processing it!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def handle_cleint(conn, addr):
    print(f"[NEW CONNECTION] {addr} connected.") 
    connected = True
    while connected == True:
        message_length = conn.recv(HEADER).decode(FORMAT) # Receive message
        if message_length:
            message_length = int(message_length)
            msg = conn.recv(message_length).decode(FORMAT) # Receive message
         # Print message
            if msg == DISCONNECT_MESSAGE:
                connected = False
            print(f"[{addr}] {msg}")
            conn.send(f"Message received: | {msg} |".encode(FORMAT))
    print(f"[{addr}] ** Has left the chat.**")
    conn.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the handle client function in the server.py script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def start():
    server.listen() 
    print(f"SEVER IS LISTENING ON {SERVER}") # Listen for incoming connections
    while True:
        conn, addr = server.accept() # Accept connection

        thread = threading.Thread(target=handle_cleint, args=(conn, addr))
        print("[ACTIVE CONNECTIONS] ", threading.activeCount() - 1 ) # Show active connections
        thread.start()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the start function, also using threading (YAY!)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    if len(array_cache) &amp;gt;= 39:
        array_cache.pop(0)
        if face_detected == False:
            if check_array_cache_sum(array_cache) &amp;gt;= 38:
                print("Face Detected")
                face_detected = True
                web_hook.send("Face Detected")
                array_cache = []
        if check_array_cache_sum(array_cache) &amp;lt;= 38 and (len(array_cache) != 0):
            print("Face Not Detected")
            face_detected = False
            array_cache = []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is some of the code for smoothing out the detection.&lt;/p&gt;

</description>
      <category>python</category>
      <category>diy</category>
      <category>student</category>
    </item>
    <item>
      <title>Dorm Room Doorbell</title>
      <dc:creator>Jacob Woods</dc:creator>
      <pubDate>Sun, 23 Jan 2022 08:28:07 +0000</pubDate>
      <link>https://forem.com/jacobwoods45/dorm-room-doorbell-3a46</link>
      <guid>https://forem.com/jacobwoods45/dorm-room-doorbell-3a46</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Currently working on a camera for my dorm room that can detect if a person is at the door and alert me via an iOS app. The doorbell will run on an Raspberry Pi and the image detection will be done on OpenCV and the app will be built in Python. &lt;strong&gt;The goal of this project is to create something comparable to Amazon's Ring Device&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Current Progress
&lt;/h2&gt;

&lt;p&gt;Installed and implemented OpenCV, achieved facial recognition via CascadeClassifier within OpenCV, achieved facial recognition with bounding boxes.&lt;/p&gt;

&lt;p&gt;I was completely unaware that OpenCV comes out of the box with image classification tools, I was always under the assumption that additional libraries had to be installed. Hoping to get the recognition to be less touchy, perhaps slowing the frame rate of the video capture down so that events such as taking a picture or sending an alert via webhooks does not happen multiple times per instance that someone is at your door.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next:
&lt;/h2&gt;

&lt;p&gt;Get OpenCV to take an image and save it locally when it detects a person in the frame longer that a couple seconds. As well as have the computer chime when a picture is taken or something to alert someone at the door their picture has been taken.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ios</category>
      <category>sideprojects</category>
    </item>
  </channel>
</rss>
