Elc Report
Elc Report
Detection and
Recognition using
Python in Image
Processing
An ELC activity report submitted in partial fulfilment of the requirements
for the degree of
Bachelor of Engineering
in
February-April 2024
Objective-> The objective of this project is to develop a Python
program that can identify and classify basic geometric shapes such
as circles, squares, triangles, and rectangles within an image.
(Geometrical Shape Detection and Recognition using Python
in Image Processing.)
Introduction->
Geometrical shape detection and recognition represent a
fundamental aspect of computer vision and image processing, with
wide-ranging applications across various industries and fields. From
automated quality control in manufacturing to object detection in
robotics and autonomous vehicles, the ability to identify and classify
geometric shapes within images is indispensable.
The significance of geometrical shape detection lies in its utility for
understanding and interpreting visual data. By analysing the spatial
arrangement of pixels in an image, algorithms can infer the
presence of distinct geometric structures, enabling automated
systems to make informed decisions based on visual inputs. This
capability finds applications in numerous domains, including
industrial automation, medical imaging, surveillance, and
augmented reality.
This project aims to delve into this crucial aspect of image
processing by developing a Python program capable of detecting
and recognizing basic geometric shapes, such as circles,
squares, triangles, and rectangles, within a given image.
The process of shape detection and recognition typically involves
several key steps. Initially, the input image is pre-processed to
enhance relevant features and reduce noise. This preprocessing
may include operations such as grayscale conversion,
smoothing, and thresholding. Subsequently, contours are
extracted from the processed image, representing the boundaries of
distinct objects or shapes present in the scene. These contours are
then analysed and classified based on their geometric properties,
such as the number of vertices, angles, and aspect ratios.
In this project, we will utilize the OpenCV (Open-Source Computer
Vision) library, a powerful tool for image processing and computer
vision tasks in Python, to implement the shape detection and
recognition algorithm. OpenCV provides a rich set of functions and
algorithms for tasks such as image filtering, edge detection, contour
detection, and shape analysis, making it well-suited for our
purposes.
Through this endeavour, we aim to not only develop a functional
shape detection system but also gain insights into the underlying
principles of image processing and computer vision. By
understanding the techniques and algorithms involved, we can
appreciate the intricacies of visual perception and its computational
realization, paving the way for further exploration and innovation in
this fascinating field.
Insertion of
Convert To GRAY
Libraries and Image resize Threshold
SCALE
image.
Set Different
Find and draw Connecntion of Dilation on
kernel matrices for
Contours over disjoining edges in threshold image
morphologocal
image the shape. output.
operations
Python Code->
Visit the following link to access the code-
https://colab.research.google.com/drive/
1tDsN_LDg9Eg8A4UqlMj7GQOe-w7nIvsg?usp=drive_link
The same code is also pasted in blocks as follows-
import cv2 #iporting computer vision libraries
import PIL #python imaging library
import numpy as np #numerical operations
from matplotlib import pyplot as plt
from PIL import Image #Opening, rotating and displaying an image
from matplotlib import image as mpimg #Image read and Image show function
img=Image.open("9.jpeg")
plt.imshow(img)
print(img.format)
print(img.size)
print(img.mode)
img=np.array(img)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
plt.imshow(gray,cmap='gray')
_,threshold=cv2.threshold(gray,110,255,cv2.THRESH_BINARY_INV)
plt.imshow(threshold,cmap='gray')
opening=cv2.morphologyEx(dilated,cv2.MORPH_OPEN,kernelc,iterations=8)
plt.imshow(opening,cmap='gray')
thinned = cv2.ximgproc.thinning(opening)
plt.imshow(thinned,cmap='gray')
dilated_t=cv2.dilate(thinned,kernel,iterations=5)
plt.imshow(dilated,cmap='gray')
i=0
#list for storing names of shapes
for contour in contours:
elif len(approx) == 4:
cv2.putText(img,'Rectangle',(x,y),
cv2.FONT_HERSHEY_SIMPLEX,2,(0,255,0),5)
elif len(approx) == 5:
cv2.putText(img,'Pentagon',(x,y),
cv2.FONT_HERSHEY_SIMPLEX,2,(0,255,255),5)
elif len(approx) == 6:
cv2.putText(img,'Hexagon',(x,y),
cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,0,255),2)
else:
cv2.putText(img,'circle',(x,y),
cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,255),5)
plt.imshow(img)
Learnings->
1. Understanding the basics of image processing techniques like
thresholding, contour detection, and moments calculation.
2. Implementing contour approximation to recognize shapes.
3. Exploring how to determine the shape type based on the
number of vertices and aspect ratio.
4. Gaining practical experience in working with OpenCV library
for image processing tasks.
5. Retrieve Python programming syntax and basic functions
used in image processing libraries like OpenCV.
6. Apply image processing techniques to detect and analyze
geometrical shapes in sample images or datasets.
7. Design and implement customized algorithms for detecting
and recognizing specific types of geometrical shapes in
images.
References->
1. OpenCV Documentation: https://docs.opencv.org/
2. PPT provided on LMS.
3. "Learning OpenCV 4 Computer Vision with Python 3" by
Joseph Howse, Joe Minichino, and Prateek Joshi.
4. "Python Computer Vision" by Jan Erik Solem.