<?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: Jaya chandrika reddy</title>
    <description>The latest articles on DEV Community by Jaya chandrika reddy (@chandrika56).</description>
    <link>https://dev.to/chandrika56</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%2F379067%2Ff50772c5-5a90-44a4-ad13-0c71569274e0.jpg</url>
      <title>DEV Community: Jaya chandrika reddy</title>
      <link>https://dev.to/chandrika56</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chandrika56"/>
    <language>en</language>
    <item>
      <title>Hello Hadoop | Learn Hadoop in just a few minutes easily!</title>
      <dc:creator>Jaya chandrika reddy</dc:creator>
      <pubDate>Fri, 05 Jun 2020 17:59:21 +0000</pubDate>
      <link>https://dev.to/chandrika56/hello-hadoop-learn-hadoop-in-just-a-few-minutes-easily-1687</link>
      <guid>https://dev.to/chandrika56/hello-hadoop-learn-hadoop-in-just-a-few-minutes-easily-1687</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally written at:&lt;/em&gt; &lt;a href="https://jayachandrika.com" rel="noopener noreferrer"&gt;https://jayachandrika.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets explore Hadoop(Click to skip to that topic):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hadoop: Whats the buzz around it?&lt;/li&gt;
&lt;li&gt;Hadoop EcoSystem &lt;/li&gt;
&lt;li&gt;HDFS: Hadoop Distributed File System&lt;/li&gt;
&lt;li&gt;YARN: Yet Another Resource Negotiator &lt;/li&gt;
&lt;li&gt;MapReduce: Mappers and Reducers&lt;/li&gt;
&lt;li&gt;Pig : A fast and easy alternative to MapReduce&lt;/li&gt;
&lt;li&gt;TEZ&lt;/li&gt;
&lt;li&gt;Hive&lt;/li&gt;
&lt;li&gt;Ambari: UI&lt;/li&gt;
&lt;li&gt;Mesos: An Alternative to YARN&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Spark: Queen of Hadoop Chessboard&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HBase&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apache STORM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OOZIE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ZooKeeper &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data Ingestion: Sqoop + Flume + Kafka&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;External Data Storages: MySQL, Cassandra, MongoDB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Query Engines: Drill + Hue + Phoenix + Presto + Zeplin&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Platform:&lt;/code&gt; Hortonworks Sandbox &lt;/p&gt;

&lt;h2 id="what-is-yaml"&gt; Hadoop: Whats the buzz around it?&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hadoop is an open source software platform with utilities or tools, for distributed storage and distributed processing on very large files and datasets, performed on several computer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I agree if it doesnt make complete sense yet. Lets break it down.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example:&lt;/em&gt; Lets say we got employee information of millions of people working in Google, Amazon , Facebook and we have to combine all their information and remake the list in decreasing order of salary.&lt;/p&gt;

&lt;p&gt;To load such big data into one normal computer and perform operations on it, making the computer to process each every employee, will either make computer to burst out like a SpaceX rocket or take a lo...ng time to process that our next generation have to see the output!&lt;/p&gt;

&lt;p&gt;If we alloted this data to several computers, each computer processing a small piece of it, it gives fast output without the overload of processing huge data.&lt;/p&gt;

&lt;p&gt;This is what Hadoop does, &lt;/p&gt;

&lt;p&gt;&lt;em&gt;distributed storage&lt;/em&gt;-The huge data is distributed to several computers and is stored there.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;distributed processing&lt;/em&gt;-Instead of one costly computer with high processing power, several normal computers can process the big data.&lt;/p&gt;

&lt;p&gt;In short, Hadoop has tools to store, process this big data giving us the expected results.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lets see how exactly Big Data is handled in Hadoop!&lt;/em&gt;&lt;/p&gt;

&lt;h2 id="draw"&gt; Hadoop EcoSystem&lt;/h2&gt;

&lt;p&gt;Hadoop has many components, each has its own purpose and functions.(&lt;em&gt;Kind of like each hero in Endgame has their own movie&lt;/em&gt;.)&lt;/p&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fav65p9uw5foyeeq0ywop.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fav65p9uw5foyeeq0ywop.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HDFS, YARN and MapReduce belong to core Hadoop Ecosystem while others were added later on to solve specific problems. Lets explore each one of them, one by one.&lt;/p&gt;

&lt;p&gt;Lets say we have a huge chunks of potato(Big data) with us and we wish to make French fries, Chips and Nuggets.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In order to make them, we divide potato into 3 blocks of potato for french fries, potato for chips and nuggets,&lt;br&gt;
which is what &lt;code&gt;HDFS&lt;/code&gt; does, dividing the big chunk of data and distribute to several computers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All resources or ingrediants required for each dish are alloted respectively, similiar to &lt;code&gt;YARN&lt;/code&gt; which manages the resources needed for each chunk or cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We transform this potato to the desired dish which is same as &lt;code&gt;MapReducers&lt;/code&gt; which transform data in efficient manner and aggregate the data giving us the desired result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lets explore in more detail about each component.&lt;/p&gt;

&lt;h2 id="blur"&gt; HDFS: Hadoop Distributed File System&lt;/h2&gt;
 

