CG MINI PROJECT
“SHAPES DETECTION
OPENCV”
BY: 1) SAKET RAJ SINGH
2)RAMAJAN ALLABHAKSH TAHASHILDAR
USN: 1)2JI21CS038
2)2JI21CS032
OPENCV
• OpenCV stands for open-source computer vision.
• It is basically a powerful and reliable library for performing image processing and
computer vision tasks.
• A library in programming refers to a package of pre-defined functions.
• This library is popular for its easiness and performance.
• This library is available for python and other languages.
• Some of the common tasks that it does is face detection, image processing, shape
detection and so on.
OpenCV-prerequisites
• The key feature in python version of OpenCV is that the functions are obvious. This
means that the meaning of the function is known from the name of the function.
• OpenCV in python language is known as cv2. This is the name of the library we have use.
• This library is not pre-installed in IDE. Hence it is essential to install the library we have
use.
• Windows-> Search bar-> Command prompt-> Run as administrator.
• After this, pip install opencv-python.
• OpenCV is installed in the system.
Basic functions with images
• Since the library is installed in the system, we can use them by simply importing them by
the command import cv2.
• So now we can do many things on images. But before that it is essential to load/read the
image in the IDE.
• This is done by imread function.
• cv2.imread(image filename, mode).
• This is the syntax for the imread function, and the role is obvious, it is going to read the
image from the system to the IDE.
Image extensions
• PNG- (Portable Network Graphics) is a lossless image format widely used for its transparency support and
compression capabilities. It preserves high-quality images without losing detail, making it ideal for web graphics
and digital photography. PNG files are commonly used for logos, icons, and images with sharp edges.
• JPG-JPEG (Joint Photographic Experts Group) is a popular lossy image format known for its efficient
compression of photographs. It reduces file sizes by discarding some image data, leading to some loss of quality.
JPEG files are widely used for web images, digital photography, and graphics where smaller file sizes are
preferred.
• JPEG (Joint Photographic Experts Group) is a widely used image format known for its lossy
compression method that reduces file sizes while maintaining decent image quality. It is suitable for
photographs and web images where smaller file sizes are essential. JPEG files support millions of
colors and are compatible with most devices and platforms.
Modes
• The second argument present in the imread function is the mode.
• This defines the way to read the image.
• cv2.imread_GRAYSCALE is used to read image in black and white format.
• cv2.imread_COLOR is used to read the image in color format.
• The number 0 is read in black & white and 1 to read color.
Displaying an image
• Assuming that we have applied a suited image processing technique over our read image, it is
essential to show the image. We have to display the image on which we have performed our
processing on.
• For this there is a function in OpenCV called as imshow.
• cv2.imshow(“image name”, image)
• The first argument is the name that we want to keep for the image. It is essential that we give
the name within single or double quotes.
• The second argument is the image, this is the image which has been read by the imread
function.
• We can store the read image in a temporary variable and then use it in the imshow functions.

Real-Time Shape Detection Using OpenCV and Python for Geometric Object Classification

  • 1.
    CG MINI PROJECT “SHAPESDETECTION OPENCV” BY: 1) SAKET RAJ SINGH 2)RAMAJAN ALLABHAKSH TAHASHILDAR USN: 1)2JI21CS038 2)2JI21CS032
  • 2.
    OPENCV • OpenCV standsfor open-source computer vision. • It is basically a powerful and reliable library for performing image processing and computer vision tasks. • A library in programming refers to a package of pre-defined functions. • This library is popular for its easiness and performance. • This library is available for python and other languages. • Some of the common tasks that it does is face detection, image processing, shape detection and so on.
  • 3.
    OpenCV-prerequisites • The keyfeature in python version of OpenCV is that the functions are obvious. This means that the meaning of the function is known from the name of the function. • OpenCV in python language is known as cv2. This is the name of the library we have use. • This library is not pre-installed in IDE. Hence it is essential to install the library we have use. • Windows-> Search bar-> Command prompt-> Run as administrator. • After this, pip install opencv-python. • OpenCV is installed in the system.
  • 4.
    Basic functions withimages • Since the library is installed in the system, we can use them by simply importing them by the command import cv2. • So now we can do many things on images. But before that it is essential to load/read the image in the IDE. • This is done by imread function. • cv2.imread(image filename, mode). • This is the syntax for the imread function, and the role is obvious, it is going to read the image from the system to the IDE.
  • 5.
    Image extensions • PNG-(Portable Network Graphics) is a lossless image format widely used for its transparency support and compression capabilities. It preserves high-quality images without losing detail, making it ideal for web graphics and digital photography. PNG files are commonly used for logos, icons, and images with sharp edges. • JPG-JPEG (Joint Photographic Experts Group) is a popular lossy image format known for its efficient compression of photographs. It reduces file sizes by discarding some image data, leading to some loss of quality. JPEG files are widely used for web images, digital photography, and graphics where smaller file sizes are preferred. • JPEG (Joint Photographic Experts Group) is a widely used image format known for its lossy compression method that reduces file sizes while maintaining decent image quality. It is suitable for photographs and web images where smaller file sizes are essential. JPEG files support millions of colors and are compatible with most devices and platforms.
  • 6.
    Modes • The secondargument present in the imread function is the mode. • This defines the way to read the image. • cv2.imread_GRAYSCALE is used to read image in black and white format. • cv2.imread_COLOR is used to read the image in color format. • The number 0 is read in black & white and 1 to read color.
  • 7.
    Displaying an image •Assuming that we have applied a suited image processing technique over our read image, it is essential to show the image. We have to display the image on which we have performed our processing on. • For this there is a function in OpenCV called as imshow. • cv2.imshow(“image name”, image) • The first argument is the name that we want to keep for the image. It is essential that we give the name within single or double quotes. • The second argument is the image, this is the image which has been read by the imread function. • We can store the read image in a temporary variable and then use it in the imshow functions.