<?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: KANIKSHA SHARMA</title>
    <description>The latest articles on DEV Community by KANIKSHA SHARMA (@kanikshas4).</description>
    <link>https://dev.to/kanikshas4</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%2F891062%2Fcbfa9de7-0512-464f-87e9-6caa54ddae1c.jpeg</url>
      <title>DEV Community: KANIKSHA SHARMA</title>
      <link>https://dev.to/kanikshas4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kanikshas4"/>
    <language>en</language>
    <item>
      <title>Surrounding Light Intensity Detection Computer Vision App with streamlit &amp; OpenCV</title>
      <dc:creator>KANIKSHA SHARMA</dc:creator>
      <pubDate>Fri, 15 Jul 2022 21:37:03 +0000</pubDate>
      <link>https://dev.to/kanikshas4/surrounding-light-intensity-detection-computer-vision-app-with-streamlit-opencv-1nnj</link>
      <guid>https://dev.to/kanikshas4/surrounding-light-intensity-detection-computer-vision-app-with-streamlit-opencv-1nnj</guid>
      <description></description>
      <category>computervision</category>
      <category>streamlit</category>
      <category>opencv</category>
    </item>
    <item>
      <title>Let's Build An Easy Computer Vision Web App with Streamlit &amp; Streamlit-webrtc</title>
      <dc:creator>KANIKSHA SHARMA</dc:creator>
      <pubDate>Wed, 13 Jul 2022 22:34:44 +0000</pubDate>
      <link>https://dev.to/kanikshas4/lets-build-an-easy-computer-vision-web-app-with-streamlit-streamlit-webrtc-4fp0</link>
      <guid>https://dev.to/kanikshas4/lets-build-an-easy-computer-vision-web-app-with-streamlit-streamlit-webrtc-4fp0</guid>
      <description>&lt;h2&gt;
  
  
  Streamlit
&lt;/h2&gt;

&lt;p&gt;It is an amazing Open-Source framework to create web apps with python with few lines of code. So, now instead of creating HTML pages and Css sheets for designing web apps, we have a tool Streamlit(framework). Which can ease all this work and can compile all the designing and the app functionality in one single piece of code script. So, let's dive deep to learn the functionalities of this tool. You can know more about this amazing framework by referring to this link - &lt;a href="https://docs.streamlit.io/"&gt;Streamlit documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Before moving ahead you need to install following packages.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;streamlit&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% pip install streamlit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;opencv-python&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% pip install opencv-python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;streamlit-webrtc&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% pip install streamlit-webrtc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;av&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% pip install av
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  You're ready to build the app 🥳
&lt;/h2&gt;

&lt;p&gt;We will first print the "Hello world" to launch our app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps To Follow&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create an empty folder on your system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Move to that directory.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% cd /usr/include directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create an empty &lt;code&gt;app.py&lt;/code&gt; file in the same directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a Virtual Environment in the same directory.(optional)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% python -m venv venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Activate the Virtual Environment.(macOS)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% . /venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Move to empty &lt;code&gt;app.py&lt;/code&gt; file and write the following code and save the file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import streamlit as st
st.write("Hello, world")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run the following command in the same directory to run the app.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% streamlit run app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will boot up the streamlit server and the app will open in your browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  OUTPUT
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TdC7Ppiz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/og41fki19w5fifgt3aj8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TdC7Ppiz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/og41fki19w5fifgt3aj8.png" alt="output" width="880" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Streamlit_Webrtc
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;streamlit_webrtc&lt;/code&gt; Package is for Real-time Video/Audio Streaming. &lt;/p&gt;

&lt;p&gt;Updating the &lt;code&gt;app.py&lt;/code&gt; file to add the title and Video streaming component &lt;code&gt;streamlit_webrtc&lt;/code&gt; to it. We will remove the "Hello World" from our app as that was just an example to show the functioning of our app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Importing all the pacakges required.&lt;/li&gt;
&lt;li&gt;Adding a title to the app- "Computer Vision Streamlit application"&lt;/li&gt;
&lt;li&gt;calling the &lt;code&gt;webrtc_streamer()&lt;/code&gt; class imported from &lt;code&gt;streamlit_webrtc&lt;/code&gt; for real-time video streaming.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import streamlit as st
from streamlit_webrtc import webrtc_streamer
st.title("Computer Vision Streamlit application")
webrtc_streamer(key="demo")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OUTPUT
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m33ZcnXM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qplih41rrb1xtvh6ayyt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m33ZcnXM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qplih41rrb1xtvh6ayyt.png" alt="OUTPUT1" width="880" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you will click on the "start" button, it will ask for a video and audio capturing permission. After you grant the permission it will show you live video streaming.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's add Video Processing component to the app using OpenCV.
&lt;/h2&gt;

&lt;p&gt;We will update the &lt;code&gt;app.py&lt;/code&gt; file to apply a filter using &lt;code&gt;OpenCV&lt;/code&gt; on the video captured. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this tutorial we will use an Image processing filter of &lt;code&gt;OpenCV&lt;/code&gt; Library called canny edge detection filter. &lt;br&gt;
You are free to use any other filter as per your choice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We will first create a class name &lt;code&gt;VideoProcessor&lt;/code&gt; and define a function inside it, name &lt;code&gt;recv()&lt;/code&gt;. This will be a callback function which will receive an input from the frame and return an output to the frame. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;webrtc_streamer()&lt;/code&gt; can take a class object with &lt;code&gt;.recv()&lt;/code&gt; function as its &lt;code&gt;video_processor_factory&lt;/code&gt; argument.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The argument of &lt;code&gt;.recv()&lt;/code&gt; is the image frame from the webcam input video captured. we will convert it into a NumPy array with &lt;code&gt;frame.to_ndarray()&lt;/code&gt; command.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;-The return is from &lt;code&gt;.recv()&lt;/code&gt; which will display on the screen with this command &lt;code&gt;av.VideoFrame.from_ndarray(image, format="bgr24")&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upadte the &lt;code&gt;app.py&lt;/code&gt; file with following code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import av
import cv2
import streamlit as st
from streamlit_webrtc import webrtc_streamer
st.title("Computer Vision Streamlit application")
class VideoProcessor:
    def recv(self, frame):
        image = frame.to_ndarray(format="bgr24")

        image = cv2.cvtColor(cv2.Canny(image, 100, 200), cv2.COLOR_GRAY2BGR)

        return av.VideoFrame.from_ndarray(image, format="bgr24")
webrtc_streamer(key="demo", video_processor_factory=VideoProcessor)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OUTPUT
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8dDaEYBW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmb9tzp14naiabud33g7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8dDaEYBW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmb9tzp14naiabud33g7.png" alt="output" width="880" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  wohhooo!🥳 We are ready with this app
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;For deploying the app on Streamlit Cloud check out this &lt;a href="https://docs.streamlit.io/streamlit-cloud/get-started/deploy-an-app"&gt;Documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>streamlit</category>
      <category>computervision</category>
    </item>
  </channel>
</rss>