&lt;p&gt;As it says, it distributes the big file across many computers as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The big file is converted to blocks(each block size max upto 128 Mb) &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Blocks are stored across many computers. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Redundancy&lt;/em&gt;:To handle failure of one computer, more than one copy of each block is stored in each computer. So that if one fails,other computers will have, failed computer's data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="yarn"&gt; YARN: Yet Another Resource Negotiator&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Its the heartbeat of the hadoop system, all the &lt;em&gt;data processing&lt;/em&gt; happens here.&lt;/li&gt;
&lt;li&gt;It provides the computational resources like CPUs, memory, etc for application executions.&lt;/li&gt;
&lt;li&gt;It does job scheduling and manages the resources like what nodes are available for, which ones should be allowed to run tasks etc.&lt;/li&gt;
&lt;li&gt;Usually, its advised not to code against YARN directly. Instead, use one of the higher-level tools, for example Hive, to make your life easier.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a way, like how Operating System allots resources to a computer, YARN &lt;code&gt;allocates resources&lt;/code&gt; in Hadoop. &lt;/p&gt;

&lt;h2 id="map"&gt; MapReduce: Mappers and Reducers&lt;/h2&gt;

&lt;p&gt;So we got data in HDFS, resources allocated from YARN. Now how to make get our desired results from this? We code using MapReduce.&lt;/p&gt;

&lt;p&gt;MapReduce has two functions: Mappers and Reducers.&lt;br&gt;
Here python or java programming is used to code those functions.Its overall, a programming model to process and compute across the data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mappers split the data and map them according to the desired output.&lt;/li&gt;
&lt;li&gt;Reducers take the output of the mappers and aggregate or combine the data to give result.&lt;/li&gt;
&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fynx62ganu3vxhfb87d9w.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fynx62ganu3vxhfb87d9w.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As input gets in, mapper transforms data one by one and organizes according to the output we desire.&lt;/p&gt;

&lt;p&gt;The reducer, reduces the mapper output to the aggregated form which we require as output.&lt;/p&gt;

&lt;h2 id="pig"&gt; Pig : A fast and easy alternative to MapReduce&lt;/h2&gt; 
 

&lt;ul&gt;
&lt;li&gt;Pig Latin, &lt;code&gt;a scripting language&lt;/code&gt;, uses SQL like syntax, forming relationship, selecting a data, filtering it, transforming it etc. Contains &lt;code&gt;User defined functions&lt;/code&gt; to help us create our own functions.&lt;/li&gt;
&lt;li&gt;Not all business problems can be solved by converting to mappers and reducers form. So Pig Latin sitting on top of MapReduce, converts our Pig Latin script into map reduce form.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Pig script can be run by either of the 3 below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grunt(Command Line Interpreter)&lt;/li&gt;
&lt;li&gt;Script(place the script in file and running it)&lt;/li&gt;
&lt;li&gt;Ambari (Directly from Pig View)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1fasv0zk1lt2ac77xgfk.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1fasv0zk1lt2ac77xgfk.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2 id="tez"&gt; TEZ&lt;/h2&gt; 

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We might wonder if using pig on top of mapreduce might increase latency. Tez is present in between them, to optimize and make it 10x faster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It makes Hive, Pig and Map Reduce jobs faster, optimising physical dataflow and resource usage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using DAG(Directed Acyclic Graphs) it sees the workflow of the jobs and finds the optimal way among it making our job easier. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suppose:we have three ways, 1-2-3 , 4-9-8, 2-7-9 and we need to find the smallest path, we choose 1-2-3. DAG works in somewhat similar way.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The output is processed again and again Through DAG giving us the optimal solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="hive"&gt; Hive&lt;/h2&gt; 

&lt;ul&gt;
&lt;li&gt;It takes &lt;code&gt;SQL queries&lt;/code&gt; as input from command prompt and transforms them to mapreduce jobs and automatically gets the job done.&lt;/li&gt;
&lt;li&gt;We can store the result of query into a &lt;code&gt;view&lt;/code&gt;, perform a query onto entire cluster and &lt;code&gt;define our own functions&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Though Pig and Hive might be similiar,Hive is used for completely structured Data whereas Pig Hadoop Component is used for semi structured data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pig is relatively faster than Hive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hive is slow and not useful for realtime transactions unlike Pig and Spark.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It might give the feel of a relational database, but it cant delete, insert etc as there are no tables, joins, primary keys and the data is just a flat text, &lt;code&gt;de-normalized&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3590hkz2m4fi8hiaytcy.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3590hkz2m4fi8hiaytcy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can observe,the queries used are same as SQL queries.&lt;/p&gt;

&lt;h2 id="ambari"&gt; Ambari: UI&lt;/h2&gt; 
 

&lt;ul&gt;
&lt;li&gt;Its pretty much a web interface to graphically interact with the cluster and its usage.&lt;/li&gt;
&lt;li&gt;It gives us a high-level view of your cluster, what’s running, what system you are using, what resources are available/in use.&lt;/li&gt;
&lt;li&gt; It shows statistics about the cluster like CPU Usage,Memory Usage,Network Usage, Cluster load etc.&lt;/li&gt;
&lt;li&gt;All services like HDFS, YARN etc can be used on a cluster using Ambari.&lt;/li&gt;
&lt;li&gt;Even Hadoop can be installed using Ambari.&lt;/li&gt;
&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flyi1oetwh9ear07yxkio.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flyi1oetwh9ear07yxkio.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="mesos"&gt; Mesos: An Alternative to YARN&lt;/h2&gt; 

