<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by namitha guruprasad on Medium]]></title>
        <description><![CDATA[Stories by namitha guruprasad on Medium]]></description>
        <link>https://medium.com/@namitha-guruprasad1410?source=rss-58096f3b19c8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Yb5eMIgf7eBCMjZz</url>
            <title>Stories by namitha guruprasad on Medium</title>
            <link>https://medium.com/@namitha-guruprasad1410?source=rss-58096f3b19c8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:14:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@namitha-guruprasad1410/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[MachNEase —Delaunay Triangulation and Voronoi Diagram using Facial Landmarks]]></title>
            <link>https://medium.com/analytics-vidhya/machnease-delaunay-triangulation-and-voronoi-diagram-using-facial-landmarks-2edbe2353ed5?source=rss-58096f3b19c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2edbe2353ed5</guid>
            <category><![CDATA[voronoi-diagrams]]></category>
            <category><![CDATA[delaunay-triangulation]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[facial-landmarks]]></category>
            <dc:creator><![CDATA[namitha guruprasad]]></dc:creator>
            <pubDate>Sat, 19 Dec 2020 14:27:09 GMT</pubDate>
            <atom:updated>2020-12-20T14:53:54.881Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>MachNEase by Nam — Machine Learning made Easy by Namitha Guruprasad</blockquote><p>Ever wondered how our facial morphology is similar irrespective of the genetics, geographical and environmental variations!? Nayyyyyyyy… We are too busy with the stuffs happening in our lives!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pKneJZwfi7hfNXiA" /><figcaption>Photo by <a href="https://unsplash.com/@thomascpark?utm_source=medium&amp;utm_medium=referral">Thomas Park</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my previous <a href="https://medium.com/analytics-vidhya/machnease-simple-yawn-detector-using-facial-landmarks-994e6804d2ba">post</a> (yeah, go ahead and click on the link), we had showered light on the usage of facial landmarks in a use case.</p><ul><li><strong>Human faces </strong>significantly communicate and express feelings effectively due to the constriction of various facial muscles.</li><li><strong>Craniofacial genetic research</strong> has enabled the analysis of 3 dimensional systems which have the ability to capture the facial details.</li><li><em>This post is the major stride for various applications like face swaps, morphs etc.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ByQ2tSrUMZehpMjwwPXSFg.png" /><figcaption><strong>Understanding Delaunay Triangulation and Voronoi Diagram using Facial Landmarks</strong></figcaption></figure><h3><strong>SQUIZ THE BASICS!!!!!!! (CATCH A GLIMPSE)</strong></h3><ul><li>Surface subdivisions is substantial for rendering of shapes of subject entities and for smooth comprehensibility of the dimensional characteristics of the entities.</li><li>Polygon hulls approximate the offset from the true surface planar representations.</li><li>Various points can have multiple triangulations. However, in <strong>Delaunay</strong> mechanism, no point is inside any triangle&#39;s circumcircle.</li><li>In short, they circumvent silver triangles ( lean and long triangles with extreme acute angles)</li><li>Linking the centers of those circumcircles (points that are non-collinear) will lead to <strong>Voronoi </strong>diagram. These circumcenters act as vertices and the edges together form the Voronoi tessellations.</li><li>Points in the planes (seeds) exhibit adhesive property resulting in local chunks called “cells” or “regions” (similar to nearest neighbour).</li><li>Hence, they exhibit a <strong>mathematical </strong><a href="https://en.wikipedia.org/wiki/Duality_(mathematics)"><strong>duality</strong></a><strong> property</strong>.</li></ul><p>Sounds interesting!? <strong>Auxiliary resources</strong> -&gt; <a href="https://en.wikipedia.org/wiki/Delaunay_triangulation"><strong>1</strong></a><strong>, </strong><a href="https://en.wikipedia.org/wiki/Voronoi_diagram"><strong>2</strong></a><strong> and </strong><a href="https://www.learnopencv.com/delaunay-triangulation-and-voronoi-diagram-using-opencv-c-python/"><strong>3</strong></a>(a shameless request for you to come back to this blog if you are in a deep survey of the fundamentals XDXD).</p><h3>STORE FACIAL LANDMARKS CO-ORDINATES IN A FILE:</h3><ul><li>Finds the landmarks co-ordinates on the faces — a shape estimator is used that is implemented in the <strong><em>dlib</em> </strong>library</li></ul><pre>#obtain the image feed<br>#path of the file - if stored in the same directory. Else, give the relative path<br><strong>frame = cv2.imread([filename])<br></strong>#[filename] - ex : &quot;image.jpg&quot; (path of the image)<br>#for detecting faces<br><strong>detector = dlib.get_frontal_face_detector()<br></strong>#facial landmarks - identifier<br><strong>predictor = dlib.shape_predictor(&quot;shape_predictor_68_face_landmarks.dat&quot;)</strong></pre><pre><strong>gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)</strong><br>#clahe - Contrast Limited Adaptive Histogram Equalization - to avoid over - brightness, contrast limitation and amplification of noise<br>#image is divided into small blocks called &quot;tiles&quot; (tileSize is 8x8 by default in OpenCV)<br>#if histogram bin is above the specified contrast limit - pixels are clipped and distributed uniformly<br>#here bi-polar interpolation is implemented<br><strong>clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))</strong> #optional arguments<br><strong>clahe_image = clahe.apply(gray)</strong></pre><ul><li>I have chosen <a href="https://suits.fandom.com/wiki/Harvey_Specter"><strong>Harvey Specter</strong></a> and <a href="https://en.wikipedia.org/wiki/Homer_Simpson"><strong>Homer Simpson</strong></a> as my models.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*GEspaEhWjG_kmmmi731ovw.jpeg" /><figcaption><strong>“I don’t have dreams, I have goals”</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*SPtNb9GyUkW9OaitZZu2nA.png" /><figcaption><strong>“Ummm… Donuts”</strong></figcaption></figure><ul><li>The estimator gives <strong>68 landmark points </strong>including the corner of the eyes, the tip of the nose, lips etc</li><li>The landmark coordinates on the detected face are now stacked up in a text file</li></ul><pre>#detect the faces in the image<br><strong>detections = detector(clahe_image, 1) <br>for k,d in enumerate(detections):</strong><br>    #for every detected face<br>    #create a text file to save the landmark coordinates<br>    <strong>coordinates_txt = open([filename] + &quot;.txt&quot;,&quot;w&quot;)<br>    </strong>#[filename] - ex : &quot;abc&quot; <strong><br>    shape = predictor(clahe_image, d) <br>    for i in range(1,68):</strong><br>        #68 landmark points on each face<br>        <strong>cv2.circle(frame, (shape.part(i).x, shape.part(i).y), 1, (0,0,255), thickness=2)</strong> #For each point, draw a red circle with thickness2 on the frame<br>        <strong>coordinates_txt.write(str(shape.part(i).x) + &quot; &quot; + str(shape.part(i).y) + &quot;\n&quot;)</strong><br>        #drawing the landmarks with thickness 3 - yellow in color</pre><pre>#display the imageframe<br><strong>cv2.imshow(&quot;image&quot;, frame)</strong></pre><h3>UNDERSTANDING DELAUNAY TRIANGULATION AND VORONOI DIAGRAM:</h3><ul><li><strong>Checks </strong>if the point is inside the plane / region defined</li></ul><pre><strong>def region(plane, point):</strong> # to check if the point is inside the plane / region defined<br>    <strong>if point[0] &lt; plane[0]:<br>        return False<br>    elif point[1] &lt; plane[1]:<br>        return False<br>    elif point[0] &gt; plane[2]:<br>        return False<br>    elif point[1] &gt; plane[3]:<br>        return False<br>    return True</strong></pre><ul><li>Performs the subdivisions of regions and generate triangles based on <strong>Delaunay conditions</strong> (check the basics section)</li></ul><pre><strong>def delaunay_triangulation(image, subdiv, color):</strong><br>    #subdivision surface evaluation for the image (shape, surface etc)<br>    #color for drawing of lines for the traingulation in the region<br>   <strong> triangles = subdiv.getTriangleList();</strong><br>    #triangle list is generated for the subdivisioned area<br><strong>    size = image.shape<br></strong>    #image size is calculated<br><strong>    p = (0, 0, size[1], size[0])<br></strong>    #plane demarkation to check if the points lie in the region<br>   <strong> for tr in triangles:<br>        p1 = (tr[0], tr[1])<br>        p2 = (tr[2], tr[3])<br>        p3 = (tr[4], tr[5])<br>        if region(p, p1) and region(p, p2) and region(p, p3):</strong><br>            #if the points lie in the plane, then connect the dots<br>            <strong>cv2.line(image, p1, p2, color, 1, cv2.LINE_AA, 0)<br>            cv2.line(image, p2, p3, color, 1, cv2.LINE_AA, 0)<br>            cv2.line(image, p3, p1, color, 1, cv2.LINE_AA, 0)</strong></pre><ul><li><strong>Tessellate </strong>the surface of the image with polygons for better subdivisions of the planes and <strong>generate </strong>“seeds” for constructing <strong>Voronoi </strong>diagram</li></ul><pre><strong>def draw_voronoi(image, subdiv):</strong><br>    <strong>(facets, centers) = subdiv.getVoronoiFacetList([])</strong><br>    #points in the plane - set of seeds<br>    #each seed - consists of region with all points closer to the seed than any other<br>    #similar to nearest neighbour algorithm<br>    <strong>array_colors = [[255,0,255],[255,248,220],[188,143,143],[0,255,255],[240,230,140]]</strong><br>    #colors for the set of planes <br>    <strong>for i in range(0,len(facets)) :<br>        ifacet_arr = []<br>        for f in facets[i] :<br>            ifacet_arr.append(f)<br>        ifacet = np.array(ifacet_arr, np.int)<br>        color = array_colors[random.randint(0,4)]</strong><br>        #random colors for different polygons <br>        <strong>cv2.fillConvexPoly(image, ifacet, color, cv2.LINE_AA, 0);<br>        ifacets = np.array([ifacet])<br>        cv2.polylines(image, ifacets, True, (0, 0, 0), 1, cv2.LINE_AA, 0)<br>        cv2.circle(image, (centers[i][0], centers[i][1]), 3, (0, 0, 0), cv2.FILLED, cv2.LINE_AA, 0)</strong></pre><h3>VISUALIZATION: (Now, this is fun!!!!)</h3><ul><li>Obtain <strong>image feed</strong></li></ul><pre><strong>img = cv2.imread([filename]);<br></strong>#[filename] - ex : &quot;image.jpg&quot; (path of the image)<br>#create a copy / duplicate of the image <br><strong>dup = img.copy();<br></strong>#obtain image size<br><strong>size = img.shape</strong></pre><ul><li>Create a <strong>plane </strong>and its <strong>subdivisions</strong></li></ul><pre><strong>plane = (0, 0, size[1], size[0])<br>subdiv = cv2.Subdiv2D(plane);</strong></pre><ul><li>Extract <strong>array of points</strong> to check for its validity in the region / plan</li></ul><pre><strong>points = []<br></strong>#read the landmark coordinates from the &quot;txt&quot; file for validation<br><strong>with open([filename]) as file : <br>    </strong>#[filename] - ex : &quot;abc.txt&quot; (path of the file)<strong><br>    for line in file :<br>        x, y = line.split()<br>        points.append((int(x), int(y)))</strong></pre><ul><li><strong>Triangulation </strong>mechanism with some embellishments</li></ul><pre><strong>for p in points :<br>    subdiv.insert(p)</strong><br>    #animate the triangulation<br>    <strong>if True :</strong><br>        <strong>copy = dup.copy()<br></strong>        #construct delaunay triangles <br>        <strong>delaunay_triangulation(copy, subdiv, (0, 255, 255));<br>        cv2.imshow(&#39;Delaunay Triangulation&#39;, copy)<br>        cv2.waitKey(100)</strong></pre><pre><strong>delaunay_triangulation( img, subdiv, (0, 255, 255) );</strong></pre><pre>#marks the points on the image<br><strong>for p in points:<br>    cv2.circle(img, p, 2, (255,0,0), cv2.FILLED, cv2.LINE_AA, 0)</strong></pre><ul><li>Construct <strong>Voronoi </strong>diagram</li></ul><pre><strong>img_voronoi = np.zeros(img.shape, dtype = img.dtype)<br>draw_voronoi(img_voronoi,subdiv)</strong></pre><ul><li>Create 2 separate <strong>windows </strong>:</li></ul><ol><li><strong>Delaunay Triangulation</strong></li><li><strong>Voronoi Diagram</strong></li></ol><pre>cv2.imshow(&#39;Delaunay Triangulation&#39;,img)<br>cv2.imshow(&#39;Voronoi Diagram&#39;,img_voronoi)<br>cv2.waitKey(0)</pre><h3>EXECUTION:</h3><p>Go to your terminal and paste the following commands: (if you’ve stored the above in a python file. Jupyter notebook?? Never-mind, you’re dedicated!!)</p><pre><strong>python filename.py </strong></pre><h3>YIPPPEEEE!!! YOU SAW HOW COOL THIS WAS !!! OF COURSE, THERE’S HARVEY SPECTER! ;)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*tIAA7nEc3RTITXV40QtV0w.png" /><figcaption><strong>“When you are backed against the wall, break the goddamn thing down”</strong></figcaption></figure><p>Well, Homer got nothing!!! (He was drowned in Donuts!!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*ay52KuKu-6LQG5QVXe4-sQ.png" /><figcaption><strong>“D’oh!!”</strong></figcaption></figure><h4>WAIT !! Did you just copy paste all the freaking code blocks????? Well, that was laborious. Never-mind, you learnt something new and exciting…</h4><blockquote>You can find the ENTIRE CODE STUFF here : <a href="https://github.com/nam1410/MachNEase--Delaunay-Triangulation-and-Voronoi-Diagram-using-Facial-Landmarks">https://github.com/nam1410/MachNEase--Delaunay-Triangulation-and-Voronoi-Diagram-using-Facial-Landmarks</a></blockquote><h4>Interested in Machine Learning, Data science, etc..?? :</h4><p>Dive into this ocean with the help of</p><blockquote><a href="https://github.com/nam1410">MachNEase with Nam</a></blockquote><p>I shall be uploading easy / implementable projects in my profile Follow the account for amazing, tailored feed.</p><p><strong><em>Reach me out at :</em></strong></p><blockquote>LinkedIn : <a href="https://www.linkedin.com/in/namitha-guruprasad-216362155/">https://www.linkedin.com/in/namitha-guruprasad-216362155/</a></blockquote><blockquote>Namitha Guruprasad, Student, Bengaluru, India</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2edbe2353ed5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/machnease-delaunay-triangulation-and-voronoi-diagram-using-facial-landmarks-2edbe2353ed5">MachNEase —Delaunay Triangulation and Voronoi Diagram using Facial Landmarks</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MachNEase — Simple Yawn Detector using Facial Landmarks]]></title>
            <link>https://medium.com/analytics-vidhya/machnease-simple-yawn-detector-using-facial-landmarks-994e6804d2ba?source=rss-58096f3b19c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/994e6804d2ba</guid>
            <category><![CDATA[easy]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[opencv]]></category>
            <dc:creator><![CDATA[namitha guruprasad]]></dc:creator>
            <pubDate>Wed, 27 May 2020 15:41:12 GMT</pubDate>
            <atom:updated>2020-12-19T14:06:48.224Z</atom:updated>
            <content:encoded><![CDATA[<h3>MachNEase — Simple Yawn Activity Detection using Facial Landmarks</h3><blockquote><strong>MachNEase by Nam — Machine Learning made Easy by Namitha Guruprasad</strong></blockquote><p>Ever wondered how many times you yawn everyday?! Naaayyy…. We have better things to do!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3HgYvUkpNzy-jlmt" /><figcaption>Photo by <a href="https://unsplash.com/@thirdworldhippy?utm_source=medium&amp;utm_medium=referral">mwangi gatheca</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Curious to know about your yawn count? Well, you’re just one step away!!</p><ul><li><strong>Human faces </strong>significantly communicate and express feelings effectively due to the constriction of various facial muscles.</li><li><em>Extreme fatigue, boredom and lack of interest are the primordial reasons to sleepiness and eventual yawning</em>.</li><li><strong>Determining Facial Landmarks</strong> is a radical approach to detect the yawning activity.</li><li>Hence, it is logical to expect that an effective facial image processing system can be designed using <strong>computer vision.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*XkMUzROw9ORJC0YOGQP4cw.png" /><figcaption><strong>Workflow of Yawn Detection using Facial Landmarks</strong></figcaption></figure><h3>INSTALL AND IMPORT ESSENTIAL LIBRARIES:</h3><ul><li><strong>OpenCV — </strong>A library of programming functions mainly aimed at real-time computer vision (<a href="https://opencv.org/">Documentation</a>)</li></ul><pre><strong>pip install opencv-python</strong></pre><ul><li><strong>DLib — </strong>A general purpose cross-platform software library written in C++(<a href="http://dlib.net/">Documentation</a>)</li></ul><pre><strong>pip install dlib</strong></pre><ul><li><strong>NumPy —</strong> A library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays (<a href="https://numpy.org/">Documentation</a>)</li></ul><pre><strong>pip install numpy</strong></pre><p>Now, import all these libraries:</p><pre><strong>import cv2<br>import dlib<br>import numpy as np</strong></pre><h3>OBTAIN FACIAL LANDMARKS CO-ORDINATES:</h3><ul><li>To find the landmarks co-ordinates on the faces, a shape estimator is used that is implemented in the <strong><em>dlib</em> </strong>library.</li></ul><pre><strong>detector = dlib.get_frontal_face_detector()</strong> #For detecting faces<br><strong>landmark_path=&quot;shape_predictor_68_face_landmarks.dat&quot; </strong><br>#Path of the file - if stored in the same directory. Else, give the relative path<br><strong>predictor = dlib.shape_predictor(landmark_path) </strong>#For identifying landmarks</pre><ul><li>The estimator gives <strong>68 landmark points </strong>including the corner of the eyes, the tip of the nose, lips etc.</li><li><strong>Identify the number of faces</strong> detected in the webcam. <em>Make sure there’s only one subject for the activity detection.</em></li></ul><pre>#Obtaining Facial Landmark coordinates<br><strong>def get_facial_landmarks(image):<br>    face = detector(image, 1)</strong><br>    #Detecting faces in image<br><strong>    if len(face) &gt; 1:<br></strong>   <strong>     return &quot;Multiple faces detected in the frame!!&quot;<br>    if len(face) == 0:<br>        return &quot;No face detected in the frame!!&quot;</strong><br>    #Return the coordinates<br>    #Predictor identifies all the 68 landmarks for the detected face<br>    <strong>return np.matrix([[pred.x, pred.y] for pred in predictor(image, face[0]).parts()])</strong></pre><ul><li><strong>Annotate the 68 facial landmark coordinates</strong> on the detected face</li></ul><pre>#Drawing the landmarks : yellow in color <br><strong>def landmarks_annotation(image, facial_landmarks):</strong><br>    #Different image window for facial landmarks<br>   <strong> image = image.copy()</strong><br>    <strong>for coord, p in enumerate(facial_landmarks):</strong><br>        #Extracting coordinate values and the location / matrix of the coordinates<br>       <strong> position = (p[0, 0], p[0, 1])</strong><br>        #Identify and draw the facial landmarks<br>       <strong> cv2.putText(image, str(coord), position, cv2.FONT_HERSHEY_COMPLEX, 0.3, (0, 255, 255))<br>    return image</strong></pre><h3>COMPUTE LIPS DISTANCE:</h3><ul><li>Calculate the centroid value of the <strong>upper lip </strong>using the landmarks</li></ul><pre>#Landmark coordinates for upper lip identified in the face <br><strong>def upperlip(facial_landmarks):<br>    ulip = []</strong><br>    #create an array to store the landmark coordinates of the upper lip<br>    <strong>for i in range(50,53):</strong><br>        #The range is predefined in &quot;shape_predictor_68_face_landmarks.dat&quot;<br>       <strong> ulip.append(facial_landmarks[i])</strong><br>   <strong> for i in range(61,64):</strong><br>        #The range is predefined in &quot;shape_predictor_68_face_landmarks.dat&quot;<br>        <strong>ulip.append(facial_landmarks[i])</strong><br>    #Locate the mean value of the upper lip coordinates<br>   <strong> ulip_mean = np.mean(ulip, axis=0)<br>    return int(ulip_mean[:,1])</strong>#centroid value</pre><ul><li>Calculate the centroid value of the <strong>lower lip </strong>using the landmarks</li></ul><pre>#Landmark coordinates for lower lip identified in the face <br><strong>def lowerlip(facial_landmarks):<br>    llip = []</strong><br>    #create an array to store the landmark coordinates of the lower lip<br>   <strong> for i in range(65,68):</strong><br>        #The range is predefined in &quot;shape_predictor_68_face_landmarks.dat&quot;<br>       <strong> llip.append(facial_landmarks[i])<br>    for i in range(56,59):</strong><br>        #The range is predefined in &quot;shape_predictor_68_face_landmarks.dat&quot;<br>       <strong> llip.append(facial_landmarks[i])</strong><br>    #Locate the mean value of the lower lip coordinates<br>   <strong> llip_mean = np.mean(llip, axis=0)<br>    return int(llip_mean[:,1])</strong>#centroid value</pre><ul><li>Detect the yawning activity by <strong>computing the distance</strong> between the upper and the lower lips using their respective centroids</li></ul><pre>#Detect the yawning activity<br><strong>def yawning(image):</strong><br>    #Obtain the facial Landmark coordinates<br>    <strong>facial_landmarks = get_facial_landmarks(image)<br>    if type(facial_landmarks) == str:<br>        return image, 0</strong><br>    #Obtain the frame / image with annotated facial landmarks<br><strong>    landmarks_image = landmarks_annotation(image, facial_landmarks)<br></strong>    #Obtain Lip centroids<br>   <strong> upperlip_centroid = upperlip(facial_landmarks)<br>    lower_lip_centroid = lowerlip(facial_landmarks)<br></strong>    #Calculate the distance between the centroids<br>   <strong> lips_dist = abs(upperlip_centroid - lower_lip_centroid)<br>    return landmarks_image, lips_dist</strong></pre><h3>DISPLAY THE YAWN STATUS AND COUNT: (The game begins now !!!!)</h3><ul><li><strong>Initialize the yawn status and count</strong></li></ul><pre><strong>yawn_status = False <br>yawn_count = 0</strong></pre><ul><li><strong>Create</strong> the live streaming <strong>object</strong></li></ul><pre><strong>video_capture = cv2.VideoCapture(0)</strong></pre><ul><li><strong>Detect the yawning activity</strong> by calling its function</li></ul><pre><strong>while True:<br>    _, image_frame = video_capture.read()</strong><br>    #Identify the yawning activity<br><strong>    landmarks_image, lips_dist = yawning(image_frame)<br></strong>    #Update the yawn status<br><strong>    previous_status = yawn_status</strong></pre><ul><li>Check whether the <strong>distance between the lips is eccentric</strong></li></ul><p><em>(threshold : subjective) </em><strong><em>[This is where your yawn is detected and counted :D]</em></strong></p><ul><li>If yes, then <strong>display </strong>the status and your yawn count</li></ul><pre>#comes under while loop<br>#lips distance is subjective and changes from subject to subject based on their facial structures<br>   <strong> if lips_dist &gt; 40:<br>        yawn_status = True<br>        output_text = &quot; Number of Yawns: &quot; + str(yawn_count + 1)<br>        cv2.putText(image_frame, &quot;You are yawning&quot;, (50,450), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,0))<br>        cv2.putText(image_frame, output_text, (50,50), cv2.FONT_HERSHEY_COMPLEX, 1,(0,0,255))<br>        <br>    else:<br>        yawn_status = False <br>         <br>    if previous_status == True and yawn_status == False:<br>        yawn_count += 1</strong></pre><ul><li>Create 2 separate <strong>windows </strong>:</li></ul><ol><li><strong>Facial Landmarks</strong></li><li><strong>Yawn Activity</strong></li></ol><pre><strong>cv2.imshow(&#39;Facial Landmarks&#39;, landmarks_image )<br>cv2.imshow(&#39;Yawning Activity Detection&#39;, image_frame )</strong></pre><ul><li><strong>Press Q </strong>to stop this detection activity</li></ul><pre><strong>if cv2.waitKey(1)  &amp; 0xFF == ord(&#39;q&#39;):<br>        break</strong></pre><ul><li>It’s a good habit to <strong>clean up the mess</strong> you’ve done. Hence, terminate the webcam object and dump all the windows that were opened.</li></ul><pre><strong>video_capture.release()<br>cv2.destroyAllWindows()</strong></pre><h3>EXECUTION:</h3><p>Go to your terminal and paste the following command:</p><p>Here, Filename : “yawn_detector.py”</p><pre><strong>python yawn_detector.py</strong></pre><h3><strong>YIPPPEEEE!!! YOU JUST FINISHED YAWNING AND SAW YOUR MOUTH WIDE OPEN !!!!!!</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThYfpv0tOOZE6s1Ifa_siA.png" /><figcaption><strong>Yeah, I know, My face is disgusting :P</strong></figcaption></figure><h4>WAIT !! Did you just copy paste all the freaking code blocks????? Well, that was laborious. Never-mind, you learnt something new and exciting…</h4><blockquote>You can find the <strong>ENTIRE CODE STUFF</strong> here : <a href="https://github.com/nam1410/MachNEase--Simple-Yawn-Detector-using-Facial-Landmarks">https://github.com/nam1410/MachNEase--Simple-Yawn-Detector-using-Facial-Landmarks</a></blockquote><h4>Interested in Machine Learning, Data science, etc..?? :</h4><p>Dive into this ocean with the help of</p><blockquote><a href="https://github.com/nam1410"><strong>MachNEase with Nam</strong></a></blockquote><p>I shall be uploading easy / implementable projects in my profile. Follow the account for amazing, tailored feed.</p><p><strong><em>Reach me out at :</em></strong></p><blockquote><strong>LinkedIn</strong> : <a href="https://www.linkedin.com/in/namitha-guruprasad-216362155/">https://www.linkedin.com/in/namitha-guruprasad-216362155/</a></blockquote><blockquote><strong>Namitha Guruprasad, Student, Bengaluru, India</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=994e6804d2ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/machnease-simple-yawn-detector-using-facial-landmarks-994e6804d2ba">MachNEase — Simple Yawn Detector using Facial Landmarks</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>