Statistics
4
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-06-27

AuthorMohaideen A, Dr. Kadhar, G. Anand

Today’s industries are faced with a growing demand for vision systems due to their non-invasive characteristics in inspecting product quality. These systems identify surface defects and faults, and verify components’ orientation and their measurements, etc. This book explores the vision techniques needed to design and develop your own industrial vision system with the help of Raspberry Pi. You’ll start by reviewing basic concepts and applications of machine vision systems, followed by the preliminaries of Python, OpenCV, required libraries, and installing OpenCV for Python on Raspberry Pi. These are used when implementing image processing for the system applications. You’ll then look at interfacing techniques and some of the challenges industrial vision systems encounter, such as lighting and camera angles. Algorithms and image processing techniques are also discussed, along with machine learning and deep learning techniques. Later chapters explain the use of GUI apps and real-time applications of Industrial vision systems. Each chapter concludes with examples and demo implementations to facilitate your knowledge of the concepts. By the end of the book, you’ll be able to build and deploy computer vision applications with Python, OpenCV, and Raspberry Pi. What You'll Learn Build and deploy industrial vision system using Raspberry Pi and Python programming Explore computer vision techniques using Raspberry Pi and OpenCV Implement popular vision techniques for industrial applications in real time Review modern image processing techniques such as image segmentation, thresholding, and contours Who This Book Is For Raspberry Pi and Python enthusiasts interested in computer vision applications; educators, industrialists, and industrial solution providers who want to design vision-based testing products with the help of Raspberry Pi

AI Reading Assistant

Summary and highlights from this book's index; jump to passages in the text