&lt;ul&gt;
&lt;li&gt;Its simliar to YARN but then difference is Mesos is more general.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In simple words, YARN works only on Hadoop components like mapreduce etc where as Mesos can allcate resources to outside of hadoop like web servers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;YARN is for analytical and long process jobs where as Mesos is for both long and short process jobs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="spark"&gt; Spark: Queen of Hadoop Chessboard&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Spark engine is pretty fast, infact 100x faster than mapreduce and is used for large scale data processing.&lt;/li&gt;
&lt;li&gt;Like Hive -&amp;gt; it can handle SQL queries, like Apache STORM -&amp;gt;it handles real time streaming hence we call it the queen.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Processing in Spark happens in this way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Driver Program&lt;/code&gt;, containing script to control what happens in the job.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Cluster Manager&lt;/code&gt;,which can be YARN, Mesos or its own Spark Cluster Manager.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Executor&lt;/code&gt;, it contains cache prioritizing memory based solution unlike other disk based solutions.&lt;/li&gt;
&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F629c95m8ig8xd24xi3g1.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F629c95m8ig8xd24xi3g1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Spark has many components:   &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spark Streaming: Handles Realtime data.&lt;/li&gt;
&lt;li&gt;Spark SQL: SQL interface, takes SQL queries.&lt;/li&gt;
&lt;li&gt;MLLib: Machine Learning operations can be performed without about mappers and reducers to solve a problem.&lt;/li&gt;
&lt;li&gt;GraphX: All graph related problems and analytics are done using this.&lt;/li&gt;
&lt;li&gt;Spark Core: It provides distributed task dispatching, scheduling, and basic I/O functionalities. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg9ymdncgm68w3lw4wcm1.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg9ymdncgm68w3lw4wcm1.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Spark uses a specialized fundamental data structure known as &lt;code&gt;RDD (Resilient Distributed Datasets)&lt;/code&gt;.Its an object representing dataset and we can perform operations on that object just like in java.&lt;/p&gt;

&lt;h2 id="hbase"&gt; HBase&lt;/h2&gt; 

&lt;ul&gt;
&lt;li&gt;Its basically a scalable &lt;code&gt;NoSQL Database&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A columnar data storage, pretty fast and finds it useful for high data transaction rates.&lt;/li&gt;
&lt;li&gt;CRUD(Create,Read,Update and Delete) operations are employed here.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="storm"&gt; Apache STORM&lt;/h2&gt; 

&lt;ul&gt;
&lt;li&gt;Processes continuous &lt;code&gt;realtime streaming data&lt;/code&gt; like from sensors or weblogs etc.&lt;/li&gt;
&lt;li&gt;Even spark streaming does this but more in batch intervals but storm handles data event wise.&lt;/li&gt;
&lt;li&gt;Spout is the term used for sources of the streaming data i.e., they produce. Bolts is the term used for those which transform or aggregate this streaming data.&lt;/li&gt;
&lt;li&gt;Usually kafka(which sends data into cluster) and storm are used as a pair.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2 id="oozie"&gt; OOZIE&lt;/h2&gt; 

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Runs and Schedules various jobs/tasks on Hadoop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instructions are given via XML file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2 id="zoo"&gt; ZooKeeper&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Co-ordinates everything on cluster. Like which is the master node, task assigned for each worker node, which node is up and which is down and which worker nodes are available etc.&lt;/li&gt;
&lt;li&gt;If a master node dies, it chooses who the next master should be. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;:This phenomenon can be observed in whatsapp groups or in videocalls where if the host leaves the group, someone else is assigned as the next host.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Outside Hadoop EcoSystem, we can have databases to store the data and Query Engines to get input data to the cluster. Lets have a look at them!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;h2 id="kafka"&gt; Data Ingestion: Sqoop + Flume + Kafka&lt;/h2&gt; &lt;br&gt;
 So how do you get data into the cluster? Sqoop,Flume and Kafka help with this via data ingestion.

&lt;p&gt;&lt;em&gt;Sqoop&lt;/em&gt;: Sqoop is a command-line interface application tool for transferring data between relational database servers and Hadoop.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Its just a way of tying hadoop database to relational database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Flume&lt;/em&gt;: Another way of sending data into cluster and it acts as a buffer between the data coming in and storing, so that cluster wont go down with overwhelming data coming in realtime.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Kafka&lt;/em&gt;: This is more a general publisher/subscriber model where the &lt;code&gt;publishers&lt;/code&gt; send/produce data as &lt;code&gt;topics&lt;/code&gt; which are subscribed by &lt;code&gt;consumers&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Collects any sort of data from PCs, webservers etc and broadcast it into Hadoop Cluster.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="storage"&gt; External Data Storages: MySQL, Cassandra, MongoDB&lt;/h2&gt; 

