<?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>Forem: Matt Payne</title>
    <description>The latest articles on Forem by Matt Payne (@mattpayne).</description>
    <link>https://forem.com/mattpayne</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%2F577909%2F27496b1f-c2fe-43be-94ce-038f92f0b631.jpg</url>
      <title>Forem: Matt Payne</title>
      <link>https://forem.com/mattpayne</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mattpayne"/>
    <language>en</language>
    <item>
      <title>Convert A Pandas Dataframe With String of Dict To Columns</title>
      <dc:creator>Matt Payne</dc:creator>
      <pubDate>Sun, 02 May 2021 23:48:37 +0000</pubDate>
      <link>https://forem.com/mattpayne/convert-a-pandas-dataframe-with-string-of-dict-to-columns-4gh8</link>
      <guid>https://forem.com/mattpayne/convert-a-pandas-dataframe-with-string-of-dict-to-columns-4gh8</guid>
      <description>&lt;h2&gt;
  
  
  Let's take a look at how we can convert a string column where the data is in a dictionary format to pandas dataframe columns.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Read In Data
&lt;/h2&gt;

&lt;p&gt;We're going to read in a csv and display our column with data. Pandas will display this column as an object, and we can't access the values in the dictionary as the row element is actually a string.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fPLRpQz---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huzs1b6rqvx710te249q.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fPLRpQz---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huzs1b6rqvx710te249q.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using AST To Evaluate Strings
&lt;/h2&gt;

&lt;p&gt;Let's use the AST library to transform our string into a python literal, defined &lt;a href="https://docs.python.org/3/library/ast.html#ast.literal_eval"&gt;here&lt;/a&gt;. This allows us to transform our values into dictionaries. We'll use the pandas .apply() function to apply this function to each element in the column.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Normalize Into New Columns
&lt;/h2&gt;

&lt;p&gt;Using the pandas function json_normalize, we can convert our dictionary values into columns in a new dataframe, which we will merge into the orginal later. You don't have to set the json_normalize output to a new dataframe, I just like how it comes out.&lt;/p&gt;

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

&lt;p&gt;We now have a new dataframe with the columns being the key and value pairs from our dictionary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combining Data
&lt;/h2&gt;

&lt;p&gt;Once you have your new columns, you can either set them back to columns in the original dataframe or merge them into a larger dataframe using &lt;a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html"&gt;pd.merge()&lt;/a&gt;.&lt;/p&gt;

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

&lt;h1&gt;
  
  
  Love Pandas &amp;amp; Data Structures?
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Read some more of our pandas guides to be a better data scientist.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.scalr.ai/pandas/normalize-column-pandas-dataframe"&gt;&lt;strong&gt;Normalize Columns In A Pandas Dataframe&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scalr.ai/pandas/pandas-dataframe-filter-multiple-conditions"&gt;&lt;strong&gt;Filter A Pandas Dataframe On Multiple Conditions&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>data</category>
      <category>pandas</category>
    </item>
    <item>
      <title>3 Image Processing Techniques For Building Enterprise Level 1D &amp; 2D Barcode Scanning Software</title>
      <dc:creator>Matt Payne</dc:creator>
      <pubDate>Tue, 23 Feb 2021 19:24:38 +0000</pubDate>
      <link>https://forem.com/mattpayne/3-image-processing-techniques-for-building-enterprise-level-1d-2d-barcode-scanning-software-413f</link>
      <guid>https://forem.com/mattpayne/3-image-processing-techniques-for-building-enterprise-level-1d-2d-barcode-scanning-software-413f</guid>
      <description>&lt;h3&gt;
  
  
  Image processing and computer vision techniques we’ve used to build high end custom barcode scanning software along with label readers for small business automation.
&lt;/h3&gt;

&lt;p&gt;Barcode scanning and reading is a sector of computer vision problems that rarely has a straightforward and direct solution. Lots of things including brightness, image clarity, image contrast, and barcode length relative to the image can cause your software to have issues that are tricky to solve. Many industries can see insane cost and labor hours reductions by using these same techniques to build automation systems for your business. We’ve compiled a few techniques we’ve seen great success with to build custom solutions for pretty noisy images and videos. If you want to see a real world business tool using these techniques and getting results, check out this case study where we used &lt;a href="https://www.scalr.ai/inventory-automation-computer-vision"&gt;barcode scanning software&lt;/a&gt; and computer vision to completely automate a backend system for an online retailer (along with other ML tools).&lt;/p&gt;

