<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashwin Vinod</title>
    <description>The latest articles on DEV Community by Ashwin Vinod (@ashwin_vinod).</description>
    <link>https://dev.to/ashwin_vinod</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F224057%2F1964f28f-c7fa-45d4-a4cf-ab7a8cdcf2af.jpeg</url>
      <title>DEV Community: Ashwin Vinod</title>
      <link>https://dev.to/ashwin_vinod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashwin_vinod"/>
    <language>en</language>
    <item>
      <title>Object detection under 20 lines</title>
      <dc:creator>Ashwin Vinod</dc:creator>
      <pubDate>Thu, 05 Nov 2020 18:59:33 +0000</pubDate>
      <link>https://dev.to/ashwin_vinod/object-detection-under-50-lines-9ln</link>
      <guid>https://dev.to/ashwin_vinod/object-detection-under-50-lines-9ln</guid>
      <description>&lt;p&gt;So you have been fascinated by what Computer Vision can do. Most of the people consider this hard and full of math. This also causes many people lose their interest in the subject. So I have set out to make Computer Vision easier than ever before.&lt;br&gt;
Well, I present You Visionlib. A library which makes Computer Vision as simple as possible.&lt;br&gt;
You can check out the GitHub page &lt;a href="https://github.com/ashwinvin/visionlib" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  So lets get started
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download and install &lt;a href="https://python.org" rel="noopener noreferrer"&gt;Python3&lt;/a&gt;from the official website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install Visionlib and its dependencies&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This should install the Dependencies. Now install Visionlib by&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Great, now that you have installed Visionlib, its time to write some code.&lt;/p&gt;

&lt;h2&gt;
  
  
  CODING TIME
&lt;/h2&gt;

&lt;p&gt;Create a file and paste this code. Save the code with any name but it should end with ‘.py’&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F1%2A7UXnllRtJUaUcMvOx2pm1g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F1%2A7UXnllRtJUaUcMvOx2pm1g.jpeg" alt="Before Detection"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F1%2ATC-nx5o6fpXgTz-G8E6cSQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F1%2ATC-nx5o6fpXgTz-G8E6cSQ.jpeg" alt="After Detection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Only &lt;strong&gt;20&lt;/strong&gt; lines of code is required for Object Detection. Never Been This Easy Right ?&lt;/p&gt;

&lt;p&gt;Now let me explain what is actually happening. Lets break down the code into little pieces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;visionlib.object.detection.detection&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ODetection&lt;/span&gt;                      
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;                       
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The first line import’s the visionlib library’s object detection module. The second line import’s argparse which parses the command-line options.Lastly the third line import’s the opencv which is an image processing library.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;detector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ODetection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;                      
&lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;                       
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;img_path&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Path to image&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                       
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The model to use for detecting&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                       
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--enable-gpu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Set to true to enable GPU support&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;enable_gpu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This snippet of code initializes the command-line argument parser aka argparse.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;detector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ODetection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;detector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_detector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is where everything is initialized. The first line initializes the class. The second sets the detector to use. Still remember argparse, we can set the detector when start it through command-line.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;conf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;detector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;detect_objects&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enable_gpu&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;enable_gpu&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is where the magic happens . This is the line where object detection happens. We pass in the image and a bool specifying whether we want &lt;br&gt;
to use GPU. After detection we get three lists , the bounding box, the detected class for the object and the confidence for the object.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dimg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;detector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw_bbox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This line does the hard work of drawing the bounding boxes ,the labels and the confidence. After drawing we get the image with drawing.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;imshow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Object Detection using Visionlib&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dimg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                       
&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitkey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Don’t we want display our detected images. Of course we do want to display the image. These two lines help us display the image.&lt;/p&gt;

&lt;p&gt;This is just the beginning. With Visionlib, we can do more than object detection. It can also do Face Tracking, Facial Keypoint Detection, Gender Prediction and Object Classification. As the time passes, it would try its best to become a general purpose Computer Vision Library.For more examples and documentation visit the Github Page&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ashwinvin" rel="noopener noreferrer"&gt;
        ashwinvin
      &lt;/a&gt; / &lt;a href="https://github.com/ashwinvin/Visionlib" rel="noopener noreferrer"&gt;
        Visionlib
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A simple, easy to use, feature rich, customizable cv library
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/ashwinvin/Visionlibdocs/images/logo(1).jpg"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fashwinvin%2FVisionlibdocs%2Fimages%2Flogo%281%29.jpg" alt="logo"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Visionlib&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/ashwinvin/Visionlib/workflows/Upload%20Python%20Package/badge.svg"&gt;&lt;img src="https://github.com/ashwinvin/Visionlib/workflows/Upload%20Python%20Package/badge.svg" alt="Upload Python Package"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A simple high level API made for assisting in CV-related projects.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Track faces using&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MTCNN module&lt;/li&gt;
&lt;li&gt;Dlib hog Based detector&lt;/li&gt;
&lt;li&gt;Opencv Haar cascades&lt;/li&gt;
&lt;li&gt;Dnn based model&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Predict Gender&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Detect Objects&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yolo v3&lt;/li&gt;
&lt;li&gt;tiny-yolo&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Classify Images&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VGG 16&lt;/li&gt;
&lt;li&gt;Inception v3&lt;/li&gt;
&lt;li&gt;Xception&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Detect Facial Keypoints&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MTCNN&lt;/li&gt;
&lt;li&gt;Dlib 68 point shape detector&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;TODO&lt;/h3&gt;
&lt;/div&gt;

&lt;ul class="contains-task-list"&gt;
&lt;li class="task-list-item"&gt;
 Find a Pre-Trained model for pose estimation and implement.&lt;/li&gt;
&lt;li class="task-list-item"&gt;
 Implement a motion detector preferably using Opencv&lt;/li&gt;
&lt;li class="task-list-item"&gt;
  Fix the unnecessary loading for TensorFlow&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Installation&lt;/h3&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Windows compatibility is not tested&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;Dependencies&lt;/h4&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get install build-essential cmake pkg-config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get install libx11-dev libatlas-base-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get install libgtk-3-dev libboost-python-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should install Dependencies required by dlib.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install visionlib&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will install visionlib.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h5 class="heading-element"&gt;Optional&lt;/h5&gt;

&lt;/div&gt;

&lt;p&gt;If You want to install from source
&lt;code&gt;git clone https://github.com/ashwinvin/Visionlib.git&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;cd visionlib&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;pip install .&lt;/code&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Face Detection&lt;/h3&gt;

&lt;/div&gt;
&lt;p&gt;Detecting face in an image is easy . This will return the image with bounding box and box coordinates.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;from&lt;/code&gt;…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/ashwinvin/Visionlib" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Have any doubts or suggestions.. Join our &lt;a href="https://discord.gg/bY9Ehrv" rel="noopener noreferrer"&gt;discord server&lt;/a&gt; to talk with us&lt;/p&gt;

&lt;p&gt;Do share your comments down below!!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>python</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