&lt;p&gt;&lt;em&gt;MySQL:&lt;/em&gt; Typical &lt;code&gt;SQL&lt;/code&gt; based relational database.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cassandra :&lt;/em&gt; Its a &lt;code&gt;NoSQL&lt;/code&gt; columnar database with no single point of failure. It favours availability and partial- tolerance in CAP theorem.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;MongoDB :&lt;/em&gt; A &lt;code&gt;NoSQL&lt;/code&gt; database which uses document model. Its used when we deal with huge data and its pretty flexible.&lt;/p&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1txw10ipyzg1k0uyq1iv.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1txw10ipyzg1k0uyq1iv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2 id="query"&gt; Query Engines: Drill + Hue + Phoenix + Presto + Zeplin&lt;/h2&gt; 

&lt;p&gt;All these are interactive query engines to fetch required data from databases under them like Hbase, Cassandra etc. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Drill&lt;/code&gt; lets us use SQL queries, even when the databases under it (Hbase, Cassandra, MongoDB etc) are non relational Databases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Phoenix&lt;/code&gt; is similar to drill with SQL queries but with ACID properties(Atomicity,Consistency,Isolation and Durability).Its fast but works only HBase. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Presto&lt;/code&gt; is similar to Drill and unlike Drill, it connects to Cassandra and executes query across the cluster. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Hue&lt;/code&gt; (Hadoop User Experience), an SQL Cloud Editor, is used for query and as UI in Cloudera just like Ambari to HortonWorks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Zeppelin&lt;/code&gt; has Notebook UI to visualize the data similar to jupyter notebooks for TensorFlow and share, interact with the code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It might be overwhelming to see many components doing the same work.Ultimately based on the task and the type of database(whether its relational or non structered data etc) and other factors, we need to decide the right component and utilize it and it comes with knowledge of the components,practice and experience.&lt;/p&gt;

&lt;p&gt;Hope you had fun learning Hadoop, i for one certainly had fun sharing about it!!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Originally written at:&lt;/em&gt; &lt;a href="https://jayachandrika.com" rel="noopener noreferrer"&gt;https://jayachandrika.com&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Now you can follow us to explore more interesting topics, in Instagram at: &lt;strong&gt;@code_voyager&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Great to have you here, lets get back for the next post and explore more!&lt;/p&gt;

&lt;p&gt;Have an amazing day!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>beginners</category>
      <category>hadoop</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Learn Docker basics quickly!</title>
      <dc:creator>Jaya chandrika reddy</dc:creator>
      <pubDate>Tue, 26 May 2020 15:04:54 +0000</pubDate>
      <link>https://dev.to/chandrika56/learn-docker-basics-quickly-3f7f</link>
      <guid>https://dev.to/chandrika56/learn-docker-basics-quickly-3f7f</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Article originally written at &lt;a href="https://jayachandrika.com"&gt;https://jayachandrika.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this Article lets explore :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker:What the hell is it?&lt;/li&gt;
&lt;li&gt;But why Docker??&lt;/li&gt;
&lt;li&gt;What are Containers&lt;/li&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;li&gt;Magic Commands&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Have you ever built an application but it doesn't run on all platforms? Or been sick of installing different dependencies and libraries for each service/component in the application? Dodged the whole nine yards just to deploy, scale and manage a simple application??&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then DOCKER is waiting for you!!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2 id="what-is-yaml"&gt; Docker:What the hell is it? &lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker is a set of platform as a service products that uses OS-level virtualization to deliver software in packages called containers.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
(&lt;em&gt;Well&lt;/em&gt;. . .thats the GOOGLE definition for you! )&lt;/p&gt;

&lt;p&gt;To wrap it up simply,it is just a &lt;strong&gt;BOX&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Imagine,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A printer box, we insert a paper and get printed text or colors on it.&lt;br&gt;&lt;br&gt;
So how is it working ? Perhaps all the colors and required material is already present in the printer.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xcl1qwvo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ldj07mxkg8nnnrfirfvx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xcl1qwvo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ldj07mxkg8nnnrfirfvx.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider a car wash, car is sent in, many process like washing, cleaning etc happen and at the end we get a shiny clean car (or a less rusty one).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---eLwBBWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/16bt6gz7ht3pbr95pnmz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---eLwBBWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/16bt6gz7ht3pbr95pnmz.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, docker is like a printer box or car wash setup in this instance, taking an &lt;code&gt;input&lt;/code&gt; and giving an &lt;code&gt;output&lt;/code&gt; basically.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is basically a box with an application and its related dependencies, libraries etc inside it&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h2 id="why-docker"&gt;But why docker?&lt;/h2&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uf4OLGGV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tdgcawgji5yhrw6i2njp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uf4OLGGV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tdgcawgji5yhrw6i2njp.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Imagine we are building a zoo, we toss all animals like monkeys, Lion and Crocodiles in one big park with &lt;em&gt;only one kind of food&lt;/em&gt; and &lt;em&gt;only one kind of environment&lt;/em&gt;, lets say, land.&lt;/p&gt;

&lt;p&gt;The bananas eaten by monkeys can’t be used by Lions and crocodiles, the meat for Lions can’t be eaten by monkeys. Monkeys want trees and crocodiles need a water space in the environment.&lt;/p&gt;