Passage locations
Tags
No tags
ISBN: 8868800969
Publisher: Apress
Publish Year: 2024
Language: 英文
Pages: 346
File Format: PDF
File Size: 23.1 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Maker Innovations Series
Jump start your path to discovery with the Apress Maker Innovations series! From the basics of electricity and components through to the most advanced options in robotics and Machine Learning, you’ll forge a path to building ingenious hardware and controlling it with cutting-edge software. All while gaining new skills and experience with common toolsets you can take to new projects or even into a whole new career. The Apress Maker Innovations series offers projects-based learning, while keeping theory and best processes front and center. So you get hands-on experience while also learning the terms of the trade and how entrepreneurs, inventors, and engineers think through creating and executing hardware projects. You can learn to design circuits, program AI, create IoT systems for your home or even city, and so much more! Whether you’re a beginning hobbyist or a seasoned entrepreneur working out of your basement or garage, you’ll scale up your skillset to become a hardware design and engineering pro. And often using low- cost and open-source software such as the Raspberry Pi, Arduino, PIC microcontroller, and Robot Operating System (ROS). Programmers and software engineers have great opportunities to learn, too, as many projects and control environments are based in popular languages and operating systems, such as Python and Linux. If you want to build a robot, set up a smart home, tackle assembling a weather-ready meteorology system, or create a brand-new circuit using breadboards and circuit design software, this series has all that and more! Written by creative and seasoned Makers, every book in the series tackles both tested and leading-edge approaches and technologies for bringing your visions and projects to life. More information about this series at https://link.springer.com/ bookseries/17311.
Industrial Vision Systems with Raspberry Pi Build and Design Vision products Using Python and OpenCV K. Mohaideen Abdul Kadhar G. Anand
Industrial Vision Systems with Raspberry Pi: Build and Design Vision products Using Python and OpenCV ISBN-13 (pbk): 979-8-8688-0096-2 ISBN-13 (electronic): 979-8-8688-0097-9 https://doi.org/10.1007/979-8-8688-0097-9 Copyright © 2024 by K. Mohaideen Abdul Kadhar and G. Anand This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsi- bility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Miriam Haidara Development Editor: James Markham Editorial Project Manager: Jessica Vakili Cover designed by eStudioCalamar Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress.com/gp/ services/source-code. If disposing of this product, please recycle the paper K. Mohaideen Abdul Kadhar Centre for Computational Imaging and Machine Vision, Dept of Electronics & Communication, Sri Eshwar College of Engineering, Coimbatore, Tamil Nadu, India G. Anand ML Analyst Vismaya Infotech Solutions Trivandrum, Kerala, India
To my dear father, Your unwavering support, unconditional love, and wisdom have been my guiding light. Even though you are no lon- ger with us, your presence is felt in every page of this book. Thank you for believing in me and inspiring me to pursue my dreams. This book is dedicated to you, with all my love. Forever in my heart, —Dr. K. Mohaideen Abdul Kadhar To my parents, who have always stood by me and whose steadfast love and guidance have brightened every chapter of my life's journey. I will forever be grateful for all that you have done and continue to do for me. —G. Anand
vii About the Authors ������������������������������������������������������������������������������xiii About the Technical Reviewer ������������������������������������������������������������xv Acknowledgments ����������������������������������������������������������������������������xvii Introduction ���������������������������������������������������������������������������������������xix Chapter 1: Introduction to Industrial Vision Systems ���������������������������1 Introduction to Computer Vision ����������������������������������������������������������������������������2 Industrial Vision Systems ��������������������������������������������������������������������������������������4 Steps Involved in Industrial Vision Systems ����������������������������������������������������������8 Summary�������������������������������������������������������������������������������������������������������������10 Chapter 2: Getting Started with Raspberry Pi ������������������������������������13 Raspberry Pi Boards and Pin Details�������������������������������������������������������������������14 Installing OS ��������������������������������������������������������������������������������������������������������17 Installing OpenCV on Raspberry Pi ����������������������������������������������������������������������19 Remote Access with Raspberry Pi ����������������������������������������������������������������������23 Secure Shell (SSH) Protocol ��������������������������������������������������������������������������25 Virtual Network Computing (VNC) ������������������������������������������������������������������26 Interfacing a Camera with Raspberry Pi �������������������������������������������������������������27 Summary�������������������������������������������������������������������������������������������������������������32 Table of Contents
viii Chapter 3: Python Libraries for Image Processing �����������������������������33 IDEs for Python in Raspberry Pi ��������������������������������������������������������������������������33 Thonny �����������������������������������������������������������������������������������������������������������34 Geany �������������������������������������������������������������������������������������������������������������35 IDLE ���������������������������������������������������������������������������������������������������������������36 Python Programming in Raspberry Pi������������������������������������������������������������37 NumPy �����������������������������������������������������������������������������������������������������������43 Python Imaging Library(PIL) ��������������������������������������������������������������������������48 Visualizing Images Using Matplotlib �������������������������������������������������������������������56 Read and Write Images Using OpenCV ����������������������������������������������������������������59 Image Properties in OpenCV ��������������������������������������������������������������������������61 Conversion Between Image Data Types ��������������������������������������������������������������64 Basic Image Operations in OpenCV ���������������������������������������������������������������������67 Capturing the Video Using OpenCV ���������������������������������������������������������������������68 Video Transformations �����������������������������������������������������������������������������������71 Summary�������������������������������������������������������������������������������������������������������������72 Chapter 4: Challenges in Machine Vision System ������������������������������73 Technical Challenges ������������������������������������������������������������������������������������������73 Selecting and Optimizing Suitable Algorithms for Image Processing ������������74 Selecting a Camera Model�����������������������������������������������������������������������������75 Environmental Challenges in Machine Vision System�����������������������������������������78 Integration Challenges ����������������������������������������������������������������������������������������82 Performance Challenges �������������������������������������������������������������������������������������84 Human Factors Challenges ���������������������������������������������������������������������������������85 Summary�������������������������������������������������������������������������������������������������������������86 Table of ConTenTs
ix Chapter 5: Image Processing Using OpenCV ��������������������������������������87 Image Acquisition ������������������������������������������������������������������������������������������������87 Image and Its Properties �������������������������������������������������������������������������������������89 Resolution ������������������������������������������������������������������������������������������������������89 Aspect Ratio ��������������������������������������������������������������������������������������������������90 Color Depth ����������������������������������������������������������������������������������������������������90 Image Size �����������������������������������������������������������������������������������������������������90 Image File Formats ����������������������������������������������������������������������������������������91 Noise �������������������������������������������������������������������������������������������������������������������91 Gaussian Noise ����������������������������������������������������������������������������������������������91 Salt and Pepper Noise �����������������������������������������������������������������������������������92 Speckle Noise ������������������������������������������������������������������������������������������������93 Types of Images ��������������������������������������������������������������������������������������������������94 Binary Images ������������������������������������������������������������������������������������������������94 Grayscale Images ������������������������������������������������������������������������������������������95 Color Images ��������������������������������������������������������������������������������������������������95 Resizing the Images ��������������������������������������������������������������������������������������������97 Image Enhancement �����������������������������������������������������������������������������������������100 Image Negatives ������������������������������������������������������������������������������������������101 Log Transformation ��������������������������������������������������������������������������������������102 Power Law (Gamma) Transformation ����������������������������������������������������������103 Contrast Stretching ��������������������������������������������������������������������������������������105 Edge Detection and Filtering Using OpenCV �����������������������������������������������������108 Mean Filter ��������������������������������������������������������������������������������������������������109 Median Filter �����������������������������������������������������������������������������������������������111 Sobel Filter ��������������������������������������������������������������������������������������������������112 Canny Filter �������������������������������������������������������������������������������������������������113 Case Study: Extracting the Edges of the Gear Teeth ������������������������������������115 Table of ConTenTs
x Morphological Operations with OpenCV ������������������������������������������������������������117 Erosion ���������������������������������������������������������������������������������������������������������118 Dilation ��������������������������������������������������������������������������������������������������������120 Case Study: Morphological Filtering for Noise Removal ������������������������������122 Thresholding Techniques with OpenCV �������������������������������������������������������������125 Binary Thresholding �������������������������������������������������������������������������������������125 Binary Inverse Thresholding ������������������������������������������������������������������������128 Otsu’s Thresholding �������������������������������������������������������������������������������������129 Adaptive Thresholding ���������������������������������������������������������������������������������132 Binary Large Objects (Blob) Detection Using OpenCV ���������������������������������������134 Contours Detection with OpenCV ����������������������������������������������������������������������136 Summary�����������������������������������������������������������������������������������������������������������139 Chapter 6: Graphical User Interface with OpenCV and tkinter����������141 GUIs at a Glance ������������������������������������������������������������������������������������������������141 Tkinter ���������������������������������������������������������������������������������������������������������������143 Label ������������������������������������������������������������������������������������������������������������144 Button ����������������������������������������������������������������������������������������������������������147 Entry ������������������������������������������������������������������������������������������������������������149 Radiobutton �������������������������������������������������������������������������������������������������150 Checkbutton ������������������������������������������������������������������������������������������������151 Messagebox ������������������������������������������������������������������������������������������������153 Toplevel �������������������������������������������������������������������������������������������������������154 Fielddialog and Canvas ��������������������������������������������������������������������������������155 Scale ������������������������������������������������������������������������������������������������������������159 GUI for Industrial Vision System ������������������������������������������������������������������������163 Summary�����������������������������������������������������������������������������������������������������������169 Table of ConTenTs
xi Chapter 7: Feature Detection and Matching �������������������������������������171 Image Features �������������������������������������������������������������������������������������������������171 SIFT Features ����������������������������������������������������������������������������������������������������172 SURF Features ��������������������������������������������������������������������������������������������������175 FAST Features ���������������������������������������������������������������������������������������������������178 BRIEF Features ��������������������������������������������������������������������������������������������������181 ORB Features ����������������������������������������������������������������������������������������������������184 Corner Detection �����������������������������������������������������������������������������������������������186 Line and Shape Detection in Images ����������������������������������������������������������������189 Summary�����������������������������������������������������������������������������������������������������������197 Chapter 8: Image Segmentation �������������������������������������������������������199 Image Segmentation Using Thresholding ���������������������������������������������������������199 Image Segmentation Using Contour Detection �������������������������������������������������203 Image Segmentation Using Watershed Algorithm ���������������������������������������������206 Image Segmentation Using Clustering ��������������������������������������������������������������210 Summary�����������������������������������������������������������������������������������������������������������214 Chapter 9: Optical Character Recognition ����������������������������������������215 Stages of OCR Pipeline �������������������������������������������������������������������������������������216 Image Preprocessing �����������������������������������������������������������������������������������217 Character Segmentation ������������������������������������������������������������������������������219 Character Recognition ���������������������������������������������������������������������������������222 Handwritten Digit Extraction Using kNN �����������������������������������������������������������225 Cloud APIs for OCR ��������������������������������������������������������������������������������������������230 OCR with Google® Cloud Vision API �������������������������������������������������������������231 OCR with Azure Compute Vision API ������������������������������������������������������������240 Table of ConTenTs
xii OCR with Python Libraries ��������������������������������������������������������������������������������248 EasyOCR ������������������������������������������������������������������������������������������������������248 Keras-OCR ���������������������������������������������������������������������������������������������������250 Summary�����������������������������������������������������������������������������������������������������������254 Chapter 10: Machine Learning Techniques for Vision Application ��������������������������������������������������������������������255 Image Preprocessing ����������������������������������������������������������������������������������������256 Machine Learning Algorithms ���������������������������������������������������������������������������258 Artificial Neural Networks (ANN) �����������������������������������������������������������������������261 Convolutional Neural Networks (CNN)���������������������������������������������������������������264 Handwritten Digit Recognition with CNN ����������������������������������������������������������267 Digit Recognition from Test Scripts Using CNN �������������������������������������������������273 Summary�����������������������������������������������������������������������������������������������������������283 Chapter 11: Industrial Vision System Applications ��������������������������285 Interfacing Cameras with a Raspberry Pi ���������������������������������������������������������285 Processing Videos in Raspberry Pi ��������������������������������������������������������������������287 Case Study 11�1: Detecting Thread Quality of a Nut and Bolt ���������������������������289 Case Study 11�2: Identifying Unmatched Components in a Set of Components ��������������������������������������������������������������������������������������������298 Case Study 11�3: Thread Count Detection System ��������������������������������������������306 Case Study 11�4: OCR System for Text Extraction ���������������������������������������������313 Summary�����������������������������������������������������������������������������������������������������������319 Bibliography �������������������������������������������������������������������������������������321 Index �������������������������������������������������������������������������������������������������323 Table of ConTenTs
xiii About the Authors Dr. K. Mohaideen Abdul Kadhar completed his undergraduate degree in Electronics and Communication Engineering in 2005 and his M.Tech with a specialization in Control and Instrumentation in 2009. In 2015, he obtained a Ph.D. in Control System Design using evolutionary algorithms. He has more than 16 years of experience in teaching and research. His areas of interest include computer vision, image processing, data science, optimization techniques, controller design, Python programming, working with Raspberry Pi boards and edge AI. He is currently developing customized industrial vision systems for various industrial requirements. He has been a consultant for several industries in developing machine vision systems for industrial applications, a master trainer, and delivered workshops on computer vision, image processing, optimization techniques, control system, data science, and Python programming.
xiv G. Anand completed his undergraduate degree in Electronics and Communication Engineering in 2008 and his postgraduate degree (M.E.) in Communication Systems in 2011. He has more than 11 years of experience in teaching and research and one year of industrial experience. His areas of interest include signal processing, image processing, vision systems, Python programming, data science, and machine learning. He has also delivered workshops on signal processing, image processing, and Python programming. He is currently working as an ML Analyst at Vismaya Infotech Solutions. abouT The auThors
xv Farzin Asadi received his B.Sc. in Electronics Engineering, his M.Sc. in Control Engineering, and his Ph.D. in Mechatronics Engineering. Currently, he is with the Department of Electrical and Electronics Engineering at the Maltepe University, Istanbul, Turkey. Dr. Asadi has published over 40 international papers and 25 books. He is on the editorial board of seven scientific journals as well. His research interests include switching converters, control theory, robust control of power electronics converters, and robotics. About the Technical Reviewer
xvii Acknowledgments I am deeply grateful to my parents and family for their unwavering support and encouragement throughout this journey. Their belief in me has been my strength. I would like to express my heartfelt gratitude to my wife Mrs. M. Jashima Parveen for her endless patience, incredible support, and understanding throughout this journey. Her unwavering belief in me, even when I doubted myself, has been my pillar of strength. Her patience, love, and encouragement have been instrumental in making this book a reality. I am truly blessed to have her by my side. I would like to express my sincere thanks to the principal and management of Sri Eshwar College of Engineering for their continuous support and encouragement. In particular, I would like to thank Principal Dr. Sudha Mohanram for her visionary leadership and unwavering support in developing the advanced research center "Computational Imaging and Machine Vision." Her continuous support, guidance, encouragement, and belief in my strength have been instrumental in making this book a reality. Her dedication to fostering a culture of innovation and excellence has been truly inspiring. I would like to extend my heartfelt thanks to my coauthor, G. Anand, for his invaluable contributions to this book. His expertise, dedication, and insights have enriched the content and quality of this work. Collaborating with him has been a rewarding experience, and I am grateful for his partnership throughout this journey. My sincere thanks to the Apress team, especially Shobana Srinivasan, James Markham and Jessica Vakili for their patience and support makes to write quality contents of this book. —K. Mohaideen Abdul Kadhar
xviii I thank the almighty for blessing me with this wonderful opportunity to share my knowledge. I thank my parents and my sister for their endless love, support, and encouragement. I am grateful to my company Vismaya Infotech Solutions for allowing me to pursue this project while continuing my responsibilities within the organization. I am thankful to the management for fostering a culture of growth and empowerment providing opportunities for both personal and professional development. I am deeply indebted to my coauthor Dr. K. Mohaideen Abdul Kadhar for continuously encouraging and pushing me to bring out the best in me. His constant guidance and domain expertise have helped me a great deal in developing quality content for this book. I am filled with gratitude to have worked alongside him in this journey. I would like to express my sincere thanks to Shobana Srinivasan from the Apress team for being patient with us and ensuring that the project stayed on track despite some unanticipated delays from our end. Finally, I’d like to extend my thanks to the James Markham and Jessica Vakili for their timely and valuable comments that have helped us to deliver quality content. —G. Anand aCknowledgmenTs
xix Introduction In recent years, there has been a significant demand for vision systems in industries due to their noninvasive nature in inspecting product quality. Industrial vision systems can be developed for various applications such as identifying surface defects and faults, verifying component orientation and measurements, and more. Modern image processing techniques like image segmentation, thresholding, contours, feature extraction, object detection, image analysis, and frame analysis can be utilized to create real- time vision systems for quality checks in industries. This book demonstrates the implementation of industrial vision systems in real time using Raspberry Pi. It is designed to be helpful for graduate students, research scholars, and entry-level vision engineers. The book begins with an introductory chapter that provides readers with an overview of such systems. The second chapter introduces readers to Raspberry Pi hardware, guiding them through OS installation and camera setup with practical demonstrations in Python software. Chapter 3 helps readers learn and practice essential Python libraries for handling images and videos. Chapter 4 covers the challenges involved in developing standard industrial vision systems, including the choice of cameras, their placement, and required lighting conditions. Chapter 5 provides a detailed overview of fundamental image processing techniques, starting with basic concepts like image properties and types, and progressing to advanced image operations like filtering, morphological operations, and thresholding.
xx Chapter 6 is dedicated to graphical user interface, offering readers a hands-on experience in developing interactive user interfaces for vision systems using various widgets offered by the Python tkinter library. Chapter 7 introduces readers to prominent image features like SIFT, SURF, and FAST and demonstrates how they can be extracted from raw images to be used for applications like recognition, segmentation, and matching. Chapter 8 discusses image segmentation techniques, which are crucial for most vision systems, introducing readers to commonly used segmentation techniques for partitioning images into objects or segments. Chapter 9 focuses on optical character recognition (OCR) systems, providing readers with an opportunity to develop such systems using pre- trained APIs from leading cloud service providers and available Python libraries. Chapter 10 discusses machine learning algorithms, which have seen rapid growth due to advancements in computing capacity and memory specifications. It provides a quick introduction to traditional machine learning algorithms followed by a detailed discussion on neural networks, especially convolutional neural networks (CNN) that is commonly used in image and video-based applications. In the final chapter, Chapter 11, readers are given a hands-on experience in developing end-to-end standard industrial vision systems with the Raspberry Pi board using the knowledge accumulated throughout the book. InTroduCTIon
1© K. Mohaideen Abdul Kadhar and G. Anand 2024 K. Mohaideen Abdul Kadhar and G. Anand, Industrial Vision Systems with Raspberry Pi, Maker Innovations Series, https://doi.org/10.1007/979-8-8688-0097-9_1 CHAPTER 1 Introduction to Industrial Vision Systems Modern manufacturing relies on industrial vision systems, which give machines the ability to see and understand their surroundings with previously unheard-of efficiency and precision. These cutting-edge technologies revolutionize quality control and automation processes by converting raw data into insights that can be put into practice. A thorough introduction to industrial vision systems, this book can be considered as a comprehensive guide for students, scholars, and professionals just starting out in the field of computer vision. This book provides both theoretical insights and practical implementation, as it carefully examines the diverse components and cutting-edge techniques essential to vision systems. Readers will get practical experience creating reliable vision systems for industrial use, with an emphasis on using the flexible Raspberry Pi board and Python programming. By the end of this journey, readers will possess the knowledge and capabilities necessary to design and develop efficient vision systems, paving the way for novel ideas and breakthroughs in the area of industrial automation.