Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Saint Louis University

School of Engineering and Architecture

Department of Mechanical and Mechatronics Engineering

MEC 4261L DIGITAL PROCESSING AND MACHINE VISION (LAB)


Experiment No. 3
OPENCV FUNDAMENTALS

Submitted by:
BARRIL, JHAN RAY G.

Submitted to:
ENGR. HKV

18 FEBRUARY 2024
Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 1 of 12

MEC 4261 Digital Processing and Machine Vision

Experiment No: 3
Title: Open CV Fundamentals

At the end of this experiment, the student should be able to:

TLO 3: To be familiarize with python Open CV in Google collab and upload image
samples

I. INTRODUCTION:

OpenCV is a cross-platform library using which we can develop real-time computer vision
applications. It mainly focuses on image processing, video capture and analysis including features
like face detection and object detection. In this tutorial, we explain how you can use OpenCV in
your applications.

Features of OpenCV Library


• Read and write images
• Capture and save videos
• Process images (filter, transform)
• Perform feature detection
• Detect specific objects such as faces, eyes, cars, in the videos or images.
• Analyze the video, i.e., estimate the motion in it, subtract the background, and track
objects in it.

OpenCV was originally developed in C++. In addition to it, Python and Java bindings were
provided. OpenCV runs on various Operating Systems such as windows, Linux, OSx, FreeBSD,
Net BSD, Open BSD.

II. EQUIPMENT/ MATERIALS NEEDED:

Computer/Laptop
Google Collab or Open CV

III. PROCEDURES:

Instruction: Follow the instruction provided in the google collab but use your own image for the
experiment. Also provide a 2-page Discussion of Theory Research to be attached at the back of
this experiment manual. Arial 11 1.5 spacing.

Google Collab Notebook Link:


https://colab.research.google.com/github/computationalcore/introduction-to-
opencv/blob/master/notebooks/1-Fundamentals.ipynb#scrollTo=eP9VcOVoebew
Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 2 of 12

MEC 4261 Digital Processing and Machine Vision

IV. DISCUSSION OF THEORY

Introduction to Computer Vision


The journey of computer vision spanned for more than six decades, beginning from
curious minds aiming to explore how animals see or interpret the world around them and then
trying to teach computers to do the same. In the 1980s, David Marr and Kunihiko Fukushima
introduced ideas that laid the foundation for what we now know as computer vision. Their work,
initially composed of abstract thoughts and concepts, grew to become the current breakthroughs,
such as real-time face detection.

In 2012, the introduction of AlexNet propelled computer vision. The computers were not
just recognizing images but they were doing it incredibly well. Since then, computer vision has
exploded onto the scene, finding its way into various aspects of our lives, from assisting in medical
research to powering self-driving cars. While there are still hurdles to overcome, like making sure
it's fair for everyone, the future of computer vision looks bright, with ongoing advancements
promising even greater possibilities ahead.

Figure 1. AlexNet Convolutional Neural Network (CNN)

Moreover, computer vision is a field within artificial intelligence and computer science, that
focuses on enabling computers to interpret and understand the visual world. It aims to replicate
the human visual system's ability to perceive, analyze, and interpret visual data from the
surrounding environment but then it started from animals. This includes tasks such as object
recognition, image classification, scene understanding, and image reconstruction. Computer
vision algorithms often utilize techniques from image processing, pattern recognition, machine
learning, and deep learning to extract meaningful information from visual data.

Advancements in computer vision have led to significant breakthroughs across various


industries, including healthcare, automotive, manufacturing, agriculture, security, and
entertainment. In healthcare, computer vision facilitates medical image analysis for disease
Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 3 of 12

MEC 4261 Digital Processing and Machine Vision

diagnosis and treatment planning. In autonomous vehicles, it enables perception systems to


recognize and interpret traffic signs, pedestrians, and obstacles on the road. In manufacturing,
computer vision enhances quality control processes by detecting defects in products on assembly
lines. These examples illustrate the broad applicability and potential impact of computer vision
technologies and one example is the OpenCV that is utilized in this experiment.

Brief History and Overview of OpenCV

OpenCV originated from Intel in 1999. This open-source library grew powerful for
Computer Vision and Machine Learning, due to the efforts of developers like Gary Bradsky and
Vadim Pisarevsky. Its involvement in projects like Stanley, the 2005 DARPA Grand Challenge
winner, highlighted its importance, and it continues to evolve under Willow Garage's support. With
compatibility across various programming languages (like C++, Python, and Java) and platforms
(including Windows, Linux, OS X, Android, and iOS), OpenCV offers immense flexibility. It even
supports high-speed GPU operations through CUDA and OpenCL.

OpenCV-Python, the Python API for OpenCV, brings the library's capabilities to Python
developers, combining the performance of C/C++ with Python's ease of use. Its integration with
Numpy allows for efficient manipulation of arrays, enhancing interoperability with other Python
libraries like SciPy and Matplotlib. The OpenCV-Python tutorials offer comprehensive guidance
on using OpenCV with Python, focusing primarily on version 3.x.

Community involvement is crucial for OpenCV's growth. The project welcomes


contributions to its library, documentation, and tutorials. Those proficient in specific algorithms are
encouraged to share their knowledge by contributing tutorials, fostering a collaborative learning
environment. As OpenCV continues to evolve, community contributions play a pivotal role in its
advancement, driving innovation and impact in the field of Computer Vision.

Common Applications of OpenCV

Object Detection and Recognition: OpenCV