&lt;p&gt;In similar way, if we are building an application that has services like a database and framework etc, The libraries and dependencies(food) used by databases (cassandra, postgresql, mongodb etc) may not be compatible/suitable for frameworks (strapi, nodejs express etc).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Eg: MongoDb version 4.26 might not be compatible/suitable for NodeJs version 4.16.4&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To make it easy to develop, run and maintain an application and to operate on all the platforms we came up docker. The problem in zoo example can be solved by providing each animal, a &lt;em&gt;separate boundary&lt;/em&gt; with the required food and environment.&lt;/p&gt;

&lt;h2 id="containers"&gt;Containers&lt;/h2&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F3pqLKbh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vtje8zg81l5oj7zohyuu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F3pqLKbh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vtje8zg81l5oj7zohyuu.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;In docker we have those separate boundaries called &lt;strong&gt;&lt;em&gt;containers&lt;/em&gt;&lt;/strong&gt;. We place each service in one container with all the libraries and dependencies required for it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Container is a completely isolated environment with their own processes, network interfaces and their own mounts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Wait, doesnt it look familiar?&lt;/em&gt; Yes,you are right if you guessed it, they remind us of &lt;strong&gt;Virtual machines&lt;/strong&gt;. If its similar to VMs, Why on Earth do we need to use Containers??&lt;/p&gt;

&lt;p&gt;Well, Each VM has a separate &lt;em&gt;OS&lt;/em&gt; along with libraries, dependencies and application, which increases overload and utilization, making it difficult to operate it in small PCs(though we might not use it there).&lt;/p&gt;

&lt;p&gt;Whereas Containers share the same OS, considerably less overload and utilization than VMs. Hence they are just the darlings preferred for application development, deployment and management.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q4mLKN7U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2vy9qbauditk63n7glx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q4mLKN7U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2vy9qbauditk63n7glx3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h2 id="images"&gt;Images&lt;/h2&gt;

&lt;p&gt;These are readymade templates of services like MongoDb, NodeJs etc, to run in containers. We can either use existing images from docker.io or create our own.&lt;/p&gt;

&lt;p&gt;Creating an Image of the service helps in shipping it for deployments. Then it is just running a simple command to get the server up and running. We dont have to worry about creating environment, installing dependencies and what not.&lt;/p&gt;

&lt;h2 id="magic"&gt;Magic commands&lt;/h2&gt;

&lt;p&gt;Its time to blow some fairy pixel dust and do some magic!&lt;/p&gt;

&lt;p&gt;Lets start with running an image in a container,using run command.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run redis image in container&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run redis
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Vh6YkEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sz6xa6dmde5kmt1h573u.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Vh6YkEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sz6xa6dmde5kmt1h573u.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;List the version details&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BKftNYbz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/120wrfuxn2qb8pxchsqy.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BKftNYbz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/120wrfuxn2qb8pxchsqy.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;List the Running containers&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b770m2J8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lwq7ko720lm6eq0q65o2.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b770m2J8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lwq7ko720lm6eq0q65o2.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;List the Running &amp;amp; Not Running containers&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps -a
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RQuMRXau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ho6h4ouundftgxpfooga.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RQuMRXau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ho6h4ouundftgxpfooga.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Remove a container&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker rm [container ID]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8unzI0kN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/19dim0nu2fetbr04028c.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8unzI0kN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/19dim0nu2fetbr04028c.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: To remove a container make sure it is stopped first using stop command.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;List the images&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dw192PlQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/was9o92f2kk9srrh6pi0.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dw192PlQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/was9o92f2kk9srrh6pi0.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Remove an image&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker rmi [image_name]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g3LSRBIe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p9sh5l4gu39jl2ci63v1.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g3LSRBIe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p9sh5l4gu39jl2ci63v1.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Just download the image but not run in the container&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull [image_name]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lXxen1Vf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a8eqa8gjwjblo4uch7tw.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lXxen1Vf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a8eqa8gjwjblo4uch7tw.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Thank you so much for reading my content. More of such content coming on this blog, so stay tuned.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Article originally written at &lt;a href="https://jayachandrika.com"&gt;https://jayachandrika.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>codenewbie</category>
      <category>computerscience</category>
      <category>docker</category>
      <category>devops</category>
    </item>
    <item>
      <title>Draw Shapes,Text,Polygons,Blend,Blur images | Using OpenCV With Python | Easy code</title>
      <dc:creator>Jaya chandrika reddy</dc:creator>
      <pubDate>Tue, 26 May 2020 09:24:14 +0000</pubDate>
      <link>https://dev.to/chandrika56/draw-shapes-text-polygons-blend-blur-images-using-opencv-with-python-easy-code-1o1e</link>
      <guid>https://dev.to/chandrika56/draw-shapes-text-polygons-blend-blur-images-using-opencv-with-python-easy-code-1o1e</guid>
      <description>&lt;p&gt;In this Article lets learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Blend: How to Combine 2 Images?]&lt;/li&gt;
&lt;li&gt;[Draw Shapes &amp;amp; Text on Image]&lt;/li&gt;
&lt;li&gt;[Draw a Polygon]&lt;/li&gt;
&lt;li&gt;[Blur an image]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Pre Requesites:&lt;/code&gt; Jupyter or any python editor&lt;/p&gt;

