<?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 Shawn Tng on Medium]]></title>
        <description><![CDATA[Stories by Shawn Tng on Medium]]></description>
        <link>https://medium.com/@shawntng?source=rss-ebcda6d00656------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*E8_RTkdfd8Uz7l6S</url>
            <title>Stories by Shawn Tng on Medium</title>
            <link>https://medium.com/@shawntng?source=rss-ebcda6d00656------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:44:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shawntng/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[Gesture Detection Using Intel RealSense Camera]]></title>
            <link>https://shawntng.medium.com/gesture-detection-using-intel-realsense-camera-c103f0a7de29?source=rss-ebcda6d00656------2</link>
            <guid isPermaLink="false">https://medium.com/p/c103f0a7de29</guid>
            <category><![CDATA[roses]]></category>
            <category><![CDATA[gesture-control]]></category>
            <dc:creator><![CDATA[Shawn Tng]]></dc:creator>
            <pubDate>Tue, 16 Nov 2021 04:43:21 GMT</pubDate>
            <atom:updated>2021-11-16T04:43:21.173Z</atom:updated>
            <content:encoded><![CDATA[<p>I was recently working on a robotics project that requires the use of human gestures to navigate a robot remotely. Gesture recognition is one of the ways to help computers understand human body language, thus building a richer bridge between machines and humans than primitive text user interfaces or even GUIs (graphical user interfaces), which still limit the majority of input to keyboard and mouse and interact naturally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AY6nRQCMrNL5RGUZDqkqew.png" /><figcaption>Experiment Setup</figcaption></figure><h3>Dataset</h3><p>Most of the gesture detections studied done are using static image classification. I had wanted to be able to recognize more complex gestures with a series of motions, such as clockwise or anti-clockwise motion. For complex gestures that take up about 80 frames to execute, I could not find any available public data. Moreover, my intent was to use a depth camera, there are no available dataset based on Intel Realsense camera.</p><p>Considering the amount of model training time required, it is impractical to use all the 80 frames. We all know not every consecutive frames are required to represent the gesture and some frames could be discarded, especially if there are no significant variation between 2 consecutive frames. By trial and error, different combination of number of dropped frames and total number of frames to represent the gesture was examined by trial and error. 5 classes with 1000 set of 20 images each were generated using the Intel Realsense Depth camera to form the dataset. To ensure diversity in the dataset and prevent overfitting, the distance from the camera was randomly varied during recording. The dataset was separated in the ratio of 7:3 into the training set and independent test set.</p><h3>Model</h3><p>I have adopted a CNN-RNN-based network to train the data. Basically the input of 20 images will be processed by shared CNN model to extract respective features maps. Each of this feature map is fed into RNN-based network as a single time step. The input shape is (20, 128, 128, 3), batch size is 32, and number of epoch is 30. The Adam optimizer was used for optimization along with categorical cross-entropy as the loss function. Softmax is used for the last layer’s activation.</p><h3>Ta da!</h3><p>Here’s the outcome</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fx9aHaZ1V_xI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dx9aHaZ1V_xI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fx9aHaZ1V_xI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6416222daffd3a7a02d98465acc73d5a/href">https://medium.com/media/6416222daffd3a7a02d98465acc73d5a/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c103f0a7de29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Scoring For Tiktok Dance Challenge]]></title>
            <link>https://shawntng.medium.com/automated-scoring-for-tiktok-dance-challenge-2ba43532ae65?source=rss-ebcda6d00656------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ba43532ae65</guid>
            <category><![CDATA[tik-tok]]></category>
            <category><![CDATA[mediapipe]]></category>
            <category><![CDATA[dynamic-time-warping]]></category>
            <category><![CDATA[pose-estimation]]></category>
            <category><![CDATA[dtw]]></category>
            <dc:creator><![CDATA[Shawn Tng]]></dc:creator>
            <pubDate>Thu, 20 May 2021 13:48:38 GMT</pubDate>
            <atom:updated>2021-05-25T09:30:30.419Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a continuation of my previous <a href="https://shawntng.medium.com/multi-person-pose-estimation-with-mediapipe-52e6a60839dd">post</a>, where Google’s Mediapipe was used for multi-person pose estimation. From each video frame, we are able to extract body landmarks or keypoints from the image captured. These are useful features that represent the body posture of the dancer at each recorded frame. When we collect these information for the entire video of dance sequence, we are able to obtain some form of time series data. The idea here is to explore a method to evaluate the posture of the dancer against his coach.</p><p>The motivation here is to explore automated scoring for Tiktok Dance Challenges. <a href="https://www.tiktok.com/">Tiktok </a>is a 60-second short video app is filled with memes, comedy, dancing, and talents. In a <a href="https://www.tiktok.com/en">TikTok </a>dance challenge, the originator will perform a dance based on a certain audio track and TikTok users will imitate the moves with their own video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQ-oIArp9nhc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQ-oIArp9nhc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQ-oIArp9nhc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8c793e8cba4e23d063f1f77ad7d6093/href">https://medium.com/media/b8c793e8cba4e23d063f1f77ad7d6093/href</a></iframe><p>In the video example, we have popular Taiwanese singer Jolin Tsai (right) doing a dance for her new song release <a href="https://www.youtube.com/watch?v=--giQqhWGdQ">Stars Align</a>. The guy in yellow is trying to copy her dance moves in his own video.</p><p>In this post, I shall explore the idea of using dynamic time warping as a score component for dance evaluation. The caveat here is to assume we have almost a full view of a person, and known challenges from occlusion or camera motions will not be discussed here.</p><h3>Dynamic Time Warping</h3><p>In time series analysis, dynamic time warping (DTW) is one of the algorithms for measuring similarity between two temporal sequences that are usually not synchronized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*NTQnGQGAFP56hJsT2NK9Zg.jpeg" /><figcaption>Source: <a href="https://commons.wikimedia.org/wiki/File:Euclidean_vs_DTW.jpg">Wiki Commons</a></figcaption></figure><p>With DTW, elastic alignment between points of two signals produces a better, more intuitive similarity measure. DTW calculates an optimal match between two given sequences and warps the sequences along time dimension to determine similarity independent of variations in time. DTW produces warping path, which enables alignment between two signals as seen above. See <a href="https://databricks.com/blog/2019/04/30/understanding-dynamic-time-warping.html">here</a> for more information about DTW. In this post, we are using DTW to discover pairs of matching frames so that the posture coordinates from each frame of</p><h3>Dataset</h3><p>For illustration, I will be using 2 videos below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FOPt4KRq19bI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DOPt4KRq19bI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FOPt4KRq19bI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3eb3a3a55ba8b77bdc776e945c378b24/href">https://medium.com/media/3eb3a3a55ba8b77bdc776e945c378b24/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_CP8pzwOzrg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_CP8pzwOzrg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_CP8pzwOzrg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccdeb02a850eb1ecc81b61739a20dcaa/href">https://medium.com/media/ccdeb02a850eb1ecc81b61739a20dcaa/href</a></iframe><p>Both videos have their respective video lengths cropped such that the starting dance move and the last dance move in both videos are matched. This is an important criteria for the DTW to work well.</p><p>For the ground truth, the learner in Video 2 is better dancer. For the curious folks, he is <a href="https://www.instagram.com/weijin_huang">Wayne Huang</a>, a Taiwanese actor, singer, dancer and host.</p><h3>Multi-Person Pose Estimation</h3><p>Both videos are processed with 2D pose estimation (See my <a href="https://shawntng.medium.com/multi-person-pose-estimation-with-mediapipe-52e6a60839dd">previous post</a>) to extract normalized pose landmarks for each pair of persons.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FOV-PxbDoeuI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DOV-PxbDoeuI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FOV-PxbDoeuI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d21f250c8b0112751f30b585f0ced51a/href">https://medium.com/media/d21f250c8b0112751f30b585f0ced51a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FC37D9m95czU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DC37D9m95czU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FC37D9m95czU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/490de7777e649fa14d7f1a31dff44f22/href">https://medium.com/media/490de7777e649fa14d7f1a31dff44f22/href</a></iframe><p>Here, we are using the full-body landmark model in Google’s MediaPipe Pose. It is able to predicts the location of 33 pose landmarks. You may also consider the upper-body version for scenarios where the lower-body parts are mostly out of view. The upper-body version predicts only the first 25 pose landmarks.</p><h4>Pose Landmark Model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*RPOoP1j-66ZoUBwQ.png" /><figcaption>Source: <a href="https://google.github.io/mediapipe/solutions/pose.html">https://google.github.io/mediapipe/solutions/pose.html</a></figcaption></figure><p>Each landmark consists of the following (Source: <a href="https://google.github.io/mediapipe/solutions/pose.html">here</a>):</p><ul><li>x and y: Landmark coordinates normalized to [0.0, 1.0] by the image width and height respectively.</li><li>z: Represents the landmark depth with the depth at the midpoint of hips being the origin, and the smaller the value the closer the landmark is to the camera. The magnitude of z uses roughly the same scale as x. <strong>[This is not used here as we do not have depth information]</strong></li><li>visibility: A value in [0.0, 1.0] indicating the likelihood of the landmark being visible (present and not occluded) in the image. <strong>[To simply my explanation, we will ignore this attribute]</strong></li></ul><h3>Feature Representation</h3><p>Now before I go further to talk about how the keypoints will be used, let’s take a look at the DTW library that I have used — <a href="https://github.com/slaypni/fastdtw">fastdtw</a>. The original DTW algorithm consists of mainly 3 parts (a) Compute distance matrix (b)Compute accumulated cost matrix (c)Search the optimal path. Hence, it takes quite a bit of time to compute. , fastDTW is python implementation of FastDTW that approximates the DTW algorithm and according to its website, it provides optimal or near-optimal alignments with an O(N) time and memory complexity. Below is code sample of fastDTW</p><pre>import numpy as np<br>from scipy.spatial.distance import euclidean<br><br>from fastdtw import fastdtw<br><br>x = np.array([[1,1], [2,2], [3,3], [4,4], [5,5]])<br>y = np.array([[2,2], [3,3], [4,4]])<br>distance, path = fastdtw(x, y, dist=euclidean)<br></pre><p>Assuming we now want to replace x and y of the code sample with pose descriptors to help us with frame matching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fNb6LLb_mbmLaQ_PXwIa4g.png" /></figure><p>However, FastDTW only accepts single dimensional array, so there is a limitation to how we can model the pose descriptor.</p><p>Back to our data.</p><p>Idea 1: For each frame, we have 33 sets of positional data of each body part. One idea is to generate 33 sets of DTW warped paths. Eg. x(nose) = np.array([[x1,y1],[x2,y2],…])</p><p>Idea 2: For each frame, calculate pairwise distance and angles for desired adjacent pairs of body parts. Then join up all the pairs of angles and distances for desired parts into a single array. Eg. x(nose) = np.array([[angle1,distance1,angle2,distance2,…], angle1,distance1,angle2,distance2,…],…]). See illustration below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oe2mQ99SJ5CVx3igoZZDMQ.png" /><figcaption>Using pairwise distance and angles instead of positional data</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V3H9yy-PDwV4JXI0tUlDCA.png" /><figcaption>connecting all the dots</figcaption></figure><p>Idea 3: For each frame, join up all the positional data for desired parts into a single array. Eg. x = np.array([[x1,y1,x2,y2,…],..])</p><h3>Results</h3><p>Idea 1 didn’t work well as the 33 DTW sets are disparate, and there is a need to give further thought how to resolve this problem.</p><p>Idea 2 didn’t work well, even when angles or distance are used alone.</p><p>Idea 3 was finally implemented as it works for me. It was able to discern the difference between a good dancer and poor dancer. You may consider using points and method that are relevant to your use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cNnD2UqjBCC4DsC6yLOPIA.png" /><figcaption>Learner 2 is a better dancer!</figcaption></figure><p>A smaller DTW distance implies high similarity. The lower distance by Learner 2 is validated against ground truth.</p><p>In addition, DTW warp paths are used to determine the matched frames. See the image where posture of coach and learner in matched frames are superimposed on each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tp1QvoZAganwbYGBlpGvzA.png" /><figcaption>Learner 1’s matched frames with Coach</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecBAEJg8-HihBKCltGFVuQ.png" /><figcaption>Learner 2’s matched frames with Coach</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nx5LG_8pzXam2oxDthmciA.png" /><figcaption>6 core angles to distinguish dance movement. See <a href="https://www.mdpi.com/1424-8220/17/6/1261/htm">Source</a></figcaption></figure><p>Coordinates of matched frames could be used to compute the 6 six core angles for further evaluation. Using a angle or distance threshold, we could effectively evaluate the learner’s dance move against that of a coach!</p><p>Thanks for reading, hope you enjoy the post. Feel free to share if you have other ideas about automated scoring. =)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ba43532ae65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi-Person Pose Estimation with Mediapipe]]></title>
            <link>https://shawntng.medium.com/multi-person-pose-estimation-with-mediapipe-52e6a60839dd?source=rss-ebcda6d00656------2</link>
            <guid isPermaLink="false">https://medium.com/p/52e6a60839dd</guid>
            <category><![CDATA[mediapipe]]></category>
            <category><![CDATA[pose-estimation]]></category>
            <dc:creator><![CDATA[Shawn Tng]]></dc:creator>
            <pubDate>Sat, 20 Mar 2021 05:54:28 GMT</pubDate>
            <atom:updated>2021-04-10T01:56:20.126Z</atom:updated>
            <content:encoded><![CDATA[<p>Human pose estimation from video is adopted in various applications such as sign language recognition and full-body gesture control. There are also usages in movement sequence classification of physical activities such as yoga, exercise and dance, enabling quantification of movements through body landmarks detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*KA1Ek2xLNREWTV08-_vWuQ.png" /><figcaption>Are you with the crew?</figcaption></figure><p>There are a variety of pose estimations software available, such as <a href="https://github.com/CMU-Perceptual-Computing-Lab/openpose">OpenPose </a>, <a href="https://google.github.io/mediapipe/solutions/pose.html">MediaPipe</a>, <a href="https://www.tensorflow.org/lite/examples/pose_estimation/overview">PoseNet</a>, etc. While OpenPose and PoseNet are able to support real-time multi-person pose estimations, Mediapipe is only able to support single person pose estimation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*LIz_JY2-Gw5YpJPQMkd5Ig.png" /><figcaption>Single Pose Estimation</figcaption></figure><p>Current state-of-the-art approaches rely primarily on powerful desktop environments for inference, whereas Mediapipe’s method is able to achieve real-time performance on most modern mobile phones, desktops and web(javascript). In this article, I will be sharing how to adapt Mediapipe for multi-person pose estimations.</p><h3>Dataset</h3><p>I have decide to use a TikTok video to do this experiment. The dataset could be found <a href="https://youtu.be/BR9MGDHqLko">here</a>. In the video, celebrities <a href="https://www.instagram.com/qiufengze">Fengze</a> and <a href="https://www.instagram.com/shoumethemoneyxx">Shou </a>did a TikTok dance of the latter’s song “Colorful”.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBR9MGDHqLko%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBR9MGDHqLko&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBR9MGDHqLko%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/39c7e11bd838842d5f2cb5228e85e7c9/href">https://medium.com/media/39c7e11bd838842d5f2cb5228e85e7c9/href</a></iframe><h3>Something about Mediapipe’s Pose Estimation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*YC0leyb9hWWm63NG.png" /><figcaption>Source: <a href="https://google.github.io/mediapipe/solutions/pose.html">https://google.github.io/mediapipe/solutions/pose.html</a></figcaption></figure><p>MediaPipe Pose Landmark feature is able to extract 33 landmark keypoints as shown above. The output is a list of pose landmarks, and each landmark consists of x and y landmark coordinates normalized to [0.0, 1.0] by the image width and height respectively.</p><p>If we intend to compare the pose of 2 persons in a photo, eg, in a dance like this video, one feasible approach was to determine the boundary box of a person, crop the box and then run single person pose estimation on the cropped image.</p><h3>Sample Code</h3><pre>import cv2<br>import mediapipe as mp<br>mp_drawing = mp.solutions.drawing_utils<br>mp_pose = mp.solutions.pose<br><br># For static images:<br>with mp_pose.Pose(<br>    static_image_mode=True, min_detection_confidence=0.5) as pose:<br>  for idx, file in enumerate(file_list):<br>    image = cv2.imread(file)<br>    image_height, image_width, _ = image.shape<br>    # Convert the BGR image to RGB before processing.<br>    results = pose.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))<br><br>    if not results.pose_landmarks:<br>      continue<br>    print(<br>        f&#39;Nose coordinates: (&#39;<br>        f&#39;{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].x * image_width}, &#39;<br>        f&#39;{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].y * image_height})&#39;<br>    )<br>    # Draw pose landmarks on the image.<br>    annotated_image = image.copy()<br>    # Use mp_pose.UPPER_BODY_POSE_CONNECTIONS for drawing below when<br>    # upper_body_only is set to True.<br>    mp_drawing.draw_landmarks(<br>        annotated_image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)<br>    cv2.imwrite(&#39;/tmp/annotated_image&#39; + str(idx) + &#39;.png&#39;, annotated_image)<br><br># For webcam input:<br>cap = cv2.VideoCapture(0)<br>with mp_pose.Pose(<br>    min_detection_confidence=0.5,<br>    min_tracking_confidence=0.5) as pose:<br>  while cap.isOpened():<br>    success, image = cap.read()<br>    if not success:<br>      print(&quot;Ignoring empty camera frame.&quot;)<br>      # If loading a video, use &#39;break&#39; instead of &#39;continue&#39;.<br>      continue<br><br>    # Flip the image horizontally for a later selfie-view display, and convert<br>    # the BGR image to RGB.<br>    image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)<br>    # To improve performance, optionally mark the image as not writeable to<br>    # pass by reference.<br>    image.flags.writeable = False<br>    results = pose.process(image)<br><br>    # Draw the pose annotation on the image.<br>    image.flags.writeable = True<br>    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)<br>    mp_drawing.draw_landmarks(<br>        image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)<br>    cv2.imshow(&#39;MediaPipe Pose&#39;, image)<br>    if cv2.waitKey(5) &amp; 0xFF == 27:<br>      break<br>cap.release()</pre><h3>Cropping using YOLO</h3><p>You only look once (<a href="https://pjreddie.com/darknet/yolo/">YOLO</a>) is a state-of-the-art, real-time object detection system. On a Pascal Titan X it processes images at 30 FPS and has a mAP of 57.9% on COCO test-dev. As YOLO is proven to be extremely fast and accurate, it can be used to detect a person object in the video above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*3DGWLu_7eQsILmK0PfTB2A.jpeg" /></figure><p>For each person object detected in a video frame, we execute pose estimation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/126/1*BErhOg8kBZOG5CqOZkRolA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*TWX8HzjxSuHyI8-5NQQpLg.jpeg" /><figcaption>Multi Person Pose Estimation</figcaption></figure><h3>Yay! Are we done yet ?</h3><p>Not quite yet, as there are some interesting observations made for subsequent frames extracted. The pose estimation seems to break down at some frames before resuming its functionality later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*YxRm-z24CGSjz7B63JeBjQ.png" /></figure><p>A deeper look into MediaPipe’s pose detection shows that it explicitly predicts two additional virtual keypoints that firmly describe the human body center, rotation and scale as a circle. Inspired by <a href="https://en.wikipedia.org/wiki/Vitruvian_Man">Leonardo’s Vitruvian man</a>, it predicts the midpoint of a person’s hips, the radius of a circle circumscribing the whole person, and the incline angle of the line connecting the shoulder and hip midpoints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*lNlQvvUfckkQcoks.png" /><figcaption><em>Vitruvian man aligned via two virtual keypoints predicted by BlazePose detector in addition to the face bounding box. </em>Source: <a href="https://google.github.io/mediapipe/solutions/pose.html">https://google.github.io/mediapipe/solutions/pose.html</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*4Te-7FP41oQIVHVap4-hyA.png" /></figure><p>In a separate experiment, it was demonstrated that indeed there is some “initial calibration” that happens at the start before the subsequent pose estimations get accurate. It also implies that each person detected is required to have his /her own instance of pose estimator (see below).</p><pre>mp_pose.Pose(<br>    min_detection_confidence=0.5,<br>    min_tracking_confidence=0.5)</pre><p>If we are able to detect and somehow identify a person, it is possible to correct the above problem. Basically if the person “exists”, use his/her pose estimator. Otherwise, “create” a new person with a new instance of pose estimator.</p><p>So now the burden is on YOLO to consistently detect the same person for every frame. Can YOLO do it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-3gBXtyCnzzrrhMUiJpzA.png" /></figure><p>Every person object detected was labelled to conduct this experiment. As seen above, there seem to be a “swopping” issue. The first object detected may not be the same first object detected in the previous video frame. So we need a way to “identify” a person.</p><h3>Enhancement</h3><p>2 global variables are created. pose_estimator keeps track of the pose estimators and each will have a corresponding dimensional data (object boundary) last collected. Each person object detected by YOLO will now have his boundary box checked (using distance measures) against the global variable. We can assume each set of pose estimator and dimensions represent a person.</p><pre># global variables<br>pose_estimator = []<br>pose_estimator_dim = []</pre><pre># For each object detected<br># WHICH POSE ESTIMATOR TO USE.<br>selected_pose_idx=0<br>                                                     <br>if(len(pose_estimator)==0): <br>   pose = mp_pose.Pose(min_detection_confidence=0.6,     <br>             min_tracking_confidence=0.6)<br>   pose_estimator.append(pose)    <br>   pose_estimator_dim.append(&lt;detected object&#39;s boundary&gt;)<br>   selected_pose_idx = len(pose_estimator)-1                            <br>elif(&lt;object_id&gt;&gt;len(pose_estimator)):<br>   thresholdForNew = 100<br>   prev_high_score = 0<br>   selected_pose_idx_high =0<br>   prev_low_score = 1000000000<br>   selected_pose_idx_low =0<br>   pose_idx = 0<br>   for dim in pose_estimator_dim:<br>      score = compareDist(dim,&lt;detected object&#39;s boundary&gt;)<br>      if(score &gt; prev_high_score):<br>         selected_pose_idx_high  =  pose_idx<br>         prev_high_score = score<br>      if(score &lt; prev_low_score):                                        <br>         selected_pose_idx_low  =  pose_idx<br>         prev_low_score = score<br>      pose_idx+=1<br>   if prev_high_score &gt; thresholdForNew:<br>      pose = mp_pose.Pose(min_detection_confidence=0.6,                   <br>min_tracking_confidence=0.6)<br>      pose_estimator.append(pose)    <br>      pose_estimator_dim.append(&lt;detected object&#39;s boundary&gt;)<br>      selected_pose_idx = len(pose_estimator)-1 <br>   else:<br>      selected_pose_idx = selected_pose_idx_low<br>   pose_estimator_dim[selected_pose_idx]=&lt;detected object&#39;s boundary&gt;<br>                                    <br>else:<br>   pose_idx = 0<br>   prev_score = 1000000000                                <br>   for dim in pose_estimator_dim:<br>      score = compareDist(dim,[x_min, y_min, box_width, box_height])<br>      if(score &lt; prev_score):                                        <br>         selected_pose_idx  =  pose_idx<br>         prev_score = score   <br>      pose_idx+=1</pre><pre>   pose_estimator_dim[selected_pose_idx]=&lt;detected object&#39;s boundary&gt;</pre><p><strong>Final Output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*5FiyGceAPpG3rt2wu0FzHA.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqyvC4pOKUP8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqyvC4pOKUP8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqyvC4pOKUP8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9279704e78576a2a34aee8d298e41cfb/href">https://medium.com/media/9279704e78576a2a34aee8d298e41cfb/href</a></iframe><h3>Conclusion</h3><p>We have achieved multi-person pose with Mediapipe in this implementation. Do note that it is possible to add additional “features” such as face similarity in order to identify the person. Hope you find this useful for your work or studies. Stay tuned for the next post that will demonstrate how to further utilize the landmarks obtained.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52e6a60839dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>