enables the detection and recognition of objects within
images or video streams. This capability is used in
various applications, such as surveillance systems,
autonomous vehicles, and augmented reality.

Facial Recognition: OpenCV provides tools for


detecting and recognizing faces in images and video
streams. This technology is utilized in security systems,
biometric authentication, and facial emotion recognition
applications.

Image and Video Processing: OpenCV possess


image and video processing functions including
filtering, transformation, and enhancement similar to the
goals of this experiment. These capabilities are used in
applications like medical imaging, satellite image
analysis, and video editing software.
Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 4 of 12

MEC 4261 Digital Processing and Machine Vision

V. DATA AND RESULTS


I. Open an Image

a. Provide a screenshot of your image read

Figure 2. Setting up OpenCV

Figure 3. Image Read (Teemo)

b. What is the image size, shape and data type?

Figure 4. Image Size, Shape, & Data Type


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 5 of 12

MEC 4261 Digital Processing and Machine Vision

c. BGR format image

Figure 5. BGR of Image

d. Gray format image (try to do r-gray, g-gray and b-gray images)

Figure 6. R-Gray Image


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 6 of 12

MEC 4261 Digital Processing and Machine Vision

Figure 7. B-Gray of Image

Figure 8. G-Gray of Image


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 7 of 12

MEC 4261 Digital Processing and Machine Vision

e. Merged (rgb) format image

Figure 9. Merged RGB of Image

II. Color flags


a. Enumerate at least 10 color flags
- COLORMAP: AUTUMN, BONE, HOT, SPRING, WINTER, CIVIDIS, SUMMER,
TWILIGHT, OCEAN, PINK.
b. Apply the first 5 color flags in the list

Figure 10. COLORMAP_AUTUMN


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 8 of 12

MEC 4261 Digital Processing and Machine Vision

Figure 11. COLORMAP_BONE

Figure 12. COLORMAP_HOT


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 9 of 12

MEC 4261 Digital Processing and Machine Vision

Figure 13. COLORMAP_SPRING

Figure 14. COLORMAP_WINTER


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 10 of 12

MEC 4261 Digital Processing and Machine Vision

III. Image Data


a. What is the pixel of your image?

Figure 15. Finding Pixel of 717 x 1215 Image (Using 716 x 1214)

Set a new pixel for your image.

Figure 16. Setting up Pixels of Image to 100

IV. Regions of image


a. Screen shot of a region of your image

Figure 17. Region of Image


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 11 of 12

MEC 4261 Digital Processing and Machine Vision

Figure 18. Region in Comparison to Original Image

V. Matrix Slice
a. Screen of a sliced image

Figure 19. Slice of the Image


Document Code FM-SEA-018
Revision No. 00
Saint Louis University Effectivity Feb 01, 2021
School of Engineering and Architecture Page 12 of 12

MEC 4261 Digital Processing and Machine Vision

VI. DISCUSSION/CONCLUSION (observation/ interpretation of results):

In this experiment, I initially observed familiarity with the format of the activity in relation to
the past experiments that involved Arduino IDE. With the use of Google Colab, the notebook that
was provided, allowed me to explore the OpenCV fundamentals. As simple as opening files,
determining an image’s size and pixels, and in allowing me to practice simple image processing
techniques such as color manipulation, slicing and region setting. Here are further observations:
Upon getting OpenCV Python started, I noticed the importance of importing the OpenCV
library and some of its functions first in order to work on the next steps of the experiment. After
that, I only had to substitute the URL of my test image “Teemo” to the code prepared in the entire
notebook. After substituting to all “noimage.jpg”, I just had to run the codes to determine the image
size, shape and data type and execute some color manipulation or image processing techniques.
One key note when it comes to using OpenCV, is that it stores images in BGR format
instead of RGB. Next, the channels can be split into different channels; b, g, and r. Changing the
r from [plt.imshow(r,cmap=’gray’)] to b makes the image very dark while changing it to g makes a
little bit darker. Merging the three channels will output the original colors of the image as uploaded.
Furthermore, as I am exploring the color flags, I have observed that not all of them are displayable
and there were some color flags with different names output the same image.
The next segment, discusses how the images in python OpenCV are actually numpy
arrays. Instead of determining the area of the image pixel by pixel, it can be accessed through
matrix. The array manipulation is a relevant practice particularly in slicing.
As a conclusion, this experiment is integral in establishing how OpenCV can be relevant
in image processing. Being a huge open-source library, it becomes a stepping stone for computer
vision and machine learning enthusiasts and also those who aim to teach or learn how to process
images, identify objects, faces and more.

VII. REFERENCES (APA Format):

Demush, R. (2019, February 26). A brief history of computer vision (and convolutional neural
networks). HackerNoon. https://hackernoon.com/a-brief-history-of-computer-vision-and-
convolutional-neural-networks-8fe8aacc79f3
Pujara, A. (2020, November 5). Concept of AlexNet:- Convolutional Neural Network - Analytics
Vidhya - Medium. Medium. https://medium.com/analytics-vidhya/concept-of-alexnet-
convolutional-neural-network-6e73b4f9ee30
Shiksha Online. (2024, February 1). Amazing applications of OpenCV in Python - Shiksha online.
Shiksha.com. https://www.shiksha.com/online-courses/articles/amazing-applications-of-
opencv-in-
python/#:~:text=OpenCV%20finds%20applications%20in%20various,%2C%20surveillan
ce%2C%20and%20autonomous%20vehicles.

You might also like