<?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 Ripul Agrawal on Medium]]></title>
        <description><![CDATA[Stories by Ripul Agrawal on Medium]]></description>
        <link>https://medium.com/@ripulagrawal?source=rss-69f978f61dc8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j_kvY_hwV2IiPiXZsgj5vQ.jpeg</url>
            <title>Stories by Ripul Agrawal on Medium</title>
            <link>https://medium.com/@ripulagrawal?source=rss-69f978f61dc8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 13:46:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ripulagrawal/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[Invisible Cloak Using OpenCV | Analytics Steps]]></title>
            <link>https://ripulagrawal.medium.com/invisible-cloak-using-opencv-analytics-steps-e7cd9e551563?source=rss-69f978f61dc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7cd9e551563</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ripul Agrawal]]></dc:creator>
            <pubDate>Fri, 31 Jul 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-12-10T05:42:58.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*HSJ3czsZE_adZ_YVNH17yw.jpeg" /></figure><blockquote><strong>“Let us step into the night and pursue that flighty temptress, adventure.” — </strong><a href="https://en.wikipedia.org/wiki/Harry_Potter_(film_series)"><strong>Harry Potter Movie</strong></a><strong>”</strong></blockquote><h3><strong>Introduction</strong></h3><p>In the last few blogs, we have discussed <strong>OpenCV</strong> with some of its functions and applications in different fields including <strong><em>Computer Vision, facial recognition, </em></strong><a href="https://www.analyticssteps.com/blogs/streaming-live-motion-detection-using-opencv"><strong><em>live motion detection</em></strong></a><strong><em>, object detection, image processing, tracking of 3D objects, and many more.</em></strong></p><p>Other than that, we have also have covered how to use an external camera device with OpenCV and stream results on your laptop/PCs with the help of third-party applications like <strong>IP webcam</strong> in case of integration with an <strong>android camera</strong>. ( <a href="https://www.analyticssteps.com/blogs/streaming-android-camera-using-opencv">Link</a> to that blog)</p><p>As already discussed, all the <a href="https://www.analyticssteps.com/blogs/open-cv-applications-functions">OpenCV applications</a>, valid for web cameras, can be implemented with the external camera devices too, like, a low budget home surveillance system without using CCTV cameras.</p><p>Moving forward with this now, it&#39;s time to work on some fun projects with the help of OpenCV, i.e., so we are considering here the <strong><em>“Invisible Cloak” like “Harry Potter had which he got from Dumbledore at Hogwarts.”</em></strong></p><p>It’s not anything new to the Harry Potter fans, but this is new for the people who don’t have an idea about it, so it’s a technique to render physical objects invisible. In the below image you can see how Potter’s body is not visible, it&#39;s just a miracle of the cloak.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/0*HP562m1lYFI7F0PP" /><figcaption><em>A glimpse of Potter’s Invisible Cloak</em></figcaption></figure><p>You will find more such a demo <a href="https://www.google.com/search?q=invisible+cloak+gif&amp;sxsrf=ALeKk01ovOrwHOHiDEKeIx_8afMArq2VBg:1595321352620&amp;tbm=isch&amp;source=iu&amp;ictx=1&amp;fir=TSf_a18Cp2JLLM%252Cz-mxyIlY9hoAYM%252C_&amp;vet=1&amp;usg=AI4_-kRD7gpkS6wO0QU34o_BYAMxOvm_yw&amp;sa=X&amp;ved=2ahUKEwjA1pmU-93qAhXGyzgGHd5KCYcQ9QEwCHoECAoQNA&amp;biw=1536&amp;bih=722#imgrc=TSf_a18Cp2JLLM">here</a>.</p><h3><strong>Cloak with OpenCV</strong></h3><p>Inspired by Harry Potter, I felt like creating one for me, just for fun, so I just dived into it and came up with the same using OpenCV. Follow this to create your own invisible cloak.</p><p>Obviously, it will not be any real but will be graphical. It will be based on the <strong><em>image processing approach i.e. color detection and masking</em></strong> which means it will work for some particular colors as per our choice.</p><blockquote>For a brief, let’s suppose you have chosen the red color, then after you run the code. After two seconds bring any red color cloth and hide your self in that, and then you will not be visible on the screen.</blockquote><p>We will be using both the <strong>web-camera and android camera</strong> for the testing of Invisible Cloak.</p><h4><strong>1. Get Started with Coding</strong></h4><ul><li><strong>Import the required libraries</strong></li><li><strong>OpenCV</strong> will be used for the image processing part i.e. to start the camera, read each frame in code, color detection, color masking, and streaming final results</li><li><strong>Numpy</strong> will be used to deal with arrays as images in python are a series of Numpy array</li><li><strong>Time</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*9AGNybbB9OzEu9O_" /><figcaption>Import the libraries</figcaption></figure><p><strong>Initialize video Capture object </strong>from a web camera and suspends execution for 2 seconds</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*Bta5EhngLtF4HM0H" /><figcaption><em>Video capture object</em></figcaption></figure><p><strong>Initialize background to be visible </strong>in place of the invisible object whenever any red color ( or any other color) object will come in front of the camera.</p><p>In the beginning, it will be equals to 0 but as soon as the camera will start it will record the frame for 30 seconds and then stored the same in the background variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/0*oNgP-xZOxiE9k8HY" /><figcaption><em>Record the background</em></figcaption></figure><ul><li>Initialize while loop to read each frame through the web camera till any keypress, in this <strong><em>ESC </em></strong>key of the keyboard.</li><li>Next, convert the image from <strong><em>RGB format into HSV format (hue-saturation-value) as RGB is highly sensitive to illumination.</em></strong></li><li>Hue contains the color information in degrees where,</li><li><strong>0 degree — </strong>Red color</li><li><strong>120 degree- </strong>green color</li><li><strong>240 degree — </strong>white color</li><li><strong>Saturation is </strong>used to encode the intensity of color i.e. amount of gray in a particular color.</li><li><strong>Value describes </strong>the brightness of the color.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/0*rGVH1IqGfJYLtCLG" /><figcaption><em>Get the HSV format of each frame</em></figcaption></figure><p><strong>Color Detection: </strong>Now, it&#39;s time to detect the red color from the frames that first need to define the range both the lower bound and upper bound to like as below. Repeat the same step for mask 2 and combined both of the masks with <strong><em>OR operations</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*e4c2I-Xs2SXTzHMO" /><figcaption><em>Create a mask for the red color</em></figcaption></figure><p>In the above code, wherever red color will find it will apply thresholding so as change its value or in other words will save the portion of red color in variables i.e. <strong>mask1 &amp; mask2</strong>.</p><p><strong>Color Segmentation: </strong>Now we have retrieved the mask of the red color and now will segment both of those using morphology and dilation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/0*q-SYxgYKDo7Hp2S7" /><figcaption><em>Dilation of the image</em></figcaption></figure><ul><li><strong>Create </strong>an inverted mask to segment out the particular out of it using<strong> bitwise_not().</strong></li><li><strong>Generate </strong>the final output by combining the background captured and one with the masked red color following by the help of<strong> bitwise_and() operations.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/0*sy45E_PVF_0WxAY2" /><figcaption><em>Final output by color masking</em></figcaption></figure><p>Here you can check the output of my invisible cloak, where I have used a red pillow instead of a red cloth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/0*tFyVvOC2Tj_3euXY" /><figcaption><em>My Invisible Cloak</em></figcaption></figure><h3>Invisible Cloak using Android Camera</h3><p>Above we have created an invisible cloak using a web-camera and it worked fine. What if you want to use your android phone for the same. It will be simple and just similar to the case that we have discussed. In the previous post, we have covered, how to access the android camera in OpenCV using third-party applications. So let’s combine both of them as below.</p><h4>Get Start with Coding</h4><ul><li><strong>Import the required packages,</strong></li><li><strong>urllib </strong>to open internet websites by using their URLs. Here it will be used to access the camera with their IPs.</li><li><strong>OpenCV </strong>will be used for image processing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/0*aO98bgYOKFuTl6NU" /><figcaption><em>Import the required package to work with the android camera</em></figcaption></figure><ul><li><strong>Next, initialize the for loop </strong>to start the camera and then access the live image from the URL (captured by android phone) following by the conversion into<strong> NumPy using cv2.imdecode().</strong></li><li>After that initialize the background with the frames for 30 seconds as we did above.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/0*_oQ4uvZcDNJSkCq7" /><figcaption><em>Capture background for 30 seconds</em></figcaption></figure><ul><li><strong>Now use a while loop </strong>to start the camera for creating an invisible cloak.</li><li><strong>Use Urllib to access </strong>the image from the android and convert it into a NumPy format. Once done with this step, now repeat the same steps that we have used for web-camera as the conversion of an image into <strong><em>HSV format, color detection, color segmentation, and then the final output of invisible cloak.</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/0*2yNauoxgpwBLrsqK" /><figcaption><em>code for an invisible cloak with android</em></figcaption></figure><p>In the following image, you can see the output of this invisible cloak as a real screen vs cloak screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kyXnddMphws3CMoO" /><figcaption><em>Invisible Cloak for android camera</em></figcaption></figure><h3>Conclusion</h3><p><em>OpenCV is a vast field and has many practical applications available in the industry like object detection, motion detection, facial recognition</em>, and nowadays many organizations are using the same in the name of AI and <a href="https://www.analyticssteps.com/blogs/an-overview-to-computer-vision-thats-redefining-surveillance">Computer Vision</a> for developing surveillance systems to keep track of criminal activities.</p><p>Another reason for its useful its execution speed and efficiency as compared to other image processing libraries. Once you dive into it, will open the way for many innovative ideas and fun projects like you can control a racing game with gloves in your hand, or else you can be invisible in your online video classrooms, and many more.</p><p>This blog is all about the developing Invisible Cloak that our childhood hero <strong><em>Harry Potter used in Hogwarts acquired from Dumbledore</em></strong>. It will not be the real cloak but some <strong><em>graphical tricks with OpenCV and Python to make things invisible in front of the camera</em></strong> based on color detection and color segmentation techniques. The same has been done for an android camera using OpenCV and Python.</p><p><em>Originally published at </em><a href="https://analyticssteps.com/blogs/invisible-cloak-using-opencv"><em>https://analyticssteps.com</em></a><em> on July 31, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7cd9e551563" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streaming Android Camera using OpenCV | Analytics Steps]]></title>
            <link>https://ripulagrawal.medium.com/streaming-android-camera-using-opencv-analytics-steps-31623134219f?source=rss-69f978f61dc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/31623134219f</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ripul Agrawal]]></dc:creator>
            <pubDate>Mon, 27 Jul 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-12-10T05:55:02.310Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*VUHOGnqME1YRTMm0E7R7GQ.jpeg" /></figure><p>In the previous blogs, you have seen OpenCV used with Python in various applications like <strong><em>image processing, face detection, object detection, gesture recognition, object tracking, </em></strong><a href="https://www.analyticssteps.com/blogs/streaming-live-motion-detection-using-opencv"><strong><em>motion detection</em></strong></a><strong><em>, etc.</em></strong></p><p><strong>OpenCV</strong> is an <strong>Open Source Computer Vision library</strong>, as it provides various functions, to perform all of the applications, <strong><em>like read, write, display the images, edge detection, contour detection, and many more.</em></strong> All these functions work for both images and videos either saved media or live streaming. (To know more about OpenCV and its application and functions, learn from <a href="https://www.analyticssteps.com/blogs/open-cv-applications-functions">here</a>).</p><p>For live streaming, you can either use a <strong>web camera</strong> or some external camera like or <strong>android camera</strong>. This article is about how to access the android camera with the help of OpenCV in python and later will perform some of the common <strong>OpenCV applications.</strong></p><h3>Comparing Cases of Web Camera and External Camera</h3><ul><li>When using the web camera for any application then it’s limited to one place as you cant carry it everywhere all the time for testing. But this is not the case with the external camera, as you can carry it anywhere by placing the system in one place, so it makes it flexible for testing.</li><li>Another used case is when you want to test your code in the dining hall, but you can’t as your system is in your room but if you use an external camera then it’s possible for you.</li><li>Apart from this if you want to keep process everything going on in your house/offices by sitting in your room then also this can be possible by using an external camera, obviously, replacement if CCTV, like face detection, face recognition, object detection, motion detection, and many more.</li></ul><h3>Pre-requisite</h3><ul><li>Python 3</li><li>OpenCV</li><li>Numpy</li><li>Install <a href="https://play.google.com/store/apps/details?id=com.pas.webcam&amp;hl=en_IN">IP webcam</a> on your android device</li><li>Jupyter notebook or any other code editor like vscode, sublime.</li></ul><h3>Getting Started</h3><ul><li>Connect your PC/laptop and android device to the same wifi,</li><li>Open the app on your phone,</li><li>Navigate through the app and select the option Start server at the bottom,</li><li>Note down the IP address that appears on the screen,</li><li>Paste the same in the browser and then a page will open where you can control the camera of your phone with the available options there.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iyezD-As85HLo5TV" /><figcaption><em>IP webcam controller in browser</em></figcaption></figure><ul><li>From the above image, it’s clear that with the IP address there are several options available to control the android camera from the laptop like the way CCTV cameras.</li><li>Capture image, focused image, can save it to the storage, video recording, live streaming in the laptop as seen in the below figure,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GIVErl1XOTiir7LD" /><figcaption><em>Live streaming from android in laptop</em></figcaption></figure><p>Also can toggle flash and front camera from the browser.</p><h3>Access Android Camera with OpenCV</h3><p>At the top of the page in the browser move to Video render option and then select <a href="https://www.analyticssteps.com/blogs/revisiting-the-basics-whats-inside-javascript-engine">Javascript </a>and then copy the image address by right click on that, as it will be helpful to access the camera in OpenCV.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hc6fXpB5yX5bfBkf" /><figcaption><em>Get the image address in JavaScript mode</em></figcaption></figure><p>Open Jupyter notebook and get started with coding;</p><p><strong>Import the required packages</strong></p><ul><li>Urllib- This package will allow us interacting with internet websites by their URL address. It provides different modules to open, parse the URLs as seen in the below image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/0*Y1owRQdDGDWxobR7" /><figcaption><em>urllib packages in Python </em><a href="https://www.educative.io/edpresso/what-is-the-urllib-module-in-python-3"><em>Sources</em></a></figcaption></figure><p>CV2 — OpenCV package to deal with the images to display the images captured from the camera or you can term this as live streaming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*GFLBiunOwLiIbVPF" /><figcaption><em>Import the libraries</em></figcaption></figure><p>Store the image address from the above in a variable <strong>URL</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/0*TA0sDxJF7kiCe2h3" /><figcaption><em>Image address for live streaming</em></figcaption></figure><ul><li>Start the while loop till any key will be pressed to terminate the same, Q in this case. Next access the image from the URL using<strong> urlopen() function</strong>, bypassing the above URL as an argument and it will return and it will return <strong>http.client.HTTPResponse object</strong>.</li><li>Next, convert the object into NumPy and later on, we will use <strong>cv2.imdecode()</strong> to convert the array into an image format from the streaming data.</li><li>Now it&#39;s time for live streaming using <strong>cv2.imshow()</strong> from android’s camera in python.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H-d_o765RqcCEbpm" /><figcaption><em>Live streaming from the android camera using OpenCV</em></figcaption></figure><p>Once you will be done with the above procedure, now you can any <a href="https://www.analyticssteps.com/blogs/an-overview-to-computer-vision-thats-redefining-surveillance">computer vision application</a> with your <strong><em>android camera like object detection, motion tracking, face recognition, etc</em></strong>. Without investing in CCTV cameras you can spy on your house by sitting in one place with your android phone.</p><h3>OpenCV applications with the android camera</h3><h3>Face Detection</h3><ul><li>Import the required libraries</li><li>Load the pre-trained <strong>haar cascade classifier</strong> for <strong>face detection</strong> from the storage</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/0*v2Qe_TwhPlFyvPUi" /><figcaption><em>Load the haar cascade classifier for face detection</em></figcaption></figure><p>Follow the same code to access the<strong> streaming image</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/0*rXnFajX_Gx1EVf2C" /><figcaption><em>Get the streaming image</em></figcaption></figure><p>Convert the image into the <strong>grayscale format</strong> and then use the <strong>“using classifier”</strong> object to detect the faces present in the streaming image and store all of the coordinates which will be used to plot bounding boxes on the detected faces.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nVBnQkk-auJHt-Xw" /><figcaption><em>Live streaming of face detection from android phone</em></figcaption></figure><h3>Motion Detection</h3><p>The last article covered <strong>live motion detection using OpenCV</strong> with the help of a web camera but it has several limitations as discussed above because it will bound to use at only one place. Instead, use your<strong> Android camera</strong> to keep track of changes at any place concerning a particular frame at a particular time.</p><p>Let’s suppose you are doubting that someone behind you makes changes in your workplace but you can’t be able to figure it out as <strong>CCTVs</strong> are too costlier to afford but this approach is more economical and easier to keep track of victims.</p><ul><li>Import all the required libraries</li><li>Assign a <strong>static frame</strong> with the frame concerning the one you want to compare all other frames, in this case initially it will be none, and once a camera start it will initialize to the first frame.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*ibAkC-29_FcxPHjx" /><figcaption><em>Import the required modules</em></figcaption></figure><p>Load the streaming image into image format from the URL using urllib modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/0*RuD01xWj-1px4V0U" /><figcaption><em>Store the streaming image into an image format</em></figcaption></figure><ul><li>Convert the image into a grayscale format followed by the image blurring using <strong>cv2.GaussianBlur() function</strong>, to detect motion changes.</li><li>The next step is to calculate the difference between <strong>the static frame and image</strong> from streaming by an android camera which further if crosses the set threshold, demonstrates the motion detection. Later on, using contour detection bounding boxes will be plotted on the region of motion in the image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*lza4pfybW9IaPBMA" /><figcaption><em>Steps for motion detection</em></figcaption></figure><p>Here is the completed code along with the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*97oSziTgKoL__NZf" /><figcaption><em>Completed code for live motion detection using Android Camera</em></figcaption></figure><h3>Conclusion</h3><p><strong>OpenCV, a computer vision library</strong>, is open-source with several functions available to perform the different applications, make everything easy and effective. Also, it’s fast in computation as compared to other available languages like<strong> MATLAB.</strong></p><p>OpenCV can be used for images as well as videos either from the storage or from the live streaming using <strong>a web- camera</strong> or external camera. This blog has been specifically designed to use OpenCV with an external camera i.e. <strong>android camera</strong> by using third-party application <strong>IP Webcam</strong> on the same network i.e. both the android device and laptop/PC.</p><p>With this, you can try different computer vision approaches like keep spying of your house in your absence, or when you come back to your place.<em> Object detection, facial recognition, motion tracking, and many others.</em></p><p><em>Originally published at </em><a href="https://analyticssteps.com/blogs/streaming-android-camera-using-opencv"><em>https://analyticssteps.com</em></a><em> on July 27, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31623134219f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streaming Live Motion Detection using OpenCV | Analytics Steps]]></title>
            <link>https://ripulagrawal.medium.com/streaming-live-motion-detection-using-opencv-analytics-steps-dbf2ba12b9?source=rss-69f978f61dc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbf2ba12b9</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Ripul Agrawal]]></dc:creator>
            <pubDate>Tue, 14 Jul 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-12-11T05:33:42.160Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*80E5fmtLjHnPDhV4mXBuXA.jpeg" /></figure><blockquote><strong><em>“It seems probable that once the machine thinking method had started, it would not take long to outstrip our feeble powers… They would be able to converse with each other to sharpen their wits. At some stage, therefore, we should have to expect the machines to take control.” — </em></strong><a href="https://www.britannica.com/biography/Alan-Turing"><strong><em>Alan Turing</em></strong></a></blockquote><h3>Introduction</h3><p>In the <a href="https://www.analyticssteps.com/blogs/open-cv-applications-functions">last blog</a>, we featured OpenCV along with the functions it provides and the areas of application. OpenCV is a <a href="https://www.analyticssteps.com/blogs/an-overview-to-computer-vision-thats-redefining-surveillance">Computer Vision</a> library, written in two languages, i.e., <strong><em>C++ &amp; Python to deal with both images and videos.</em></strong></p><p>Besides, it provides real-time support using the camera or web cameras in many applications as can be seen in <a href="https://www.analyticssteps.com/blogs/introduction-yolov4">Yolo</a>, <strong>Face Recognition</strong>, and many more.</p><p><strong>Some of the common functions available by OpenCV are,</strong></p><ul><li>Read, write and display the image,</li><li>Different color formats for image i.e. BGR, RGB, grayscale, HSV, etc,</li><li>Data Augmentation i.e. rotation, shrinking, resize, magnification, etc,</li><li>Image Thresholding,</li><li>Edge Detection, and</li><li>Contour Detection will help in detecting different shapes from the image.</li></ul><p><strong>Common Areas of application are,</strong></p><ul><li>Image Processing,</li><li>Face Recognition,</li><li>Object Detection,</li><li>Gesture Recognition,</li><li>Can create a high-resolution image from different images,</li><li>Track moving objects,</li><li>Track 3D models,</li><li>Track camera movements,</li><li>Track human motions, and</li><li>Motion Detection.</li></ul><h3>Comparison with Other Languages</h3><p>No doubt there are <a href="https://www.analyticsinsight.net/opencv-vs-matlab-which-is-best-for-successful-computer-vision-project/">other languages</a> available for computer vision but none of them compete with OpenCV, as <strong>it&#39;s open-source</strong> and also there is no restriction on its use as you can use it without a license while some language requires a license to use like <strong>Matlab</strong>. To use Matlab on a large scale you have to purchase a license that makes it less economical.</p><p>It also fits best in terms of execution as OpenCV is much faster as its speed can reach up to 80 in some cases. So in this way, anyone who wants to explore the field of computer vision or image processing can easily use Open CV whereas Matlab is more feasible for the researchers who can afford its license.</p><h3>Understanding Motion Detection</h3><p>The core concept is to detect motion in the frame i.e. if any change will occur in the frame using OpenCV. It can be done for <em>either recorded video or live streaming i.e web-camera or any other camera mounted.</em></p><p>In this article, we will detect motion from the <strong>web camera using OpenCV</strong> and a bounding box will be rendered to the motion detected as if any new object will introduce in the frame then a bounding box will appear surrounding the object.</p><p>In videos, multiple frames are stack together to form a video. For motion detection, we calculate the difference between two continuous frames and if it’s higher than the set threshold, it means motion detection has been observed there.</p><h3>Code your own Motion Detector</h3><h4>Import the Libraries</h4><p>Import the required libraries to be used i.e.<strong> cv2 (OpenCV), NumPy</strong>. As the video is comprised of images, and OpenCV will be used to preprocess images i.e. <em>starting the web camera, to read video as a stack of frames, deal with the color formatting of the frame, find the gaussian blur of the image, calculation the difference between frames, image thresholding, dilation, contour detection, and bounding boxes over the motion detected.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/0*6DLBkw9m4bCfgALZ" /><figcaption><em>Code Snippet: 1</em></figcaption></figure><h4>Assignment of Static Frame</h4><p>To perform motion detection, we will compare every frame with the first frame that will be termed <strong>as a static frame</strong>. So every time each frame will be compared with the static frame and based on the difference motion in the frames will be detected.</p><p>Initially, the static frame will be <strong>None</strong> and will initialize with the first frame once the web camera is opened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/0*wKu1be9ORIkKvM-J" /><figcaption><em>Code Snippet: 2</em></figcaption></figure><h4>Create video capture Object</h4><p>To capture a live stream from the web camera using OpenCV the first step is to create a <strong>VideoCapture object by passing 0</strong> as an argument to signify the camera to use. Set the window size to a particular dimension.</p><p>Next, we will run <strong>while</strong> loop, to capture every frame from the web camera and run until the camera will be closed using <strong>waitkey</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*tDToNmieqAwO-2ls" /><figcaption><em>Code Snippet: 3</em></figcaption></figure><h4>Read the frames and convert into grayscale</h4><p>Now read the frames using the object initialized above and further convert it into the <strong>grayscale format</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/0*DFPiMRdDoJVHoblh" /><figcaption><em>Code Snippet: 4</em></figcaption></figure><h4>Image Blurring</h4><p>Now the next step is to remove the noise from each frame basically remove high frequencies from the images using the <strong>GaussianBlur</strong> function by CV2. Pass the height and width of <strong>the low pass filter kernel</strong> as an argument along with the <strong>standard deviation in both directions.</strong></p><p>Also, pass the grayscale image as input to the function. After blurring the image, motion in the consecutive frames will be detected easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*OsJUJcPt2FPuVkcD" /><figcaption><em>Code Snippet: 5</em></figcaption></figure><h4>Update Static Frame</h4><p>Now it&#39;s time to update the static frame with the first frame from the live streaming as no changes in the initial level. This frame will be used as a reference to calculate the absolute difference between each frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*dG7Ml6IE-wKh61me" /><figcaption><em>Code snippet: 6</em></figcaption></figure><h4>Calculate the difference in the frames and detect motion</h4><p>Calculate the absolute difference between the static frame and each frame from the live streaming. Hence the difference is greater than 30, apply <strong>thresholding</strong> to the grayscale to where ever the motion will be detected that the region will be white and later<strong> dilate</strong> that thresholded image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/0*ChQeMcI9fsrTg0HG" /><figcaption><em>Code Snippet: 7</em></figcaption></figure><h4>Find Contours</h4><p>Now the region of motion has been converted to white using thresholding, which can be treated as contours, so use find contours to detect coordinates of the moving objects.</p><p>Apart from the motion detection, once we will get the coordinates of the moving objects to plot the rectangle (bounding box) on them and put the text<strong><em> “Motion Detected”</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZHzfYnwyh4Xg2REz" /><figcaption><em>Code Snippet: 8, </em><a href="https://www.geeksforgeeks.org/webcam-motion-detector-python/"><em>Source</em></a></figcaption></figure><h4>Display frames in live stream</h4><p>Now the motion has been detected in the video, so the next step is for live streaming with results of motion detection.</p><p>Put the code to release the camera and to destroy all the windows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/0*CypJgLS7bRFmniIB" /><figcaption><em>Code Snippet: 9</em></figcaption></figure><h3>Conclusion</h3><p><strong>OpenCV</strong> a computer vision library supports many functions and has many applications including <strong>facial recognition, object detection, tracking human motions, tracking objects, camera movements, motion detection, </strong>etc. In comparison to the other tools, easily accessible to everyone as its open-source and its speed is another factor.</p><p>Many companies are using OpenCV due to its real-time application as it can be integrated with different languages and some of the hardware devices i.e.<strong> raspberry pi </strong>and some others.</p><p>Out of its vast applications, this blog has been framed to cover one of that i.e. <strong><em>Motion Detection based on background subtraction from the live streaming,</em></strong> where each new frame will be keep subtracted from the very first frame after <strong><em>image smoothening</em></strong> and if any region has a value less than some threshold, that signifies the motion detection in the frames. Later using contours, plot the bounding boxes on the region where motion has been detected and put the text over there.</p><p><em>Originally published at </em><a href="https://analyticssteps.com/blogs/streaming-live-motion-detection-using-opencv"><em>https://analyticssteps.com</em></a><em> on July 14, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbf2ba12b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualizing Geospatial Data with Kepler.gl | Analytics Steps]]></title>
            <link>https://ripulagrawal.medium.com/visualizing-geospatial-data-with-kepler-gl-analytics-steps-48053ba2668c?source=rss-69f978f61dc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/48053ba2668c</guid>
            <category><![CDATA[business-intelligence]]></category>
            <category><![CDATA[keplergl]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[uber]]></category>
            <dc:creator><![CDATA[Ripul Agrawal]]></dc:creator>
            <pubDate>Thu, 09 Jul 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-12-11T05:50:27.311Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Y6pEXz2VrROo3m45Nvv0RA.jpeg" /></figure><blockquote><strong>“Data visualizations will often serve an integral role in helping you to uncover key patterns, trends, and anomalies in your data.” </strong><a href="https://www.domo.com/blog/three-key-traps-to-avoid-in-data-storytelling/"><strong>— Brent Dykes, Director, Data Strategy</strong></a></blockquote><h3><strong>Introduction</strong></h3><p><a href="https://www.analyticssteps.com/blogs/5-common-types-data-visualization-business-analytics">Data Visualization</a> is the graphical representation of data with the help of <strong>graphs, maps, charts, heatmaps, and some open-source tools </strong>available i.e. <a href="https://www.analyticssteps.com/blogs/why-is-tableau-used-for-read-the-working-and-key-features-of-tableau">Tableau,</a> <strong>Kepler.gl, Excel sheets, Fusion Charts, etc</strong>. Apart from that, there are some <strong>Python libraries like matplotlib, plotly, seaborn, ggplot.</strong></p><blockquote><strong><em>Visualization of the data will help in understanding the data by getting insights into that like the relationship between different features, recognizing the patterns, and trends.</em></strong></blockquote><p>It will obviously help to roll out the <strong>irrelevant information</strong> from the data and keep the <strong>relevant information</strong> required for the purpose. Also, it’s an easygoing process to visualize large as well as small datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/0*0d51yKz8Cksawc0O" /><figcaption><em>Common Process of Data Visualization, </em><a href="https://eng.uber.com/keplergl/#:~:text=kepler.gl%20is%20a%20data%2Dagnostic%2C%20high%2Dperformance,large%2Dscale%20geolocation%20data%20sets.&amp;text=Showing%20geospatial%20data%20in%20a,glean%20insights%20from%20these%20visualizations."><em>Source</em></a></figcaption></figure><h3>Understanding Geospatial Data</h3><p>Geospatial data represent the information regarding the locations<strong> i.e. <em>both latitude, longitude, zip code, address, city. This dataset can be accumulated from GPS, geotagging, satellite imagery.</em></strong></p><h3>Types of Geospatial Data</h3><ul><li>Vector files</li><li>Raster files</li><li>Geographic Database</li><li>Web Files</li><li>Multi-Temporal</li></ul><h3>What is Kepler. gl?</h3><p><a href="https://kepler.gl/">Kepler. gl</a> is an open-source geo-analytics tool developed by some geniuses at Uber, for the visualization of geospatial data which can be helpful in getting trends and patterns hidden in the dataset. <strong><em>The dataset contains various geospatial information including latitude, longitude, zip or postal code, address, city, country, etc.</em></strong></p><p>It makes it easier to visualize a large set of geospatial data. You can visualize any kind of <strong><em>geospatial data i.e. road trips, flights, earthquakes, the population of a country or city, etc.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/0*Dzta8gXhjF48YAeE" /><figcaption><em>Visualization of NYC taxi trips using kepler. gl</em></figcaption></figure><p>In Kepler.gl data visualization will be done with a combination of different layers i.e. points, hexagons, arcs, paths, grid layers. At the same time, it offers both 2D and 3D visualization with different layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/0*0H1rLMoXCCgryZQO" /><figcaption><em>Layers in kepler. gl</em></figcaption></figure><p>As discussed above, there are many other methods to visualize the geospatial data, but the point is many of them are the time taken, and also some of them have hardware restrictions i.e. GPU as you need to use some software but this is not the case with kepler.gl as it’s a web-based application and you just need to import the dataset to visualize to the browser and by utilizing some filters and visualize the data with layers of your choice in fewer minutes only.</p><h3>Datasets</h3><p>If you are new to these tools and want to explore this, you can just make use of some of the available datasets in <a href="https://kepler.gl/demo">Kepler.gl</a>, by selecting one of your choices and then start playing with that on the map by applying different maps layers and filters, either in 2D or 3D mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AS3gRYeab4s-XSHa" /><figcaption><em>Available dataset on kepler.gl</em></figcaption></figure><p><strong>Some of the famous datasets available,</strong></p><ul><li>California Earthquakes</li><li>NYC Taxi trips</li><li>Travel Times From Uber Movement</li><li>San Francisco Street Tree Map</li><li>2017 Unemployment Rates for U.S. Counties.</li></ul><p>There are many others, you can choose any one of them and explore kepler.gl. Apart from this one can also import a dataset of their own either in CSV or GeoJson data or it can be URL to load data from some cloud.</p><h3>Getting Started with Kepler.gl</h3><p>In this blog, we will be utilizing the<strong> NYC Taxi Trip data</strong>, from one of the <a href="https://www.kaggle.com/c/nyc-taxi-trip-duration/data">Kaggle</a> competition. So the dataset is originally based on the <strong>2016 NYC Yellow Cab trip record data, where the user has to make the prediction of trip duration.</strong></p><p><strong>This dataset has different features, some of them are -</strong></p><ul><li>Pickup DateTime</li><li>Dropoff DateTime</li><li>Pickup latitude</li><li>Pickup longitude</li><li>Dropoff latitude</li><li>Dropoff longitude</li><li>Trip duration</li><li>Passenger count</li></ul><p>So, the first step is to load the dataset on the kepler.gl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/0*xuCwvgJNN-wvttfT" /><figcaption><em>Uploading data on kepler.gl</em></figcaption></figure><p>In Kepler.gl, there is an option to show the data table to display the dataset that is pre-uploaded there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sJqHeTFtt1TA5_zy" /><figcaption><em>NYC Taxi Trip data</em></figcaption></figure><h3>Interactions</h3><p>Navigate to the Interactions tab by moving the mouse in the Kepler.gl dashboard. <strong>There are different options to interact with the data plotted on the map, i.e. tooltips, brush, coordinates.</strong> You can choose any of that, but from tooltips and brush, only one can be chosen.</p><p><strong>Let’s have a look into each of them one by one;</strong></p><ul><li>Tooltips will display the information corresponding to the locations while hovering on the map. You can choose the information from the dataset of your choice. So whenever the user clicks on any location a pop up will show the information as seen below,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_0lqtmJfIjOeejLG" /><figcaption><em>Tooltip Interaction</em></figcaption></figure><ul><li>Brushes will highlight the region where you move and the rest of another area will get dark or you can say the other plotted locations will get hidden.</li><li>Coordinates will display the coordinates of all points where you put the cursor, as seen in the image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MTBcAbKQrMLK-V_-" /><figcaption>C<em>oordinates Interaction</em></figcaption></figure><h3>Base Map</h3><p>Kepler.gl provides different types of map styles to plot the data on, even you can add one of your choices as well. <strong>Some of the available map styles are,</strong></p><ul><li>Dark</li><li>Light</li><li>Muted Night</li><li>Muted Light</li><li>Satellite</li></ul><p><strong>Apart from different map styles, there are another option i.e. layers to show on the map and those are,</strong></p><ul><li>The label of cities and other localities on the map</li><li>Road</li><li>Border</li><li>Building</li><li>Water</li><li>Land</li><li>The 3D building, for this you can choose the color of your choice.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/0*rx2GMzLK2XscD9rl" /><figcaption><em>3D layer </em><a href="https://docs.kepler.gl/docs/user-guides/f-map-styles"><em>Source</em></a></figcaption></figure><h3>Layers</h3><p>Now it&#39;s time to plot the geospatial dataset on the map by utilizing different layers along with setting particular attributes. You can add multiple layers for visualizing your data by providing a suitable label for each layer.</p><p><strong>Some of the available layers are as follows,</strong></p><ul><li><strong>Point: </strong>It will plot points on the locations from the dataset like pickup points, dropoff points by giving their latitude and longitude.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oD_cA1ZhD7iVQRAxU7BRaw.png" /><figcaption><em>Point Layer</em></figcaption></figure><ul><li><strong>Arc: </strong>It will plot arcs between two points, which can be helpful in getting distance between two points like the distance between pickup and dropoff points for each passenger.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2OGfTXCRDaz1zyb3" /><figcaption>Arc Layer</figcaption></figure><ul><li><strong>Line: </strong>Another version of the arc layer but it will be a 2D version.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F341ljh9EeRGhA65" /><figcaption>Line Layer</figcaption></figure><ul><li><strong>Heatmap: </strong>It demonstrates the intensity at geographical points using different colors.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RoKsYhIFn8hzPXZ4" /><figcaption>Heatmap Layer</figcaption></figure><ul><li><strong>Grid: </strong>It is similar to heatmaps.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1sl1E2W8q1TWwNLA" /><figcaption>Grid Layer</figcaption></figure><ul><li><strong>H3: </strong>It plots data by making use of the H3 <a href="https://eng.uber.com/h3/">Hexagonal Hierarchical Spatial Index</a>. To plot H3 on the map you need hex id corresponding to each location which can be found using the python h3 module.</li></ul><p>Apart from setting layers, you can also choose particular layer attributes corresponding to each <strong>different layer i.e. color, stroked, height (in case of 3D), cluster size, etc.</strong></p><h3>Filters</h3><p>Using filters you can limit the data to be displayed on the map according to features from the dataset. For example, say you just want to display the points corresponding to trip pickup time or trip dropoff time, so just set the fields according to your choice.</p><p>As in the below figure you can see the filtration according to trip pickup time and trip dropoff time,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/0*dx_PlAxojJ3rN0Ww" /><figcaption><em>Filters in kepler.gl</em></figcaption></figure><p>For the filter having <strong>time-field values,</strong> you can use <strong>time playback video</strong> which will on play display points corresponding to that time from the scale as seen below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TYZQCGOrYsPC5BNT" /><figcaption><em>Time playback for time-field Filters</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gSqOYpTmafcJA_vv" /><figcaption><em>Layer Legend</em></figcaption></figure><p>Also, you can export the map from kepler.gl in different modes as <strong>an image, HTML page, JSON, or as URL.</strong></p><p>As in this blog, you have seen some of the basic functionalities of <strong>Kepler.gl toolbox</strong>, but there are many others available which you can explore on your own and also explore some other datasets available there and try with your own datasets too.</p><h3>Conclusion</h3><p>Data Visualization makes it easier for getting hidden patterns from the large dataset and as there are many ways to visualize the data as MS <strong>excel, tableau, python libraries</strong> but all of them have some restrictions in their use i.e time taken, hardware resources, and many more, which can be resolve by utilizing an open-source web-based toolbox by Uber Engineering i.e. kepler.gl. (Read another blog on <a href="https://www.analyticssteps.com/blogs/5-ways-ml-helps-uber-services-optimization"><strong>5 ways ML helps in Uber Services Optimization</strong></a><strong>)</strong></p><p>It helps in the visualization of geospatial data on the maps by plotting lat-long only in some minutes without utilizing any hardware resources as it runs on a web browser. It has different functionalities as covered in this blog, <strong><em>to visualize data like the point, arc, lines, heatmaps, 3D Grids, layers, etc</em></strong>. Even you can manage particular attributes for each of the layers. Any kind of geospatial data can be visualized here as in this blog we have covered <strong>NYC Taxi Trips Data</strong>.</p><p><em>Originally published at </em><a href="https://analyticssteps.com/blogs/visualizing-geospatial-data-keplergl"><em>https://analyticssteps.com</em></a><em> on July 9, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48053ba2668c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Telegram Chatbot with Dialogflow | Analytics Steps]]></title>
            <link>https://ripulagrawal.medium.com/building-telegram-chatbot-with-dialogflow-analytics-steps-a5502744e3dd?source=rss-69f978f61dc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5502744e3dd</guid>
            <category><![CDATA[dialogflow]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Ripul Agrawal]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-12-10T06:13:45.575Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*zk_oRYzsUW0i00hbDuYHyA.jpeg" /></figure><blockquote><strong>“Connecting Artificial Intelligence and Customer Service.”</strong></blockquote><h3>Introduction</h3><p>A chatbot is an <strong>AI-driven</strong> application for human interaction with the computer program either via <strong>text or text-to-speech</strong> mode. It’s developed to communicate the same way as human activity in their chat.</p><p>The chatbot is developed by the proper tuning and testing based on <strong>NLU</strong> to make it more adaptable by humans. You must have been using a chatbot in your life from seeking some online product to hunting for pizza at dominos online store.</p><p>Some of the common <a href="https://www.analyticssteps.com/blogs/learn-everything-about-machine-learning-chatbots"><strong>ML Chatbots</strong></a> include <strong>Google Assistant, Alexa, Siri, Cortona</strong>, etc. If you own <strong>windows, android phones, or iPhones,</strong> then you must be conscious of these apps.</p><p>If you look into the industrial application of chatbot, there are many as many firms who are using it to scale their business at a greater level, as it supports them in managing their relations with customers. Like in <strong>Facebook Messenger, Telegram, Slack, Skype, Twitter, etc</strong>. there are some inbuilt chatbots where users can interact in the same way as humans interact.</p><p>While surfing the internet, you might find on some websites an option of “<strong><em>Chat with us”</em></strong>, so when you click on that there will be a pop up with some program generated message, which is a chatbot developed by the company <strong>for customer support.</strong></p><p>For example, you can see the below image, of domino’s chat option,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*zWteCCkZna5lW4oD" /><figcaption><em>Domino’s Virtual assistant</em></figcaption></figure><p>The sole purpose of this blog is to develop a chatbot. As with the evolution of technology, there are so several tools available for chatbot development like it can be developed by writing programs in a different language utilizing available libraries and frameworks like <a href="https://rasa.com/"><strong>RASA</strong></a><strong>, </strong><a href="https://dialogflow.com/?authuser=2"><strong>Dialogflow</strong></a><strong>, </strong><a href="https://aws.amazon.com/lex/"><strong>Amazon Alex</strong></a><strong>.</strong></p><p>These frameworks let you integrate these chatbots with your own developed applications or some existing ones as <strong>telegram, Facebook messenger, Slack, Skype, etc.</strong></p><h4><strong>What is Dialogflow?</strong></h4><p>It’s a<strong> </strong><a href="https://www.analyticssteps.com/blogs/natural-language-processing-discussion-nlp-working-and-applications"><strong>natural language understanding</strong></a> platform, owned by Google Service. It can be used to develop conversational interfaces for websites, mobile applications. It also supports both text and text-to-speech features for interaction with the user.</p><p>As many companies are using their services by integrating with their business to scale their customer support. Dominos, <em>The Wall Street Journal, Ticketmaster, KLM Royal Dutch Airlines, etc. have used Dialogflow services in the integration of their customer support on their websites.</em></p><p>Apart from these, it can be further utilized to create bots for the existing platforms, including Google Assistant, Messenger, Telegram, Slack, Hangouts, Twitter, etc.</p><p>You can make your own chatbot on these for just fun among your buddies or expand your business via social media. Later you will witness one such application of bot for the<strong> </strong><a href="https://www.analyticssteps.com/"><strong>Analytics Steps</strong></a><strong>.</strong></p><p>From now onwards, you will start developing your first virtual agent using the Dialogflow console, that first log in to your google account, and move to the<strong> </strong><a href="https://dialogflow.com/"><strong>Dialogflow page</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*sk1xd_Y0I6FK6Lad" /><figcaption><em>Dialogflow home page</em></figcaption></figure><p>Now click on the Sign up for free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/0*5cCy3C8KOPRcCeuX" /><figcaption><em>Sign in with Google</em></figcaption></figure><p>Now feed your Google account details. Following this, there will be a pop-up asking for your location and time-zone, fill the valid details.</p><p>Next, create a new agent by pressing<strong> CREATE AGENT</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pQ7c6XradnAaGkjs" /><figcaption>Create Agent</figcaption></figure><p>Next set the agent name of your choice and that fit best of its soul purpose, also provide the language of the bot and the time zone and press create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TATvi1xUuIUdGDPU" /><figcaption><em>Fill up the agent details</em></figcaption></figure><p>Now before heading towards the development, you should be aware of some important terminology that will be further used in the development. These are as follows,</p><h3>1. Intents</h3><p>It refers to the group of texts/sentences from the user, that reflects the intention of the user while talking to the agent. And those sentences which form one intent will be used as <strong>Training Phrases to trigger that particular intent.</strong></p><p>There are some default intents already trained for intentions which everyone shares like greetings, welcome intents, apart from this, you can also add small talks as well with prebuilt responses.</p><p>In the default intents, user can store their own training phrases as per their convenience and responses simultaneously. Also, you can create your own intents i.e.<strong> customizable</strong>. Follow the below steps for the same,</p><h4><strong>Create Intent</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*Pw7QshafrfKQS1jO" /><figcaption>Creating Intent</figcaption></figure><h4>Set the name of the intent</h4><p>It should be relatable with the intents training phrases so it won’t be difficult in future if you need to make some changes or any updates,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fX8itCETv2p5wjhL" /><figcaption><em>Enter the name of Intent</em></figcaption></figure><h4>Add Training Phases</h4><p>Now add some training phases, use common words, by navigating to the training phases section. There will be different phrases for every intent and the user will use these or similar sentences while interacting with agents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V3nhQdgSheaRYnKX" /><figcaption><em>Add training phrases</em></figcaption></figure><h4>Add Responses</h4><p>Now it&#39;s time to set responses text which will be generated by the agent. There can be one or more responses at a time for a single user phrase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Edlq6j6N53HObAJc" /><figcaption>A<em>dd Responses</em></figcaption></figure><p>You can set custom responses as per the platform you want it to integrate.</p><p>In the above image, you can see there are two options to add responses;</p><ul><li>One is the <strong>default</strong>, it includes the text responses only,</li><li>The other one is <strong>Telegram</strong>, where you can add responses with images, and</li><li>Cards with multi-features as it provides buttons as well.</li></ul><p>At all, if you have used telegram bots then, you must be aware of those or refer to the below figure for the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1i3xiybMu7JQa98D" /><figcaption><em>Add responses for Telegram</em></figcaption></figure><p>As in the above image, you can see how to add buttons, images, hyperlinks in the response by the chatbot.</p><h4>Save and Train</h4><p>Now before moving to the next intent first press Save at the top to save all the phrases and responses,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*WCkkvWlTiopQOMQg" /><figcaption><em>Save the Changes</em></figcaption></figure><p>Wait till the training complete, as there will be a pop up at the bottom once training completes,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/0*PcLuJcWkllCXKcI6" /><figcaption><em>Training of Dialogflow</em></figcaption></figure><ul><li><strong>Test your agent</strong></li></ul><p>Once you are done with the creating of all the required intents, now its time to test your assistant, by just navigating to the Try it now section in the side panel,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*tSdW-lzua5dLqNsF" /><figcaption><em>Try it now</em></figcaption></figure><p>To test this out, you can also use speech-to-text as well.</p><p>In the below image you can see some examples of user-bot conversation with the Telegram generated responses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/0*PGg9KJdQ_i9yRYV4" /><figcaption><em>Chatbot Demo</em></figcaption></figure><p>From the above image, it is clear that there are images, clickable links in the form of buttons in the bot’s response.</p><p>Further, there are many more advancements that can be done in chatbot development i.e. use of <a href="https://cloud.google.com/dialogflow/docs/entities-overview">Entities</a>, <a href="https://cloud.google.com/dialogflow/docs/contexts-overview">Context</a>, <a href="https://cloud.google.com/dialogflow/docs/agents-small-talk">Small talk,</a> and <a href="https://cloud.google.com/dialogflow/docs/events-overview">Events</a>.</p><h3>2. Entities</h3><p>It is something that <a href="https://www.analyticssteps.com/blogs/text-analytics-and-models-natural-language-processing">natural language processing </a>(NLP) chatbots can pluck from phrases that users enter to turn around accurate recommendations and answers. It can be a time, place, person, item, number, etc.</p><h3>Integration with Telegram</h3><p>Now it’s time to integrate your first agent with a telegram and let your friends explore your bot.</p><ul><li>Open the telegram either on the phone or on a laptop and log in with your credentials.</li><li>Search for <a href="https://telegram.me/botfather.">@botfather</a> and type /start and it will show a list of commands,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*_WojsGVtq1jibu7D" /><figcaption><em>Commands by botfather</em></figcaption></figure><ul><li>As this is your first bot so type the /newbot command,</li><li>Then provide with the display name and username for your bot,</li><li>Got the access token, copy it, and save it for later use,</li><li>Navigate to the Dialogflow.</li><li>Move to Integrations tab,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/0*N9hJBL6eXYrL4D3-" /><figcaption><em>Integrate bot with other apps</em></figcaption></figure><p>Navigate to telegram and enable it as in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yJeLEPWSc1CsvXEX" /><figcaption><em>Enable the Telegram Integration</em></figcaption></figure><p>Paste the access token and press start, now your bot is ready to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/0*I3NWlIz24x6iRZVc" /><figcaption><em>Start the Telegram bot</em></figcaption></figure><p>Take a live demo of a chatbot on <a href="https://t.me/deep_404_bot">Telegram</a>.</p><p>You can integrate every chatbot with more apps like Facebook messenger, hangouts, Slack, Twitter, Skype, Google Assistant, and many more following the <a href="https://cloud.google.com/dialogflow/docs/integrations">official documentation</a>, with some limitations.</p><p>You can see the snap of integration of this with the <a href="https://bot.dialogflow.com/fcaa1cd5-f2a5-4f17-8a58-55c44ee079a8">web demo</a>. As it doesn’t support clickable hyperlinks and images, just only simple text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*jieguRSBFAovtjuS" /><figcaption>Web Demo</figcaption></figure><p>Further to make your bot more advanced as per your requirements follow <a href="https://cloud.google.com/dialogflow/docs">this</a>.</p><h3>Conclusion</h3><p>A chatbot is basically a computer program based on <a href="https://www.analyticssteps.com/blogs/7-natural-language-processing-techniques-extracting-information">Natural language understanding</a> which simulates the human-human interaction and makes it more smooth. <strong><em>Chatbots helps the business in expanding by improved customer services, increased customer engagement, etc.</em></strong></p><p>Many Rest APIs and frameworks are there for its development, one of them is Dialogflow that has been used here for the chatbot development as it is built on Google infrastructure and powered by <a href="https://developers.google.com/machine-learning/crash-course/ml-intro">Google Machine Learning</a>. Also, integrations with other services or applications are easier by this. It has been integrated with Telegram and the web demo.</p><p><em>Originally published at </em><a href="https://analyticssteps.com/blogs/building-telegram-chatbot-dialogflow"><em>https://analyticssteps.com</em></a><em> on June 22, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5502744e3dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Extract & Analyze YouTube Data using YouTube API? | Analytics Steps]]></title>
            <link>https://ripulagrawal.medium.com/how-to-extract-analyze-youtube-data-using-youtube-api-analytics-steps-632a410ca2cc?source=rss-69f978f61dc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/632a410ca2cc</guid>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ripul Agrawal]]></dc:creator>
            <pubDate>Thu, 04 Jun 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-06-09T05:49:27.156Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*MnU4iWRduQwtrUvWZyseGw.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>There are a lot of <a href="https://developers.google.com/apis-explorer">APIs available by google</a> with each of them having their application in various fields which makes the work easier while the development of mobile applications, website development and many more. One such API is the <a href="https://developers.google.com/youtube/v3/docs/">YouTube Data API v3</a> by google. It provides features including:</p><ul><li>Search for videos,</li><li>Retrieve information of videos from youtube either of channel or of particular video i.e. likes/dislikes, comments, etc.</li><li>Can start the youtube video directly from the application.</li></ul><p>As described above there are other applications of youtube API. Now you’re going to use one such application of Youtube API in the field of data science using Python.</p><h3>Getting Started with YouTube API</h3><h3>Activate API from Google console</h3><ul><li>Login to Google, if you don’t have an account create one and then login.</li><li>Visit the Google developer dashboard, create a new project from the top of the page as in below image, click “Select a project” from the top :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*1PGZMGFfR-Qc0QAn" /></figure><p><em>Google developer dashboard</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/0*M_88EnZqnCSOcu3V" /></figure><p><em>Select a project window</em></p><p>Once done you will be automatically redirected to the Google APIs dashboard.</p><ul><li>The next step is to activation of YouTube API, so for that navigate to the API &amp; Services from the side panel.</li><li>Then click on Enable API &amp; Services from the top of the page.</li><li>Search for Youtube and then select YouTube Data API v3.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LQSeHIKQA2K6W-Pp" /></figure><p><em>Select YouTube Data API v3 page</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/0*Egf-egKBbkoYRDkV" /></figure><p><em>API library that Enables the API</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/0*V6gwsMwf3cEQtIZC" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/0*fiChHOkglyH0oOHc" /></figure><p>API key created</p><h3>Extraction of Data from YouTube Channels</h3><p>Google collab provides all the features as provided by the Jupyter notebook on local machines. To store the data like datasets, images, videos to work on, it will be stored in the google drive the same way stored in a local machine.</p><p>Apart from that it also provides a free GPU with 12 Gb of RAM, but only supports Python 2.7 and Python 3.6.</p><p>After you run the below code in the cell it will mount the google drive with google collab, just after entering the authorization code got from the URL in the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iZSLFTW13r0Q4o1Z" /></figure><p>After this step, you can access any of the folder/files in the google drive from the google collab. Now just create a new folder in google drive for this project and run the below cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/0*JYdyqXsHH36ByxN1" /></figure><p>In the google collab, all the libraries are pre-built but while using in jupyter notebook or any other editor you have to install using pip command.</p><p>You will be using <a href="https://pypi.org/project/google-api-python-client/">google api python client</a> library to access youtube data and <a href="https://pandas.pydata.org/">pandas</a> library to apply exploratory data analysis on the extracted data.</p><p>To install these in windows run the below commands in the command prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rzvRQMuewt8Vo0Oq" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/0*jNa2oGH-9zY5r5oZ" /></figure><p>Now it’s time to start with the coding part to get insights from youtube data. So the first step towards this is to import the required libraries as mentioned above i.e. pandas, google client library,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/0*Sm3L85cQy5XdVP6i" /></figure><p>As explained above, you have generated the YouTube API key from the google console page. Now it’s time to use that API, so here set some parameters to be used in future steps including “youtube API key”, version of API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*1mAQI1KjwhuaYs00" /></figure><p>“YouTube Data API” provides so many functions to retrieve all kinds of data from the youtube of particular channels, videos or playlists, and many more. There are many resources available with this API to retrieve.</p><p>Apart from this, there are some other functionalities supported by this API to insert, update or delete on youtube, but for that, there is need of authorization while generating API. For now, you ‘re going to retrieve function only and for that, there is no need for authorization while generating API.</p><p>Some of the resources available to retrieve which are used in the following steps are:</p><p>Run the below cell to perform a youtube search by API calling and will save the data in the list.</p><p>You need to use <a href="https://developers.google.com/youtube/v3/docs/channels#snippet">snippets</a> property for youtube search as it contains the basic information of the channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*goE5KOjCBhj53SD_" /></figure><p>As from the output of the above cell, you can see the details of the all channels associated with the provided one. The output of search results stored in a list that will become a dictionary after execution.</p><p>All the basic information related to all the channels will be retrieved after the execution of the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vod8AQU8eMpVoHHh" /></figure><p>As seen from the output, it can be observed that there are four other channels which are associated with the given one, and including the other information for that channel like published date, channel ID, channel title, description, thumbnails, published time, etc. has been retrieved, all this information stored in the snippet.</p><p>Next, you will find the channel ID of the first in the list from the details above,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ebEEJ_hC6LppujOC" /></figure><p>Now find the <a href="https://developers.google.com/youtube/v3/docs/channels#statistics">statistics</a> of the channel by using channel ID where you get all the details of the total subscribers, views, videos uploaded, likes/dislikes, etc. of the channel.</p><p>For this step, you have to use of the channel resource by YouTube Datav3 API through passing channel IDS as a parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*PytYBKwK_E5j4LKX" /></figure><p>In this step, you will be using this property for channel resources to retrieve the information for the <a href="https://developers.google.com/youtube/v3/docs/channels#contentDetails">content</a> of the channel, including uploads- playlists, i.e. playlist id of uploads with which you can find all the uploaded videos on the channel since the creation of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U3ciIhsYpAGWwdzx" /></figure><p>Now, this is another resource that is used to retrieve the details of the<a href="https://developers.google.com/youtube/v3/docs/playlistItems"> playlist</a> uploads including all the uploaded videos. But also possess some limitations, i.e. at the one time, you can only get results of 50 videos maximum to get all the videos in a single run, and also using the next page token parameter that will be useful to retrieve the details of the next page.</p><p>So here, extracting all the videos with their details and saving it in a list as in below code,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ErENdZ2GSC76epr2" /></figure><p>From the below cell, you can see the data gets retrieved from the playlists as it contains the video ID and title.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O7bwq-xB5vEEsa3h" /></figure><p>Next, retrieve the video IDs, and in the next cell, the statistics of all the videos, including total likes/dislikes, comments, views on the video is presented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/0*aRt7gOx6iWFce7j3" /></figure><p>Now, retrieving the content details of all the videos and will store them in lists after then save it to disk as a csv file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/0*gtxtecPFDfNJP-2G" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*izVC76dWe9DXmEWk" /></figure><h3>Analyzing the YouTube extracted Data</h3><p>Till now, you have extracted the information of all the videos and saved them in one csv file using pandas. Now it’s time to get some more insights into the dataset.</p><p>For that you can make use of a python library -pandas, which provide various functions to get insights into the dataset like,</p><ul><li>Total number of videos,</li><li>Getting counts of unique values, i.e. using value_counts() method,</li><li>Most liked the video, disliked video, most commented video,</li><li>Most viewed the video,</li><li>Video with the maximum number of comments, likes, dislikes,</li><li>Maximum Number of likes, dislikes, comments.</li></ul><p>So at first read that csv file from the disk,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m9V016bVR2q23RnI" /></figure><p>Counts of unique values,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/0*0pswF4JYz_fZlrdX" /></figure><p>In the same way, unique values of comments and dislikes can be found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*smCTZsgemeaA78W1" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/0*Pqszd-OLyV65EQWA" /></figure><p>From the above cell, the description of the video shows the maximum number of likes, dislikes, comments, and views on the videos.</p><p>Using “value_counts” you can also get the number of videos corresponding to the likes, dislikes, comments, and views.</p><p>Now it’s time to get to know about the videos with the maximum number of likes, dislikes, comments, views. For that, first, you have to find the index of videos corresponding to the most liked, commented, disliked, and viewed the video,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*VmTiIy6CuK_zLSai" /></figure><p>After this, you can access the video information, i.e. video title, video Id, URL likes, comments, etc. using an index.</p><p><strong>Most liked video is;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k44gq5ipiLplZQ-T" /></figure><p><strong>Most Viewed Video is;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*4shLWKtIPqQhseAa" /></figure><p><strong>Most Commented video is;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*g1_guzKVfqJcWh7O" /></figure><p>For the complete code go through this <a href="https://github.com/ripulagrawal98/Analytic_Steps/tree/master/Extract-YouTube-ChannelData"><em>Github repository</em></a>. After this, there can be some more insights that can also be retrieved i.e. <a href="https://www.analyticssteps.com/blogs/learning-recurrent-neural-network-applications-and-its-role-sentiment-analysis"><em>sentiment analysis</em></a><em> </em>of the comments on videos can be done.</p><h3>Conclusion</h3><p>YouTube Data API is used to extract the information from the youtube channel using Python. Information includes the details corresponding to each video uploaded to that channel, i.e. channelId, number of videos, upload Id, the maximum number of likes, comments, views, total subscribers of the channel, published date, published time of the channel and videos as well.</p><p>All these steps will be followed by the generation of youtube API from the google console. After this analysis of the data extracted from the youtube, which is in csv format, will be done to get some interesting insights from the datasets as <em>“</em><strong><em>which video is the most liked video”, “video with maximum comments”, “video that is most viewed”.</em></strong></p><p><em>Originally published at </em><a href="https://www.analyticssteps.com/blogs/how-extract-analyze-youtube-data-using-youtube-api"><em>https://www.analyticssteps.com</em></a><em> on June 4, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=632a410ca2cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hand Gesture Classification using Deep Learning with Keras | Analytics Steps]]></title>
            <link>https://ripulagrawal.medium.com/hand-gesture-classification-using-deep-learning-with-keras-analytics-steps-be23cb668d98?source=rss-69f978f61dc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/be23cb668d98</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[hand-gesture]]></category>
            <dc:creator><![CDATA[Ripul Agrawal]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 00:00:00 GMT</pubDate>
            <atom:updated>2020-06-09T05:59:11.797Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*90ad5MK_NFgv6g7O-b350g.jpeg" /></figure><p>In recent years, <a href="https://www.analyticssteps.com/blogs/deep-learning-overview-practical-examples-popular-algorithms">Deep Learning</a> has become extremely popular, being the part of <a href="https://www.analyticssteps.com/blogs/introduction-machine-learning-supervised-and-unsupervised-learning">Machine Learning</a>, it has several applications in today’s world from classifying pictures and translating languages to putting together a self-driving car. Today all these tasks are being controlled by computers itself with none human intervention.</p><h3>Why Deep Learning?</h3><p>In this “ <strong>Big Data Era</strong>” of technology, we have a lot of data, which is not possible to process using traditional machine learning algorithms but possible with deep learning. It is obvious that if the data increase then deep learning will certainly increase the performance of the model. So Deep Learning is gaining much popularity due to its <a href="https://www.analyticssteps.com/blogs/what-does-googles-quantum-supremacy-describe">supremacy</a> in terms of accuracy once trained with a vast amount of data.</p><p>Generally, deep learning is a machine learning algorithm in which we feed an input X and use it to predict an output Y like given some labeled images of cats and dogs and then use deep learning to make predictions for the new unlabelled image of cat or dog. Now the question arises is how deep learning does this? So basically deep learning algorithm is made up of a neural network that takes a labeled dataset and tries to find out the pattern between input and its labels like the human brain does and then based on this experience it makes predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/0*K2GLcx9oaBU-p_T5" /></figure><p>It consists of an <strong>input layer</strong>, <strong>hidden layers,</strong> and <strong>output layer</strong> which is made up of a collection of neurons (or nodes). Input layers take an array of numbers(i.e. In case of images -pixel values), predictions at the output layer, while hidden layers are correlated with most of the computation. When there is a case of a large number of neural layers in any network then it will be deep neural network and then only deep learning comes into existence, thus deep neural network improves its ability to approximate additional complex functions.</p><h3>Types of Neural Network</h3><p>There exist various types of neural networks for different tasks like Dense Neural Networks, Convolutional Neural Networks, <a href="https://www.analyticssteps.com/blogs/learning-recurrent-neural-network-applications-and-its-role-sentiment-analysis">Recurrent Neural Networks</a>, and many more. Apart from these layers, there exist other layers which include Pooling Layers, Dropout Layers, Activation Functions, etc, all these added up to make the outcomes of model efficient.</p><h4>Convolutional Neural Network (CNN)</h4><p>CNN is mainly used for computer vision which includes image classification, face recognition, object detection, etc. CNN, for image classification, followed by neural layers and activation functions takes an input image and treats it as an array of pixels, processes it by finding patterns in the image, and then classifies it into certain categories or classes given in the problem statement. Image( the input layer) accepts will be either an array of RGB matrix ( 3 channels) or grayscale matrix (1 channel).</p><p><strong>CNN Architecture</strong></p><p>In deep learning, the CNN architecture will be composed of convolutional layers(filters), Pooling layers, fully connected layers (Dense), and then output layers.</p><p><strong>Convolutional Layer</strong></p><p>In this, the filter will be used to learn features from the image by convolving it with image, a mathematical operation, and then a new matrix will form i.e. with the learned features like edge detections, sharpen, or blurred image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QYDTm0DkDEvv-5ob" /></figure><p><em>Matrix visualization in a convolutional neural network</em></p><p><strong>Pooling Layer</strong></p><p>This layer would be used to perform downsampling operation on the input of this layer so that the input image will be compressed i.e. from a more detailed image to a less detailed image with more information. It can be of different types:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*laMNzAV9SDIHhu0w" /></figure><p><em>Pooling layer in CNN architecture</em></p><p>Max Pooling takes the largest element from the rectified feature map and Sum Pooling takes the sum of all elements in the feature map.</p><p><strong>Fully Connected Layer</strong></p><p>At this layer, just after the CNN network followed by pooling, the matrix will be flattened before feeding to Fully Connected Layer like a <a href="https://www.analyticssteps.com/blogs/neural-network-using-keras-functional-api-overview-structure-and-its-applications">neural network</a>. Then at the final layer, there will be activation function softmax or sigmoid to classify the output with the no of neurons in the final layer equals to no of classes in the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*4TQfVGPiDkMw0v4r" /></figure><p><em>The thread of fully connected layer between input and output data</em></p><p><strong>Activation Function</strong></p><p>It is a nonlinear layer put at the end of or in between neural networks which then decide the output of that node. Available <a href="https://www.analyticssteps.com/blogs/7-types-activation-functions-neural-network">activation functions</a> are: <a href="https://www.analyticssteps.com/blogs/introduction-logistic-regression-sigmoid-function-code-explanation">Sigmoid</a>, ReLU, Leaky ReLU, Softmax etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*X-iwcWb8HFnAROXR" /></figure><p><em>List of various Activation Function</em></p><h4>Hand Gesture Classification using Python Code</h4><p>In the Hand Gesture Classification, we used a dataset that contains images of different hand gestures, such as a fist, palm, showing the thumb, and others which can be further useful to show counts from 1 to 5 with these hand gestures.</p><p>There are many algorithms in machine learning for classification out of which we’ll be using Deep learning with the help of <a href="https://www.analyticssteps.com/blogs/convolutional-neural-network-cnn-graphical-visualization-code-explanation">Convolution Neural Network (CNN)</a> as discussed above, with the help of<a href="https://keras.io/"> Keras</a> ( an open-source neural network library written in Python). Keras is easy and fast and also provides support for CNN and runs seamlessly on both CPU and GPU.</p><p>Technologies Used:</p><p><strong>Import all the required libraries</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/0*aZptvLMWTvlPrumT" /></figure><p><strong>Loading the dataset</strong></p><p>We have two datasets one is the training dataset and the other is the test dataset. Training dataset containing 1080 images and test dataset containing 120 images with 6 labels to classify i.e. 0 to 5. Each image will be 64x64 pixels.</p><p>The dataset has been stored in the h5py format. The h5py package is a Pythonic interface for the HDF5 binary data format. With the help of HDF5, thousands of datasets can be stored in a single file. They support standard modes like r/w/a, so we’ll load our dataset which contains images in r mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/0*Wx3IEA0qiYd7zcO7" /></figure><p>After loading the dataset next step will be to get the image pixel’s values in to set of arrays and labels as in different array for both training and test dataset as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*SLYWpNZyW23hS7vE" /></figure><p>Normalization of dataset Pixel values of the images will be from 0 to 255, so we’ll normalize the dataset by dividing pixel values by 255.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/0*f0a54uIGmt3JjZLt" /></figure><p>converting class values to binary class metric for training and test set</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/0*fb22AZm_1HOOigDE" /></figure><p><strong>Create CNN architecture using Keras</strong></p><p><a href="https://keras.io/getting-started/sequential-model-guide/"><strong>Sequential</strong></a><strong>:</strong> It is a linear stack of layers, used for creating deep learning models like the instance of a Sequential model is created and layers will then be added to it piecewise.</p><p><a href="https://keras.io/layers/convolutional/"><strong>Conv2D</strong></a><strong>: </strong>This 2D convolution layer creates a kernel a filter that is convolved with the input layer (at the initial level with the image) and then produces a new array(tensor). There are some arguments we have to add while creating this layer are: filters (number of output filters in the convolution), kernel_size(dimension of the kernel), strides(an integer or tuple specifying the strides of the convolution along with height and width).</p><p><a href="https://keras.io/layers/pooling/"><strong>MaxPooling2D</strong></a><strong>:</strong> This layer performs downsampling operation on the input of this layer which means it will compress the input image with more details to less detailed images as some features (like boundaries) have already identified, Conv2D it also accepts some arguments: pool_size(size of max pooling windows), strides, padding, etc.</p><p>This flattens layer which flattens the inputs, will be added after the series of convolutional and pooling layers and followed by a fully connected <a href="https://keras.io/layers/core/">dense</a> layer which results in an N-dimensional vector, where N is the number of classes from which the model selects the desired class.</p><p><a href="https://keras.io/layers/core/"><strong>Dropout</strong></a><strong>: </strong>It Applies Dropout to the input. This is a technique used to prevent the model from overfitting by making weights of some redundant neurons in a particular layer equal to zero.</p><p>Import all the modules from Keras to create a CNN architecture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*nXdchxxqbeW8WNYb" /></figure><p>Creates a model and adds layers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/0*SmdVTYyTROiyOKdy" /></figure><p>As seen from code, we have created a neural network with 2 convolution layer followed by max pool layer with activation function “relu” in both layer, where the first layer has 8 filters of size (4,4) and size of the max pool is (8,8) while the second layer has 16 filters of size (2,2) and size of the max pool is (4,4), padding will be “same” in each layer. After the convolution layer, we’ll flatten the output of the convolution layer and then will add another fully connected layer(Dense) with 6 nodes in that because in our output we have 6 classes to predict.</p><p><a href="https://keras.io/models/sequential/"><strong>Configures the model for training</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/0*CsgjZRq-QE-d59tg" /></figure><p><strong>Training of Model</strong></p><p>We’ll train our model by feeding the labeled dataset (as loaded above) i.e. training dataset will be the training dataset and testing dataset will behave as the validation dataset. With the help of Keras, it will be easy to train our model using the <a href="https://keras.io/models/sequential/">fit</a> method and during the training, it will run off 140 iterations to update its weights and bias of the neural network with the help of optimizers,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/0*-rqqO6NkWPzVGyZ9" /></figure><p><strong>Testing of the model</strong></p><p>After the training of the model, we’ll test the model that how accurate it will be on the new dataset i.e. test dataset using an <a href="https://keras.io/models/sequential/">evaluation</a> method which returns loss value &amp; accuracy value for the model in test mode, its input will be input test images and target variables i.e. x_test, y_test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*PzYpQwBF1cels6qr" /></figure><p>Then we’ll predict the output for the input samples i.e. test datasets using <a href="https://keras.io/models/sequential/">predict</a> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*vfAj25iu3OCle8VF" /></figure><h3>Conclusion</h3><p>Hand Gesture dataset has been classified using Convolution Neural Network with the help of Keras, an open-sourced neural-network library written in Python. Keras is preferred because it increases the computational power of deep neural network architecture by providing some functions that are needed for optimization like backpropagation, gradient descent, etc, and reduce the computation time. Keras has <a href="https://keras.io/applications/">applications</a> that provide some pre-trained models along with pre-trained weights which can be directly used for prediction, feature extraction, and fine-tuning. For more updates and blogs on Analytics, Do read <a href="https://www.analyticssteps.com/"><strong>Analytics Steps</strong></a>.</p><p><em>Originally published at </em><a href="https://www.analyticssteps.com/blogs/hand-gesture-classification-using-deep-learning-keras"><em>https://www.analyticssteps.com</em></a><em> on December 17, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be23cb668d98" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>