AMITY INSTITUTE OF
INFORMATION TECHNOLOGY
KOLKATA
AMITY UNIVERSITY KOLKATA
PROJECT REPORT
ON
SHAPE ANALYSIS OF A SPECTACULAR OBJECT
A report submitted in partial fulfilment of the requirement for the
Bachelor of Computer Applications course (2021-2024) of Amity
University.
Submitted to: Submitted by:
Prof SUPRIYA CHAKRABORTY ARIJIT NANDI
FACULTY GUIDE A91404821041
BCA
PROFESSOR- ACADEMICS (2021-2024)
DECLARATION BY STUDENT
I ARIJIT NANDI, student of BCA hereby declare that the
project titled “Shape Analysis of a Spectacular Object”
which is submitted by me to the department of Amity
Institute of Information Technology, Amity University
Kolkata, in partial fulfilment of requirement for the award of
the degree of BCA, has not been previously formed the basis
for the award of any degree, diploma or other similar title or
recognition.
The author attests that permission has been obtained for the
use of any copyrighted material appearing in the report other
than brief excerpts requiring only proper acknowledgement in
scholarly writing and all such use is acknowledged.
Signature:
Date:
CERTIFICATE
On the basis of report submitted by ARIJIT NANDI, student
of BCA, I hereby certify that the report “Shape Analysis of a
Spectacular Object” which is submitted to department
Amity Institute of Information Technology, Amity
University Kolkata in partial fulfilment of requirement for
the award of the degree of BCA is an original contribution
with existing knowledge and faithful record of work carried
out by him/her under my guidance and supervision. To the
best of my knowledge this work has not been submitted in
part or full for any Degree or Diploma to this University or
elsewhere.
Date:
Name of Guide:
Designation Department of
(Faculty Guide):
ACKNOWLEDGEMENT
I express my sincere gratitude to my faculty guide Prof.
SUPRIYA CHAKRABORTY, for his able guidance, continuous
support, and cooperation throughout my project, without
which the present work would not have been possible. My
endeavour stands incomplete without dedicating my
gratitude to him; he has contributed a lot towards successful
completion of my project work.
I would also like to express my gratitude to my family, friends
for their unending support and tireless effort that kept me
motivated throughout the completion of this project.
Yours Sincerely
ARIJIT NANDI
BCA (2021-2024)
TABLE OF CONTENTS
Topics
ABSTRACT
INTRODUCTION
METHODOLOGY
RESULT
CONCLUSION
REFERENCES
ABSTRACT
We can analyse any shape of an object through two
main steps. The steps are:
(1) the extraction of image components of the
target (e.g., area, boundary, network pattern
and skeleton),
(2) the description of the shape features (e.g., size,
perimeter, circularity, and compactness).
But we can also analyse the shape of a spectacular
object through a programming language called Python
using OpenCV.
INTRODUCTION
Analysing shape of a spectacular object can be done by
python using OpenCV.
To detect forms, objects, language, and other features in
photos and movies, OpenCV is a free open-source
library. Python is primarily used with it. We'll look at
how to identify shapes in images in this tutorial. We
will use the OpenCV function cv2.findContours() for
this as well as cv2.drawContours() to draw edges on
images. A contour is a shape's outline or boundaries.
METHODOLOGY
Approach
Import module
Import image
Convert it to grayscale image
Apply thresholding on image and then find out contours.
Run a loop in the range of contours and iterate through it.
In this loop draw a outline of shapes (Using drawContours() ) and
find out center point of shape.
Classify the detected shape on the basis of a number of contour points
it has and put the detected shape name at the center point of shape.
Function Used
cv2.findContours(): Basically, this method find outs all the boundary
points of shape in image.
Syntax: cv2.findContours(src, contour_retrieval,
contours_approximation)
Parameters:
src: input image n-dimensional (but for in our example we are going
to use 2 dimensional image which is
mostly preferred.)
contour_retrieval:
cv.RETR_EXTERNAL:retrieves only the extreme outer contours
cv.RETR_LIST:retrieves all of the contours without establishing any
hierarchical relationships.
cv.RETR_TREE:retrieves all of the contours and reconstructs a full
hierarchy of nested contours.
contours_approximation:
cv.CHAIN_APPROX_NONE: It will store all the boundary points.
cv.CHAIN_APPROX_SIMPLE: It will store number of end
points(eg.In case of rectangle it will store 4)
Return value: list of contour points
cv2.drawContours() : This method draws a contour. It can also draw a
shape if you provide boundary points.
Syntax: cv.DrawContours(src, contour, contourIndex, colour,
thickness)
Parameters:
src: n dimensional image
contour: contour points it can be list.
contourIndex:
-1:draw all the contours
To draw individual contour we can pass here index value
color:color values
thickness: size of outline
CODE:
INPUT:
import cv2
import numpy as np
from matplotlib import pyplot as plt
# reading image
img = cv2.imread('shapes.png')
# converting image into grayscale image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# setting threshold of gray image
_, threshold = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
# using a findContours() function
contours, _ = cv2.findContours(
threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
i=0
# list for storing names of shapes
for contour in contours:
# here we are ignoring first counter because
# findcontour function detects whole image as shape
if i == 0:
i=1
continue
# cv2.approxPloyDP() function to approximate the shape
approx = cv2.approxPolyDP(
contour, 0.01 * cv2.arcLength(contour, True), True)
# using drawContours() function
cv2.drawContours(img, [contour], 0, (0, 0, 255), 5)
# finding center point of shape
M = cv2.moments(contour)
if M['m00'] != 0.0:
x = int(M['m10']/M['m00'])
y = int(M['m01']/M['m00'])
# putting shape name at center of each shape
if len(approx) == 3:
cv2.putText(img, 'Triangle', (x, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.6,
(255, 255, 255), 2)
elif len(approx) == 4:
cv2.putText(img, 'Quadrilateral', (x, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.6,
(255, 255, 255), 2)
elif len(approx) == 5:
cv2.putText(img, 'Pentagon', (x, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.6,
(255, 255, 255), 2)
elif len(approx) == 6:
cv2.putText(img, 'Hexagon', (x, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.6,
(255, 255, 255), 2)
else:
cv2.putText(img, 'circle', (x, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.6,
(255, 255, 255), 2)
# displaying the image after drawing contours
cv2.imshow('shapes', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
RESULT
The output of the code above is:
CONCLUSION
In this project, we present a shape-based
object classification and recognition approach
through Python coding language using
OpenCV. The main idea is that the shape of an
object can be effectively and efficiently by
Python.
We also learn that how can we achieve the
shape analysis of a spectacular object using a
simple code.
REFERENCES
www.geeksforgeeks.org
www.javapoint.com
www.wikipedia.org