&lt;h1&gt;
  
  
  Extracting Horizontal &amp;amp; Extreme Vertical Lines With Morphology
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w6dEgOFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eewuvcjjezhhh3bsyk8n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w6dEgOFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eewuvcjjezhhh3bsyk8n.jpg" alt="extracting horizontal lines"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When reading noisy 1D barcodes off images, this might be the most important technique available. By using the erode and dilate morphology operations, we can simply remove any large horizontal lines from the image, which is very useful for lines around the barcode or lines that run into the barcode from the sides. You can see a nice example with images and code &lt;a href="https://stackoverflow.com/questions/46274961/removing-horizontal-lines-in-image-opencv-python-matplotlib"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Example Using Musical Notes - Orginal Image&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1mgJQ5Bk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqv2jhf0cm1u46as85q7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1mgJQ5Bk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqv2jhf0cm1u46as85q7.png" alt="Muscial Notes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Horizontal Lines detected by OpenCV Library&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TzOGDo_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9ha2a0remok3w7vjzt6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TzOGDo_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9ha2a0remok3w7vjzt6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lines removed, image does have gaps after removing (not shown), but we can use a vertical kernel function to repair the lines&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ATdhS2rN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szoad1p9b5mqq0y9atb4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ATdhS2rN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szoad1p9b5mqq0y9atb4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On top of this, you can create a “vertical structuring element”, which defines the min or max size for a vertical line to be removed from an image as well. This is an important step, as it allows us to remove large vertical lines around the barcode, which in certain noisy images could be detected as part of the barcode. In the image above we can see a few examples of vertical space that could be confused as part of the barcode at certain sideways angles, especially the middle barcode with perforated space next to it. OpenCV has a great example of removing these lines using morphology operations &lt;a href="https://docs.opencv.org/3.4/dd/dd7/tutorial_morph_lines_detection.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This image processing technique has worked wonders for us when building systems for automating warehouses and the supply chain industry. Labels on inventory, like boxes and building supplies that contain a barcode can be difficult to read because of the amount of information that supply labels can contain.       &lt;/p&gt;

&lt;h1&gt;
  
  
  Removing Colors BEFORE Grayscaling Images
&lt;/h1&gt;

&lt;p&gt;One of the early steps many add to their 1d &amp;amp; 2d barcode reading software is grayscaling the image, in the idea of removing colors to make the barcode easier to read. While the thought process for this isn’t that bad, grayscaling the image in the beginning is not a good idea. Barcodes are black, and sometimes a dark gray, which means they are already one of if not the darkest objects in images in videos. What can happen is colors like dark red or dark blue around the barcode can be grayscaled into the same color as the barcode, causing huge issues when trying to detect the bounds of the real barcode. What can happen is the dark colors will change to black or dark grey and now be impossible to tell apart from the barcode itself, especially if trying to draw bounding boxes around barcodes. &lt;/p&gt;

&lt;p&gt;Instead of this, let's &lt;strong&gt;remove the colors&lt;/strong&gt; before manipulating the image:     &lt;/p&gt;

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

&lt;p&gt;In this example from one of our projects, we are looking to remove the color red by converting it to white from a Pillow Image object that gets passed in. By comparing the values of the r,g,b to the range of values for the color red, it allows us to remove any shade that could be in the image. We’ve seen this concept work especially great when building barcode systems for inventory management, given you can remove the product color that surrounds the barcode. &lt;/p&gt;

&lt;h1&gt;
  
  
  Use OCR to Read any Numbered Barcode
&lt;/h1&gt;

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

&lt;p&gt;Testing your barcode reading software against many different labels and angles is the best way to ensure you reach results with high correctness. One of the things we noticed during quality testing was we had more frequent errors with barcodes where the label exists in an outdoor or construction environment. Barcodes become faded, ripped, and torn which makes it impossible to read, even if we have a good process for isolating the barcode. &lt;br&gt;
The strategy we’ve seen work to improve these testing results is using OCR to see if we can identify and read the barcode number off a label instead. Many times if we can identify that a barcode exists but we are just unable to read it, it is possible to identify the barcode number and process it through a barcode library.    &lt;/p&gt;

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

