<?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 Rohan Kishore on Medium]]></title>
        <description><![CDATA[Stories by Rohan Kishore on Medium]]></description>
        <link>https://medium.com/@rohankishor?source=rss-13a6b35314ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fFDZ1-y7GNQTOLr-tXkKBg.jpeg</url>
            <title>Stories by Rohan Kishore on Medium</title>
            <link>https://medium.com/@rohankishor?source=rss-13a6b35314ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:39:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohankishor/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[iPad Air 5: Should you upgrade?]]></title>
            <link>https://medium.com/@rohankishor/ipad-air-5-should-you-upgrade-9a18454ffef7?source=rss-13a6b35314ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a18454ffef7</guid>
            <category><![CDATA[ipad-pro]]></category>
            <category><![CDATA[ipad]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[m1-chip]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Rohan Kishore]]></dc:creator>
            <pubDate>Thu, 24 Mar 2022 06:07:48 GMT</pubDate>
            <atom:updated>2022-03-24T06:08:17.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJr6g9wBBcjZUkzibpMmIw.png" /><figcaption>Credits: Apple</figcaption></figure><p>So Apple has just released their brand new iPad Air after two years. But the question is, should you <strong><em>UPGRADE</em></strong>?</p><p>At first sight, the new iPad air was a dream come true for Apple fans. But here’s the catch. Now both iPad pro and air have the same monstrous M1 chip (8c 8c), making it as powerful as a 13inch Macbook Pro (2020). The price difference between the air and pro is not that big, at least here in India. You can get a brand new iPad air from 55k and an iPad pro from 65k (or even less if you pay with specific bank cards). So, which one is a worthy upgrade? Let’s find out! I’ll try to be as straightforward as I can.</p><p>If you’re coming from a 3 or 4yr old tablet, both will be fast for you. But the major difference between both is the 120hz refresh rate or so-called ProMotion, that&#39;s exclusively available for iPad pro. It’s smooth af. And because of that, your experience will be even more smooth and fluid and you can get up to 120fps in supported games or apps, compared to only 60 on the iPad air.</p><p>The other factors that make the pro, even more PRO are:<br>* A ultrawide camera<br>* LiDar scanner (helps for better depth mapping and Augmented reality)<br>* Better display (better colour gamut and promotion)<br>* Less latency for apple pencil (because of higher refresh rate)<br>* A better 5G with mmWave support<br>* Slightly thinner bezels<br>* Face ID (Air has Touch ID embedded on the power button)</p><p>Common factors between both the Air and Pro are:<br>* Same chipset (M1) (8c 8c)<br>* Same front camera with Center Stage (UW)<br>* Support for Apple Pencil 2nd gen<br>* Support for Magic keyboard and smart folio<br>* Same wifi and Bluetooth antennae</p><p>According to me, just save some more money and go for the pro. You deserve the 120hz experience. If your budget is tight and you need a tablet urgently, then go for the Air. You’ll still get updates for like 7 years. And if you’re currently using an iPad Pro 2018 or iPad air 4th gen (with a14 bionic), then just don&#39;t upgrade to the new air. The only difference you get is the new chipset and new front cam. If you want to upgrade so badly, then trade in your current air and buy yourself a pro. That’ll be a better deal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a18454ffef7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to NumPy for Beginners]]></title>
            <link>https://python.plainenglish.io/an-introduction-to-numpy-for-beginners-93db7b55a778?source=rss-13a6b35314ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/93db7b55a778</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rohan Kishore]]></dc:creator>
            <pubDate>Wed, 23 Mar 2022 11:02:37 GMT</pubDate>
            <atom:updated>2022-03-23T11:02:37.418Z</atom:updated>
            <content:encoded><![CDATA[<h4>NumPy Basics in 5 minutes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0zAyWFL0WAIUq0LCCaTWw.png" /></figure><p>If there is a package that has to be used for any scientific calculations or computing, then the credit goes to none other than our hero, <strong>NumPy!</strong></p><p><strong>Python was already efficient. So why NumPy library was created?</strong></p><ul><li>NumPy Array is an alternative to Python List</li><li>Unlike Python Arrays, NumPy arrays can perform calculations on entire arrays</li><li>It serves as ground base essential for other packages example: sci-kit-learn</li><li>Many functionalities are available in NumPy with more convenient usage</li><li>Obviously, the list isn’t complete without mentioning that they’re efficient and fast</li></ul><p><strong>Adding to that, NumPy is also preferred because it is a</strong></p><ul><li>a powerful N-dimensional array object</li><li>sophisticated (broadcasting) functions</li><li>tools for integrating C/C++ and Fortran code</li><li>useful linear algebra, Fourier transform, and random number capabilities</li></ul><p>Apart from its seamlessly awesome functionality on scientific computations, NumPy handles multi-dimensional data efficiently especially when it comes to generic data. This thrusts NumPy to integrate with various databases.</p><h3>Let&#39;s get started with NumPy!</h3><p>We’re going to be using arrays or matrices extensively so to make using them simpler, let&#39;s use NumPy. We need to import the library:</p><pre><strong>In[]: import numpy as np</strong><br><em># np is just an alias, you don&#39;t want to type numpy all the time</em></pre><p><strong>1. Numpy arrays can be created by converting from a list:</strong></p><pre>In[]: my_list = [1,2,3,4]<br>In[]: my_array = np.array(my_list)<br>In[]: my_array<strong>Out[]: array([1, 2, 3, 4])</strong></pre><p><strong>2. You can add up one or more lists to form a multi-dimensional NumPy array:</strong></p><pre>In[]: my_list1 = [1, 2, 3, 4]<br>In[]: my_list2 = [11, 22, 33, 44]<br>In[]: my_list = [my_list1, my_list2]<br>In[]: my_array = np.array(my_list)<br>In[]: my_array<strong>Out[]:</strong> <strong>array([[ 1,  2,  3,  4],<br>       [11, 22, 33, 44]])</strong></pre><p><strong>3. Length of NumPy array (Matrix) — [Shape Function]:</strong></p><pre>In[]: my_array.shape<strong>Out[]: (2, 4)</strong></pre><p><strong>4. Data Type of NumPy array:</strong></p><pre>In[]: my_array.dtype<strong>Out[]: dtype(&#39;int32&#39;)</strong></pre><p><strong>5. Creating a NumPy array of zeros:</strong></p><pre>In[]: np.zeros(5)<strong>Out[]: array([0., 0., 0., 0., 0.])<br></strong><em># notice these are floating type</em></pre><p><strong>6. Creating NumPy array of Ones:</strong></p><pre>In[]: np.ones([5, 5])<strong>Out[]: array([[1., 1., 1., 1., 1.],<br>       [1., 1., 1., 1., 1.],<br>       [1., 1., 1., 1., 1.],<br>       [1., 1., 1., 1., 1.],<br>       [1., 1., 1., 1., 1.]])</strong></pre><p><strong>7. Creating an identity Matrix:</strong></p><pre>In[]: np.eye(5)<strong>Out[]: array([[1., 0., 0., 0., 0.],<br>       [0., 1., 0., 0., 0.],<br>       [0., 0., 1., 0., 0.],<br>       [0., 0., 0., 1., 0.],<br>       [0., 0., 0., 0., 1.]])</strong></pre><p><strong>8. How different Python list is from NumPy arrays?</strong></p><pre>In[]: height = [1.73, 1.68, 1.71]<br>In[]: height<br><strong>Out[]: [1.73, 1.68, 1.71]</strong>In[]: weight = [65.4, 59.2, 63.6]<br>In[]: weight<br><strong>Out[]: [65.4, 59.2, 63.6]</strong><em># Calculating BMI for the present</em><br>In[]: weight / height ** 2<strong>TypeError: unsupported operand type(s) for ** &#39;list&#39; and &#39;int&#39;</strong></pre><p>Now, this happened because python has no idea how to do calculations or computing on the lists.</p><p>You can calculate BMI for each person separately. But that is terribly inefficient. An elegant solution is to use NumPy<em>(‘</em><strong><em>num</em></strong><em>’-</em>eric<em> ‘</em><strong><em>py</em></strong><em>’-</em>thon<em>).</em></p><pre>In[]: np_height = np.array(height)<br>In[]: np_height<br><strong>Out[]: array([1.73, 1.68, 1.71])</strong>In[]: np_weight = np.array(weight)<br>In[]: np_weight<br><strong>Out[]: array([65.4, 59.2, 63.6])</strong>In[]: BMI = np_height / np_weight ** 2<br>In[]: BMI<br><strong>Out[]: array([21.85171573, 20.97505669, 21.75028214])</strong></pre><p>Another proof that Python list differs from NumPy array is about how they perform a mathematical operation between itself:</p><pre><strong># Python List</strong><br>In[]: python_list = [1, 2, 3]<br>In[]: python_list + python_list<strong>Out[]: [1, 2, 3, 1, 2, 3] </strong><em>#appends</em><strong># Numpy Array<br></strong>In[]: numpy_array = np.array([1, 2, 3])<br>In[]: numpy_array + numpy_array<strong>Out[]: array([2, 4, 6]) </strong><em>#performs addition</em></pre><p><strong>9. NumPy Sub-Setting:</strong></p><pre># Let us recall the BMI we calculated aboveIn[]: BMI<br><strong>Out[]: array([21.85171573, 20.97505669, 21.75028214])</strong>In[]: BMI[1]<br><strong>Out[]: 20.97505668934241</strong>In[]: BMI &gt; 21.8<br><strong>Out[]: array([ True, False, False])</strong>In[]: BMI[BMI &gt; 21.8]<br><strong>Out[]: array([21.85171573])</strong></pre><p><strong>Psst! Here is a way to make a NumPy array </strong><em>(commonly used)</em></p><pre><strong>Syntax: np.arange([start], [stop], [step_size])<br></strong># return evenly spaced values within a given intervalIn[]: np.arange(5)<br><strong>Out[]: array([0, 1, 2, 3, 4])</strong>In[]: np.arange(5, 50, 2)<br><strong>Out[]: array([ 5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49])</strong></pre><p><strong>10. Indexing NumPy Arrays</strong></p><pre>In[]: arr = np.arange(0, 11)<br>In[]: arr<br><strong>Out[]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10])</strong>In[]: arr[8]<br><strong>Out[]: 8<em># How to fetch values from N</em></strong><em>th</em><strong><em> location to M</em></strong><em>th</em><strong><em> location?<br># This is technically called SLICING if you assign to other variable</em></strong><br>In[]: arr[1:5]<br><strong>Out[]: array([1, 2, 3, 4])<em># Lets make first 5 range values equate to 500</em></strong><br>In[]: arr[0:5] = 500<br>In[]: arr<br><strong>Out[]: array([500, 500, 500, 500, 500,   5,   6,   7,   8,   9,  10])# Slicing<br></strong>In[]: sliced_array = arr[0:6]<br>In[]: sliced_array<br><strong>Out[]: array([500, 500, 500, 500, 500,   5])<em># See the magic here<br></em></strong>In[]: sliced_array[5] = 600<br>In[]: sliced_array<br><strong>Out[]: array([500, 500, 500, 500, 500, 600])</strong>In[]: arr<br><strong>Out[]: array([500, 500, 500, 500, 500, 600,   6,   7,   8,   9,  10])# Wait... WHAT?! But we assigned the sliced values to new numpy array. Why is arr[5] showing 600?</strong></pre><p>So slices are <strong>not </strong>separate arrays. It is a <strong>copy </strong>of the original array. Any changes to the slice <strong>reflect the original NumPy array</strong>. This is done by NumPy to remove <strong>unnecessary memory</strong> usage.</p><p>So how actually we can copy the NumPy array to another explicitly?</p><pre>In[]: arr_copy = arr.copy()In[]: arr[5] = 5<br>In[]: arr<br><strong>Out[]: array([500, 500, 500, 500, 500,   5,   6,   7,   8,   9,  10])</strong>In[]: arr_copy<br><strong>Out[]: array([500, 500, 500, 500, 500, 600,   6,   7,   8,   9,  10])<em># Voila! It did not change this time!</em></strong></pre><p><strong>11. Creating N x M matrix</strong></p><pre><strong><em># arange creates serial values from 0 to 49<br># reshape is used to shape the matrix.<br># Reshape works like - reshape(rows, columns)</em></strong>In[]: arr = np.arange(50).reshape(10,5)<br>In[]: arr<br>Out[]: <strong>array([[ 0,  1,  2,  3,  4],<br>       [ 5,  6,  7,  8,  9],<br>       [10, 11, 12, 13, 14],<br>       [15, 16, 17, 18, 19],<br>       [20, 21, 22, 23, 24],<br>       [25, 26, 27, 28, 29],<br>       [30, 31, 32, 33, 34],<br>       [35, 36, 37, 38, 39],<br>       [40, 41, 42, 43, 44],<br>       [45, 46, 47, 48, 49]])# Array Transposition<br></strong>In[]: arr.T<br>Out[]: <strong>array([[ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45],<br>       [ 1,  6, 11, 16, 21, 26, 31, 36, 41, 46],<br>       [ 2,  7, 12, 17, 22, 27, 32, 37, 42, 47],<br>       [ 3,  8, 13, 18, 23, 28, 33, 38, 43, 48],<br>       [ 4,  9, 14, 19, 24, 29, 34, 39, 44, 49]])</strong></pre><p>Let us keep it till here for now. This was a brief introduction to NumPy. Follow me to get regular updates on this kind of tutorial.</p><p><em>More content at</em><strong><em> </em></strong><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93db7b55a778" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/an-introduction-to-numpy-for-beginners-93db7b55a778">An Introduction to NumPy for Beginners</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Methods to Open Websites via Python]]></title>
            <link>https://python.plainenglish.io/3-methods-to-open-websites-via-python-8d3e10f45ca1?source=rss-13a6b35314ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d3e10f45ca1</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Rohan Kishore]]></dc:creator>
            <pubDate>Tue, 15 Mar 2022 09:56:05 GMT</pubDate>
            <atom:updated>2022-03-15T09:56:05.276Z</atom:updated>
            <content:encoded><![CDATA[<h4>The ways in which you can open a webpage using Python.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOoga42iuLkWxj_tKIzYYg.jpeg" /><figcaption>Photo by James Harrison on <a href="https://unsplash.com/photos/vpOeXr5wmR4">Unsplash</a></figcaption></figure><p>Hi. Working on a new project and trying to figure out how to open a webpage using Python? No worries! I’m here to help.</p><p>It’s pretty simple. There is an inbuilt Python library called <strong><em>webbrowser</em></strong>. To import it, just type:</p><pre>import webbrowser as wb</pre><p>I imported the module as ‘wb’ because it is easier to type compared to the original module name. In this tutorial, I’ll show you two methods using webbrowser) The first one is a single line command and the second one is a whole function dedicated to opening websites. Let’s take a look at the first one.</p><pre>import webbrowser as wb<br><br>wb.open(&quot;www.youtube.com&quot;)</pre><p>To open the link in a new tab:</p><pre>import webbrowser as wb<br><br>wb.open_new_tab(&quot;www.youtube.com&quot;)</pre><p>Now let’s look at the function method:</p><pre>import webbrowser as wb<br><br>def web(link):<br>    wb.open_new_tab(link)<br><br>web(&quot;www.medium.com&quot;)</pre><p>You can put any link inside the function and it’ll open in your default browser. You can also try other methods such as taking input from the user and then opening the user requested link. Anyways, that’s it for today, coders. See you in the next post.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d3e10f45ca1" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/3-methods-to-open-websites-via-python-8d3e10f45ca1">3 Methods to Open Websites via Python</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate QR Codes Using Python]]></title>
            <link>https://python.plainenglish.io/generate-qr-codes-using-python-2244ef882ae?source=rss-13a6b35314ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/2244ef882ae</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rohan Kishore]]></dc:creator>
            <pubDate>Tue, 08 Mar 2022 10:33:05 GMT</pubDate>
            <atom:updated>2022-03-08T10:33:05.101Z</atom:updated>
            <content:encoded><![CDATA[<h4>A guide on how to generate QR codes in Python using the pyqrcode module.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GYPsw1wIvyd3bEGx" /><figcaption>Photo by <a href="https://unsplash.com/@clark_fransa?utm_source=medium&amp;utm_medium=referral">Arnold Francisca</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The pyqrcode module is a QR code generator. The module automates most of the building process for creating QR codes. This module attempts to follow the QR code standard as closely as possible. The terminology and the encodings used in pyqrcode come directly from the standard.</p><p><strong>Installation<br></strong>pip install pyqrcode</p><p>install an additional module pypng to save image in png format:<br>pip install pypng</p><p>pyqrcode.create(content, error=&#39;H&#39;, version=None, mode=None, encoding=None)<strong>:</strong> When creating a QR code only the content to be encoded is required, all the other properties of the code will be guessed based on the contents given. This function will return a QRCode object.</p><p>One can specify all the properties of required QR code through the optional parameters of the pyqrcode.create() function. Below are some properties:</p><p>Below is the code:</p><pre># Import QRCode from pyqrcode<br>import pyqrcode<br>import png<br>from pyqrcode import QRCode<br><br># String which represents the QR code<br>s = &quot;www.youtube.com&quot;<br><br># Generate QR code<br>url = pyqrcode.create(s)<br><br># Create and save the svg file naming &quot;myqr.svg&quot;<br>url.svg(&quot;myqr.svg&quot;, scale=8)<br><br># Create and save the png file naming &quot;myqr.png&quot;<br>url.png(&#39;myqr.png&#39;, scale=6)</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FjFRqp33fOMqswp3B_Cggw.png" /></figure><p>And there you have it. Thank you for reading.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and</em><strong><em> </em></strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2244ef882ae" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/generate-qr-codes-using-python-2244ef882ae">Generate QR Codes Using Python</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Color Detection with Python]]></title>
            <link>https://python.plainenglish.io/color-detection-with-python-47c3be9821d8?source=rss-13a6b35314ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/47c3be9821d8</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rohan Kishore]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 06:50:08 GMT</pubDate>
            <atom:updated>2022-03-08T06:40:02.278Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Python program to recognize colors from a JPEG or PNG image.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5fA2Tl3iJJDdZjr1_utbA.jpeg" /></figure><p>Intermediate in Python? Here’s a cool and fun project to try, or even add to your resume. We’ll make a Python program that can recognize colors from a JPEG or PNG image. It’ll also give you the name and RGB values of the color. So let&#39;s get right into it!</p><p>Modules Required:<br>* cv2<br>* pandas</p><p>Installation of modules:</p><pre>pip install cv2<br>pip install pandas</pre><p>Then:</p><pre>def color_recognition():<br>    # required modules<br>    import cv2  # pip install cv2<br>    import pandas as pd  # pip install pandas<br><br>    img_path = &quot;colorpic.jpg&quot;<br>    img = cv2.imread(img_path)<br><br>    # declaring global variables (are used later on)<br>    clicked = False<br>    r = g = b = x_pos = y_pos = 0<br><br>    # Reading csv file with pandas and giving names to each column<br>    index = [&quot;color&quot;, &quot;color_name&quot;, &quot;hex&quot;, &quot;R&quot;, &quot;G&quot;, &quot;B&quot;]<br>    csv = pd.read_csv(&#39;colors.csv&#39;, names=index, header=None)<br><br>    # function to calculate minimum distance from all colors and get the most matching color<br>    def get_color_name(R, G, B):<br>        minimum = 10000<br>        for i in range(len(csv)):<br>            d = abs(R - int(csv.loc[i, &quot;R&quot;])) + abs(G - int(csv.loc[i, &quot;G&quot;])) + abs(B - int(csv.loc[i, &quot;B&quot;]))<br>            if d &lt;= minimum:<br>                minimum = d<br>                cname = csv.loc[i, &quot;color_name&quot;]<br>        return cname<br><br>    # function to get x,y coordinates of mouse double click<br>    def draw_function(event, x, y, flags, param):<br>        if event == cv2.EVENT_LBUTTONDBLCLK:<br>            global b, g, r, x_pos, y_pos, clicked<br>            clicked = True<br>            x_pos = x<br>            y_pos = y<br>            b, g, r = img[y, x]<br>            b = int(b)<br>            g = int(g)<br>            r = int(r)<br><br>    cv2.namedWindow(&#39;image&#39;)<br>    cv2.setMouseCallback(&#39;image&#39;, draw_function)<br><br>    while True:<br><br>        cv2.imshow(&quot;image&quot;, img)<br>        if clicked:<br><br>            # cv2.rectangle(image, start point, endpoint, color, thickness)-1 fills entire rectangle<br>            cv2.rectangle(img, (20, 20), (750, 60), (b, g, r), -1)<br><br>            # Creating text string to display( Color name and RGB values )<br>            text = get_color_name(r, g, b) + &#39; R=&#39; + str(r) + &#39; G=&#39; + str(g) + &#39; B=&#39; + str(b)<br><br>            # cv2.putText(img,text,start,font(0-7),fontScale,color,thickness,lineType )<br>            cv2.putText(img, text, (50, 50), 2, 0.8, (255, 255, 255), 2, cv2.LINE_AA)<br><br>            # For very light colours we will display text in black colour<br>            if r + g + b &gt;= 600:<br>                cv2.putText(img, text, (50, 50), 2, 0.8, (0, 0, 0), 2, cv2.LINE_AA)<br><br>            clicked = False<br><br>        # Break the loop when user hits &#39;esc&#39; key<br>        if cv2.waitKey(20) &amp; 0xFF == 27:<br>            break<br><br>    cv2.destroyAllWindows()</pre><pre>color_recognition()</pre><p>You can replace the file path with your own image.</p><p>And there you have it. Thank you for reading.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and</em><strong><em> </em></strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47c3be9821d8" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/color-detection-with-python-47c3be9821d8">Color Detection with Python</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>