Mastering OpenCV 4 with Python by Fernández Villán Alberto;
Author:Fernández Villán, Alberto;
Language: eng
Format: epub
Tags: COM051360 - COMPUTERS / Programming Languages / Python, COM016000 - COMPUTERS / Computer Vision and Pattern Recognition, COM051010 - COMPUTERS / Programming Languages / General
Publisher: Packt Publishing, Limited
Published: 2019-03-28T10:26:14+00:00
As you can see, in the upper part of the screenshot the original image is shown, while in the bottom part of the screenshot the original image has been modified to include the ordering number in the center of each contour.
Recognizing contours
We have previously introduced cv2.approxPolyDP(), which can be used to approximate one contour with another with fewer points using the Douglas-Peucker algorithm. A key parameter in this function is epsilon, which sets the approximation accuracy. In contours_shape_recognition.py, we will make use of cv2.approxPolyDP() in order to recognize the contours (for example, triangle, square, rectangle, pentagon, or hexagon, among others) based on the number of detected vertices in the decimated contour (the output of cv2.approxPolyDP()). In order to decimate the number of points, given a certain contour, we first compute the perimeter of the contour. Based on the perimeter, the epsilon parameter is established. This way, the decimated contour is invariant to scale. The epsilon parameter is calculated as follows:
epsilon = 0.03 * perimeter
The constant 0.03 is established after several tests. For example, if this constant is bigger (for example, 0.1), the epsilon parameter will also be bigger and, hence, the approximation accuracy will be decreased.
This results in a contour with fewer points, and missing vertices are obtained. Therefore, recognition of the contours is performed incorrectly because it is based on the number of detected vertices. On the other hand, if this constant is smaller (for example, 0.001), the epsilon parameter will also be smaller and, hence, the approximation accuracy will increased, resulting in an approximation contour with more points. In this situation, the recognition of the contours is also performed incorrectly because false vertices are obtained.
The output of the contours_shape_recognition.py script can be seen in the next screenshot:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Computer Vision & Pattern Recognition | Expert Systems |
Intelligence & Semantics | Machine Theory |
Natural Language Processing | Neural Networks |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8293)
Test-Driven Development with Java by Alan Mellor(6665)
Data Augmentation with Python by Duc Haba(6568)
Principles of Data Fabric by Sonia Mezzetta(6330)
Learn Blender Simulations the Right Way by Stephen Pearson(6215)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6088)
Hadoop in Practice by Alex Holmes(5958)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
RPA Solution Architect's Handbook by Sachin Sahgal(5482)
Big Data Analysis with Python by Ivan Marin(5331)
The Infinite Retina by Robert Scoble Irena Cronin(5182)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5140)
Pretrain Vision and Large Language Models in Python by Emily Webber(4292)
Infrastructure as Code for Beginners by Russ McKendrick(4051)
Functional Programming in JavaScript by Mantyla Dan(4037)
The Age of Surveillance Capitalism by Shoshana Zuboff(3943)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3766)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3568)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3543)