&lt;p&gt;While OCR algorithms will usually take longer than most barcode libraries, this can be a great last step alternative when you simply cannot read the barcode. The hidden bonus to this OCR implementation is it integrates nicely with any larger scale computer vision for automation systems, which is normally how barcode and QR code scanning systems are used as a piece of the whole puzzle. If you’re thinking about building a tool for complete automating with computer vision, both of these algorithms will probably be a part of your process.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final Tips &amp;amp; Tricks For Better Barcode Software
&lt;/h1&gt;

&lt;p&gt;Something useful to keep in mind if you or your team is struggling with getting A+ results when testing your new tools, understand the importance of normalizing the viewing of a barcode. The more noise you can remove without overfitting your reader the higher chance you’ll have of being successful. Sometimes you can crop closer around the barcode before reading it, using an object detection library before you read, allowing that barcode to be a higher percentage of the image and removing most of the noise. Sometimes you’ll just find your barcode is simply too small relative to the image and can cause problems differentiating the lines or squares of the barcode.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Using Your Barcode Reader In Other Spaces
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C42b2ZK_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9xdhgnumoanj21w62v5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C42b2ZK_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9xdhgnumoanj21w62v5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
One of the more interesting benefits to building a tool like this is the data you can capture alongside the software running. Creating systems to grab data from your barcode scanner can result in you collecting higher-level data, or data built that takes in multiple lower-level data points to be created. Normally this data is difficult to generate and find, which means it can produce pretty high ROIs for other systems. Given this data is generated from models your competition might not have, it can be used easily to gain an advantage. These &lt;a href="https://www.scalr.ai/post/data-capture-services"&gt;data capture services&lt;/a&gt; are normally simple to build and can produce great returns down the line. &lt;/p&gt;

&lt;p&gt;Hopefully, you find some of these techniques useful in your journey to building the best barcode scanning and detection software you can. We’ve used these same steps to build custom 1d &amp;amp; 2d barcode reading software for small businesses, everything from online retailers to warehousing and supply companies, so we know this can work for you too.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>machinelearning</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>A Simple Introduction to OpenCV With Real-World Business Examples</title>
      <dc:creator>Matt Payne</dc:creator>
      <pubDate>Fri, 12 Feb 2021 01:17:32 +0000</pubDate>
      <link>https://forem.com/mattpayne/a-simple-introduction-to-opencv-with-real-world-business-examples-ekd</link>
      <guid>https://forem.com/mattpayne/a-simple-introduction-to-opencv-with-real-world-business-examples-ekd</guid>
      <description>&lt;p&gt;Let’s take a look at one of the most popular and flexible computer vision libraries on the market, and some real work examples of these tools in action. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://opencv-python-tutroals.readthedocs.io/en/latest/index.html" rel="noopener noreferrer"&gt;OpenCv&lt;/a&gt; has been one of the most used computer vision libraries for quite some time now. It’s incredibly popular and has lots of flexible classes and functions that allow you to easily customize your solution. When you are planning any computer vision project its a great idea to start with OpenCV and see what you can use right out of the box. In this article I will gently introduce you to the basics of the library as well as show you some real-world examples using OpenCV.&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%2Fbwo3z7f4tzqqg9hace61.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%2Fbwo3z7f4tzqqg9hace61.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading an Image With OpenCV
&lt;/h2&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%2Fv0pwi53j7kwi37xeuxf3.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%2Fv0pwi53j7kwi37xeuxf3.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s start with just reading an image by the path to where the image is, then printing out the height and width. There's a few alternate versions of this function, each of which allows you to read images differently. &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%2F4bdgd9lbj5ph19cytk71.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%2F4bdgd9lbj5ph19cytk71.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Extracting the RGB values of a pixel with OpenCV
&lt;/h2&gt;