&lt;h2&gt; Blend: How to Combine 2 Images?&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Blending in OpenCV is joining two images of same size into each other.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can make cool posters, blend your loved ones picture with their favourite character on background and gift them, bring out your creativity and what not!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lets begin the magic!&lt;/em&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;cv2&lt;/span&gt;  &lt;span class="c1"&gt;#opencv library
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt; &lt;span class="c1"&gt;# Matplotlib used for visualization
&lt;/span&gt;    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;

    &lt;span class="c1"&gt;# Reading the jpeg formmatted image from its path to img1
&lt;/span&gt;    &lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;r'./img/hp.JPG'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Reading the jpeg formatted image from its path to img2
&lt;/span&gt;    &lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;r'./img/doc.JPG'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Converting from BGR(blue,green,red) color space to RGB using cvtColor
&lt;/span&gt;    &lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cvtColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img1&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="n"&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cvtColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img2&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="n"&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Displaying the image 1
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Displaying the image 2
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--10uuvU9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ojashsmpmns2k0riub3t.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--10uuvU9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ojashsmpmns2k0riub3t.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o6MAquM4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kc1bzq8epugh6232slbg.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o6MAquM4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kc1bzq8epugh6232slbg.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;#'1' Flips image to left side, '0' to upside down and '-1' to combination of both 0 and 1
&lt;/span&gt;    &lt;span class="n"&gt;flip_img&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Showing flipped image
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flip_img&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RB2t2HMc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8jfq839wvgguu7tdrta7.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RB2t2HMc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8jfq839wvgguu7tdrta7.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Gives the shape (height,width, no.of color channels(RGB)) of image1
&lt;/span&gt;    &lt;span class="n"&gt;flip_img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(2093, 2652, 3)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Gives the shape (height,width, no.of color channels(RGB)) of image2
&lt;/span&gt;    &lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(2127, 3840, 3)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Both images should be of same size to blend.
&lt;/span&gt;    &lt;span class="n"&gt;flip_img&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flip_img&lt;/span&gt;&lt;span class="p"&gt;,(&lt;/span&gt;&lt;span class="mi"&gt;2652&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2093&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="p"&gt;,(&lt;/span&gt;&lt;span class="mi"&gt;2652&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2093&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Increase in alpha increases img1 weightage,beta for img2
&lt;/span&gt;    &lt;span class="n"&gt;blended&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addWeighted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;flip_img&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;src2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;img2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;beta&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;gamma&lt;/span&gt;&lt;span class="o"&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;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LJiGcUyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2we6map2mfkmejuuodjq.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LJiGcUyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2we6map2mfkmejuuodjq.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Saves the blended img under the name blended.JPG
&lt;/span&gt;    &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imwrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'blended_img.png'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;blended&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;True
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;h2 id="why-yaml"&gt; Draw Shapes on Image &lt;/h2&gt;

&lt;p&gt;Different shapes can be drawn on an image, to mark an object or create a figure etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rectangles&lt;/li&gt;
&lt;li&gt;Hollow circles&lt;/li&gt;
&lt;li&gt;Solid Circles&lt;/li&gt;
&lt;li&gt;Lines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and many more can be drawn using OpenCV.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;cv2&lt;/span&gt; &lt;span class="c1"&gt;#  opencv library
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
    &lt;span class="c1"&gt;# Matplotlib used for visualization purpose
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;

    &lt;span class="c1"&gt;# Array of size 512x512 filled with zero as values,
&lt;/span&gt;    &lt;span class="c1"&gt;# to create an image with black color.
&lt;/span&gt;    &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;int16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Displays the shape(Height,width,no.of color channels(RGB))
&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;shape&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(512, 512, 3)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# To display the image
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--spsPmS5G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9hf1veop9ys3t07g2ypc.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--spsPmS5G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9hf1veop9ys3t07g2ypc.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# cv2.rectangle(image, start_point, end_point, color, thickness)
&lt;/span&gt;    &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rectangle&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;pt1&lt;/span&gt;&lt;span class="o"&gt;=&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;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;pt2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&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;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;thickness&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array([[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--67aQDuB5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w0con9c5lcujj6typi9w.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--67aQDuB5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w0con9c5lcujj6typi9w.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# cv2.circle(image, center_coordinates, radius, color, thickness)
&lt;/span&gt;    &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;circle&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;center&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&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;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;thickness&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array([[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
...,
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p-TwbsSY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fml92adxbkfvpc468smv.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p-TwbsSY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fml92adxbkfvpc468smv.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Negative values for thickness results in filled/solid circles
&lt;/span&gt;    &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;circle&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;center&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;255&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;span class="n"&gt;thickness&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array([[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IOOKb2_W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1qtocp61l3yzopslnxlq.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IOOKb2_W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1qtocp61l3yzopslnxlq.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# cv2.line(image, start_point, end_point, color, thickness)
&lt;/span&gt;    &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;line&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;pt1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;275&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;275&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;pt2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&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;span class="mi"&gt;255&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;span class="n"&gt;thickness&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array([[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E4oWIU-I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ij4mx5glbftemcseg52.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E4oWIU-I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ij4mx5glbftemcseg52.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Font of the text
&lt;/span&gt;    &lt;span class="n"&gt;text_style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FONT_ITALIC&lt;/span&gt;

    &lt;span class="c1"&gt;# Syntax
&lt;/span&gt;    &lt;span class="c1"&gt;#cv2.putText(image, text, org, font, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])
&lt;/span&gt;
    &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;putText&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;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'HAKUNA MATATA'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;fontFace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;text_style&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;fontScale&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&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;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;thickness&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;lineType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LINE_AA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array([[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K4bx8pkP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x03lxc0g4aeu5hpm5zlu.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K4bx8pkP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x03lxc0g4aeu5hpm5zlu.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="draw"&gt; Draw a Polygon &lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;cv2&lt;/span&gt;
    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

    &lt;span class="c1"&gt;# Matplotlib used for visualization purpose
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;

    &lt;span class="c1"&gt;# Array of size 512x512 filled with zero as values,
&lt;/span&gt;    &lt;span class="c1"&gt;# to create an image with black color.
&lt;/span&gt;    &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;int16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Assigning vertices to polygon
&lt;/span&gt;    &lt;span class="n"&gt;poly&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([[&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;int32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;poly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    (4, 2)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Reshaping according to opencv format
&lt;/span&gt;    &lt;span class="n"&gt;poly_new&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;poly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reshape&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;poly_new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(4, 1, 2)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# cv2.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]])
&lt;/span&gt;    &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;polylines&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;poly_new&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="n"&gt;isClosed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&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;span class="mi"&gt;255&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;span class="n"&gt;thickness&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array([[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OWwCFZGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0omx3op1l2zcpwk7b0tp.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OWwCFZGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0omx3op1l2zcpwk7b0tp.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="blur"&gt; Blur an image&lt;/h2&gt;

&lt;p&gt;There are plenty of blurring techniques available.Some of the methods are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default Blurring Technique&lt;/li&gt;
&lt;li&gt;Gaussian Blurring Technique&lt;/li&gt;
&lt;li&gt;Smoothing Technique&lt;/li&gt;
&lt;li&gt;Median Blurring Technique&lt;/li&gt;
&lt;li&gt;Bilateral Filter Blurring Technique&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets explore each one of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;     &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;cv2&lt;/span&gt;  &lt;span class="c1"&gt;# opencv library
&lt;/span&gt;
    &lt;span class="c1"&gt;# Matplotlib used for visualization
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
    &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;
    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

    &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;r'./img/image.JPG'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cvtColor&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;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XomGoqCn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b7u6j586kwlib6ngek45.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XomGoqCn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b7u6j586kwlib6ngek45.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ones&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;

    &lt;span class="c1"&gt;# Default Blurring Technique
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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="n"&gt;blur&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;ksize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fm57jWUT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/69wf6fsam1kmmrjldes6.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fm57jWUT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/69wf6fsam1kmmrjldes6.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Gaussian Blurring Technique
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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="n"&gt;GaussianBlur&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="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&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;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OQn3Pxi0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wacnrdv1lscn6jytvf20.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OQn3Pxi0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wacnrdv1lscn6jytvf20.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Smoothing Technique
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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="n"&gt;filter2D&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WaBS7ckQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/md2p176g3cy2fjwidw1o.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WaBS7ckQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/md2p176g3cy2fjwidw1o.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Median Blurring Technique
&lt;/span&gt;    &lt;span class="c1"&gt;# Reduces unwanted noise
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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="n"&gt;medianBlur&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="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5CxpH6JR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/24p8oa46siw2tt9gjcqz.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5CxpH6JR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/24p8oa46siw2tt9gjcqz.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Bilateral Filter Blurring Technique
&lt;/span&gt;    &lt;span class="c1"&gt;# Reduces unwanted noise with sharp edges but slow
&lt;/span&gt;    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&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="n"&gt;bilateralFilter&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="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hMjHTLSk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tvj3sxvpfhrqg8z30nob.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hMjHTLSk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tvj3sxvpfhrqg8z30nob.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Try out all these and feel free to ask me doubts via gmail at: &lt;strong&gt;&lt;a href="mailto:jayachandrika56@gmail.com"&gt;jayachandrika56@gmail.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;



&lt;blockquote&gt;
&lt;p&gt;Now you can follow us to explore more interesting topics, in Instagram at: &lt;strong&gt;@code_voyager&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope you had fun experimenting with the code.&lt;br&gt;
Have an amazing day!&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>python</category>
      <category>jupyter</category>
      <category>beginners</category>
    </item>
    <item>
      <title>OpenCV Basics</title>
      <dc:creator>Jaya chandrika reddy</dc:creator>
      <pubDate>Thu, 07 May 2020 20:43:15 +0000</pubDate>
      <link>https://dev.to/chandrika56/opencv-4815</link>
      <guid>https://dev.to/chandrika56/opencv-4815</guid>
      <description>&lt;p&gt;&lt;em&gt;Want to combine two images using just a line of code? Or wanna blur an image? Lets find out how!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this Article (Click to skip to that topic):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Blend images: What is it?]&lt;/li&gt;
&lt;li&gt;[Code to Blend]&lt;/li&gt;
&lt;li&gt;[Methods to Blur an Image ]&lt;/li&gt;
&lt;li&gt;[Code to Blur Image]&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id="what-is-yaml"&gt; Blend images: What is it? &lt;/h3&gt;

&lt;p&gt;Blending images in opencv, is combining to images of &lt;em&gt;same&lt;/em&gt; size. So we have to remember to resize those two images to same size(which will be shown in the code later).&lt;/p&gt;

&lt;p&gt;Using this, we can make pretty cool posters, wallpapers, beautiful creations in your imaginations and many more...&lt;/p&gt;

&lt;p&gt;So lets learn how to do it in a simple way&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bigarr=np.arange(0, 10).reshape((2,5))
bigarr

#'arange' gives an array withn values from 0 to 9, 'reshapes' converts into a matrix of 2x5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;array([[0, 1, 2, 3, 4],&lt;br&gt;
    [5, 6, 7, 8, 9]])&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bigarr[:, 2]

#Here only column 2 is considered but not row as colon(:) is mentioned
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;array([2, 7])&lt;/p&gt;



&lt;p&gt;For more practice on Numpy visit&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; https://numpy.org/devdocs/user/quickstart.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;## &lt;strong&gt;Display Image in Opencv using Numpy&lt;/strong&gt;    &lt;/p&gt;

&lt;p&gt;Now,how to open or show an image using our numpy knowledge:&lt;/p&gt;

&lt;p&gt;We use libraries &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;PIL(Python Imaging Library)&lt;/em&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Matplotlib( For visualization)&lt;/em&gt; and import Image from PIL&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;Image.open(image file path)       

# Opens and identifies the given image file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Each pixel has a shape.&lt;br&gt;&lt;br&gt;
For Eg:(1080,1080,3)which is (pixel height,pixel width,color channels)&lt;br&gt;
The 3 color channels are &lt;em&gt;red,green&lt;/em&gt; and &lt;em&gt;blue&lt;/em&gt;(RGB).&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.imshow                         

# Displays the image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Example&lt;/strong&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import matplotlib.pyplot as plt 
%matplotlib inline
from PIL import Image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;img=Image.open(r'C:\Desktop\image.jpg') 

# Opens Image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;img

#To Preview Image
&lt;/code&gt;&lt;/pre&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4c91ashgm0y69g7d7lqo.JPG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4c91ashgm0y69g7d7lqo.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each pixel has a shape.&lt;br&gt;&lt;br&gt;
For Eg:(1080,1080,3) which is (pixel height,pixel width,color channels).&lt;br&gt;&lt;br&gt;
The 3 color channels are red,green and blue(RGB).&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.imshow             

# Displays the image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;br&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;img_array=np.asarray(img)

# Converting image into array of values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;img_array.shape

# Displaying the shape of the array
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:    &lt;/p&gt;

&lt;p&gt;(1080,1920,3) &lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.imshow(img_array)

# Displaying array into Image  
&lt;/code&gt;&lt;/pre&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh6wjgqx60g7s0kwzznkh.JPG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh6wjgqx60g7s0kwzznkh.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if only one channel is used in displaying image instead all 3 in RGB?  &lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.imshow(array[:,:,0])           # Displays image with only Red channel.

plt.imshow(array[:,:,1])           # Displays image with only Green channel.

plt.imshow(array[:,:,2])           # Displays image with only Blue channel.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;## &lt;strong&gt;Gray Image using Numpy&lt;/strong&gt;   &lt;/p&gt;

&lt;p&gt;What if we want a gray image like in old movies?&lt;/p&gt;

&lt;p&gt;The parameter &lt;em&gt;cmap=’gray’&lt;/em&gt; is used to convert color images into a gray image.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.imshow(array[:,:,0],cmap=’gray’) 

# Displays image with grayscale values.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.imshow(img_array[:,:,0])

#Displaying only RED channel in RGB. Replace 0 with 1 for Green and 2 for Blue Channel. 
&lt;/code&gt;&lt;/pre&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh8kz628bltzmzi44wp5h.JPG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh8kz628bltzmzi44wp5h.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.imshow(img_array[:,:,0],cmap='gray')

#Converting the color image into grayscale using cmap
&lt;/code&gt;&lt;/pre&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgdp39vgo9aiu5e9vdyfn.JPG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgdp39vgo9aiu5e9vdyfn.JPG" alt="Alt Text"&gt;&lt;/a&gt;     &lt;/p&gt;

&lt;p&gt;For more code on fliping, resizing etc visit the blog, follow the Instagram page mentioned below 😄&lt;/p&gt;

&lt;p&gt;If you are building a project or wanna upgrade your skills for the job or just excited to build cool stuff, learn opencv easily and quickly from Instagram page code_voyager:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.instagram.com/p/B_5ey22pLu_/?igshid=1t6k2adh9a9zk" rel="noopener noreferrer"&gt;https://www.instagram.com/p/B_5ey22pLu_/?igshid=1t6k2adh9a9zk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or more detailed version feel free to visit 😄:&lt;br&gt;
&lt;a href="https://jayachandrika.com/computer-vision-images" rel="noopener noreferrer"&gt;https://jayachandrika.com/computer-vision-images&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking forward for you to join us!😊&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>python</category>
      <category>codepen</category>
      <category>jupyter</category>
    </item>
  </channel>
</rss>