&lt;p&gt;Now we want to extract the RGB values of a single pixel, but notice the colors are read in with BGR order in OpenCV, so the first value will always be blue not red. &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%2Fdfvl9pvfs7kb6s0frjta.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%2Fdfvl9pvfs7kb6s0frjta.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resizing an image with OpenCV
&lt;/h2&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%2Fberm316tngt5yf4p1d0n.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%2Fberm316tngt5yf4p1d0n.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a problem with this approach to resizing images, the aspect ratio of the image is not maintained when giving raw dimensions to resize. We must do a little extra math to insure a proper aspect ratio.&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%2Fuhrpeflr893932l8npjj.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%2Fuhrpeflr893932l8npjj.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Rotating an image with OpenCV
&lt;/h2&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%2Fsj8kklij7bfe1ubp8zdr.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%2Fsj8kklij7bfe1ubp8zdr.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's alot going on in rotating an image, so let's break it down. &lt;/p&gt;

&lt;p&gt;getRotationMatrix2D()&lt;br&gt;
The three arguments it takes in are center, angle, and the scale. The center is the center coordinates of the image. Angle is simply the angle in degrees that we would like to rotate the image counterclockwise. The scale is simply the scaling factor. It returns a 2x3 matrix that has the values derived from alpha and beta. Alpha being scale * cos(angle) and beta being scale * sine(angle)&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%2Fs9dwj6rlcji4nzv5sgcp.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%2Fs9dwj6rlcji4nzv5sgcp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;warpAffine()&lt;br&gt;
The function warpAffine transforms the original image using the rotation matrix. &lt;/p&gt;

&lt;p&gt;A few tips: &lt;br&gt;
Another way to get the center of the image is something that looks like this, where we use a NumPy array.&lt;br&gt;&lt;br&gt;
If you want to rotate the image with easier degrees such as 180 or 90, you can simply use the .rotate() function and pass easy parameters seen below.&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%2Ft5zx5e4lf89kwpee46dt.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%2Ft5zx5e4lf89kwpee46dt.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Drawing a Rectangle or Bounding Box OpenCV
&lt;/h2&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%2Fb9st5ehde7mpa9ebdsjt.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%2Fb9st5ehde7mpa9ebdsjt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The function takes in a few parameters, which are listed under the code.&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%2Flf9nkm4h8m8v44yszvqu.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%2Flf9nkm4h8m8v44yszvqu.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Real World Projects &amp;amp; Tools Using OpenCV
&lt;/h1&gt;

&lt;p&gt;Let’s take a look at a few real world examples of OpenCV being used to give you an idea of the different applications this incredible tool can be used for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extract and remove horizontal or vertical lines from images
&lt;/h2&gt;

&lt;p&gt;This image processing technique used to remove horizontal or vertical lines has a ton of real world use cases. Using a few cv2 functions like erode and dilate we can identify and remove any sized horizontal and vertical lines from an image. You’ll see this used in product label readers along with &lt;a href="https://hackernoon.com/3-image-processing-techniques-for-building-barcode-scanning-software-x04r31w5" rel="noopener noreferrer"&gt;1D &amp;amp; 2D barcode scanning software.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Edge Detection Projects
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://towardsdatascience.com/simple-edge-detection-model-using-python-91bf6cf00864" rel="noopener noreferrer"&gt;Finding the edges of objects&lt;/a&gt; in images can be a challenging and exciting project for someone looking to see quick results with openCV. Detecting edges is extremely useful for predicting the size of objects or the distance between you and the object you see. You can also include this library in video feeds to automatically move objects closer or farther away from a target.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.scalr.ai/post/inventory-automation-computer-vision" rel="noopener noreferrer"&gt;Inventory Management and Automated Product Listing&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In that article linked above, the product shown as an example uses object detection and barcode reading to automate listing custom products on a website as the product photos are taken and uploaded. The computer vision figures out what product is shown in the image and automatically builds the title and description, along with handling all the backend management needed to run an online retailer. &lt;/p&gt;

&lt;h2&gt;
  
  
  Capturing data and building datasets
&lt;/h2&gt;

&lt;p&gt;Using tools like object detection libraries in OpenCV allow you to &lt;a href="https://www.scalr.ai/post/data-capture-services" rel="noopener noreferrer"&gt;build data capturing services&lt;/a&gt; that extract data from normal business operations and can be converted into high ROI datasets. Businesses can learn things like customer satisfaction from facial recognition tools, what users care about on a website landing page using heatmaps, and much more.&lt;/p&gt;

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