SlideShare a Scribd company logo
1 of 35
Download to read offline
@DylanSeychell
Introduction to
Computer Vision
using OpenCV
Dylan Seychell
I am Dylan Seychell
Academic and Software Engineer
AI, UX and Computer Vision
@DylanSeychell
Hello!
2
@DylanSeychell
Presentation Overview
What is Computer Vision?
What is OpenCV?
Workshop:
Image Acquisition
Image Processing
Image Analysis/Understanding
3
Computer Vision
Making computers get a high-level
understanding from images and videos.
4
@DylanSeychell
Stages of Computer Vision
5
Acquisition UnderstandingProcessing
Covered in this session
@DylanSeychell
OpenCV - enabling computer vision
Open Source Computer Vision library
Cross-platform
Free for use under open source BSD license
Can be easily used with Java, Python, C and C++
Supports Machine Learning libraries such as
TensorFlow and Caffe.
https://opencv.org
6
@DylanSeychell
This Session:
We’ll be using OpenCV with Python
New to Python? Check these slides
https://www.slideshare.net/dylsey/introduction-to-python-80851217
7
@DylanSeychell
CodeLab Part 1: Acquisition of Image Data
8
@DylanSeychell
Test the library:
In terminal/CMD type python
>>> import cv2
>>>
9
@DylanSeychell
Importing an image
Create a Python module and write the following code:
import cv2
img = cv2.imread('duomo.jpg',1)
cv2.imshow("Output Window", img)
cv2.waitKey()
This code imports an image and outputs it to a window and waits for any user
keyboard input to terminate.
10
@DylanSeychell
cv2.imread() function
This function is used to load an image and store it into a variable
img = cv2.imread('duomo.jpg',1)
This function accepts 2 parameters:
1. The filename of the image
2. Colour Approach:
a. 1: Colour, neglecting transparency
b. 0: Greyscale
c. -1: Colour together with the alpha channel
11
@DylanSeychell
Different output for different imread() arguments
12
img = cv2.imread('duomo.jpg',1) img = cv2.imread('duomo.jpg',0)
@DylanSeychell
cv2.imshow() function
This function is used to display an image in a window.
cv2.imshow("Output Window", img)
This function accepts 2 parameters:
1. The name of the output window
2. The image to be displayed in the output window
NB 1: The window automatically fits the image size.
NB 2: Matplotlib can be used as an alternative
13
@DylanSeychell
cv2.waitKey() function
This is a keyboard binding function
cv2.waitKey()
A single argument value in milliseconds:
1. 0 or no argument: wait indefinitely for keyboard interrupt
2. Any other value: display the window for the duration of that value in ms
This function returns the ASCII value of the key pressed and if stored in a
variable, it can be used to perform subsequent logical operations.
14
@DylanSeychell
Using the webcam feed
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
15
@DylanSeychell
cv2.VideoCapture() Object
The video capture object allows us to manipulate captured frames from a
camera.
cap = cv2.VideoCapture(0)
The argument is either the video filename or camera index, 0 for webcam.
Allows the handling of each frame.
After being used, the capture has to be released:
cap.release()
16
@DylanSeychell
Importing a video
cap = cv2.VideoCapture('vtest.avi')
while(cap.isOpened()): #returns true when there is another frame to process
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
17
@DylanSeychell
CodeLab Part 2: Image Processing
18
@DylanSeychell
Create a new module and initialise it
import cv2
img = cv2.imread('duomo.jpg',0)
##Our Image Processing code goes here
cv2.imshow("Output Window", img)
cv2.waitKey()
19
@DylanSeychell
Image Type
Try printing these values:
print (type(img))
This will return <type 'numpy.ndarray'>
Therefore, we’d deal with a numpy array
20
@DylanSeychell
Image Shape
Try printing these values:
img = cv2.imread('duomo.jpg',0)
print (type(img))
print (img)
[[22 22 22 ..., 23 23 24]
[22 22 22 ..., 23 23 23]
[22 22 22 ..., 23 23 23]
...,
[13 13 13 ..., 5 6 6]
[13 13 13 ..., 11 11 10]
[13 13 13 ..., 12 12 10]]
21
Greyscale
@DylanSeychell
Try the same thing with a coloured image
22
@DylanSeychell
Slicing Image Channels (Colours)
Load a coloured image and set unwanted channels to zero
img = cv2.imread("duomo.jpg", 1)
img[:,:,2] = 0 #red
img[:,:,1] = 0 #green
img[:,:,0] #blue
cv2.imshow("Output", img) #returns the blue channel
23
@DylanSeychell
Slicing by colour channel.
24
img[:,:,2] = 0 #red
img[:,:,1] = 0 #green
img[:,:,0] #blue
img[:,:,2] #red
img[:,:,1] = 0 #green
img[:,:,0] = 0 #blue
img[:,:,2] = 0 #red
img[:,:,1] #green
img[:,:,0] = 0 #blue
@DylanSeychell
Blurring images in OpenCV
The blur function using average values
blur = cv2.blur(img,(5,5))
This method accepts 2 arguments:
1. The source image
2. A tuple with the size of the box filter
25
@DylanSeychell
Simple blurring using OpenCV.
26
blur = cv2.blur(img,(10,10)) blur = cv2.blur(img,(5,5))
@DylanSeychell
Detecting Edges
Using Canny edge detection:
● Removes the noise using a Gaussian Filter
● Finds intensity gradient of the image
● Non-maximum suppression (remove unwanted pixels)
● Hysteresis Thresholding (difference between min and max values)
27
@DylanSeychell
Canny Edge Detection in OpenCV
edges = cv2.Canny(img,100,200)
This method accepts 3 arguments:
1. The source image
2. Min value
3. Max value
28
@DylanSeychell
Different minVal and maxVal values
29
edges = cv2.Canny(img,50,60) edges = cv2.Canny(img,150,300)
@DylanSeychell
Choosing a region of interest
An inbuilt function to select a region of interest:
fromCenter = False
r = cv2.selectROI(img, fromCenter)
Arguments:
1. The source image
2. Flag to choose the origin of the bounding box
30
@DylanSeychell
Using the resultant RoI
Save the resultant RoI into another image
r = cv2.selectROI(img, fromCenter)
imCropT = img[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])]
Cropping the image using Numpy array slicing in the form:
crop= img[yoffset:-yoffset, xoffset:-xoffset]
31
@DylanSeychell
Selecting a RoI and displaying it
32
r = cv2.selectROI(img, fromCenter)
imCropT = img[int(r[1]):int(r[1]+r[3]),
int(r[0]):int(r[0]+r[2])]
cv2.imshow("Cropped", imCropT)
@DylanSeychell
Part 3: Analysis
This is a specialised field also known as Artificial
Vision. More resources related to this field will follow.
33
@DylanSeychell
Merging Computer Vision and AI.
34
Image to TextObject Detection & Classification
@DylanSeychell
Thank you!
35

More Related Content

What's hot

OpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the RoadmapOpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the RoadmapEugene Khvedchenya
 
openCV with python
openCV with pythonopenCV with python
openCV with pythonWei-Wen Hsu
 
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming..."The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...Edge AI and Vision Alliance
 
Active contour segmentation
Active contour segmentationActive contour segmentation
Active contour segmentationNishant Jain
 
Deblurring of Digital Image PPT
Deblurring of Digital Image PPTDeblurring of Digital Image PPT
Deblurring of Digital Image PPTSyed Atif Naseem
 
ImageProcessing10-Segmentation(Thresholding) (1).ppt
ImageProcessing10-Segmentation(Thresholding) (1).pptImageProcessing10-Segmentation(Thresholding) (1).ppt
ImageProcessing10-Segmentation(Thresholding) (1).pptVikramBarapatre2
 
Introduction to object detection
Introduction to object detectionIntroduction to object detection
Introduction to object detectionBrodmann17
 
Dital Image Processing (Lab 2+3+4)
Dital Image Processing (Lab 2+3+4)Dital Image Processing (Lab 2+3+4)
Dital Image Processing (Lab 2+3+4)Moe Moe Myint
 
Deep learning based object detection basics
Deep learning based object detection basicsDeep learning based object detection basics
Deep learning based object detection basicsBrodmann17
 
Image Enhancement using Frequency Domain Filters
Image Enhancement using Frequency Domain FiltersImage Enhancement using Frequency Domain Filters
Image Enhancement using Frequency Domain FiltersKarthika Ramachandran
 
Application of edge detection
Application of edge detectionApplication of edge detection
Application of edge detectionNaresh Biloniya
 
Frequency Domain Image Enhancement Techniques
Frequency Domain Image Enhancement TechniquesFrequency Domain Image Enhancement Techniques
Frequency Domain Image Enhancement TechniquesDiwaker Pant
 
BASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROU
BASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROUBASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROU
BASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROUanjunarayanan
 
Image segmentation with deep learning
Image segmentation with deep learningImage segmentation with deep learning
Image segmentation with deep learningAntonio Rueda-Toicen
 
Digital Image Processing: Image Segmentation
Digital Image Processing: Image SegmentationDigital Image Processing: Image Segmentation
Digital Image Processing: Image SegmentationMostafa G. M. Mostafa
 
SURF - Speeded Up Robust Features
SURF - Speeded Up Robust FeaturesSURF - Speeded Up Robust Features
SURF - Speeded Up Robust FeaturesMarta Lopes
 

What's hot (20)

OpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the RoadmapOpenCV 3.0 - Latest news and the Roadmap
OpenCV 3.0 - Latest news and the Roadmap
 
openCV with python
openCV with pythonopenCV with python
openCV with python
 
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming..."The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...
 
Object detection
Object detectionObject detection
Object detection
 
Edge detection
Edge detectionEdge detection
Edge detection
 
Active contour segmentation
Active contour segmentationActive contour segmentation
Active contour segmentation
 
Deblurring of Digital Image PPT
Deblurring of Digital Image PPTDeblurring of Digital Image PPT
Deblurring of Digital Image PPT
 
ImageProcessing10-Segmentation(Thresholding) (1).ppt
ImageProcessing10-Segmentation(Thresholding) (1).pptImageProcessing10-Segmentation(Thresholding) (1).ppt
ImageProcessing10-Segmentation(Thresholding) (1).ppt
 
Introduction to object detection
Introduction to object detectionIntroduction to object detection
Introduction to object detection
 
Dital Image Processing (Lab 2+3+4)
Dital Image Processing (Lab 2+3+4)Dital Image Processing (Lab 2+3+4)
Dital Image Processing (Lab 2+3+4)
 
Deep learning based object detection basics
Deep learning based object detection basicsDeep learning based object detection basics
Deep learning based object detection basics
 
Image Enhancement using Frequency Domain Filters
Image Enhancement using Frequency Domain FiltersImage Enhancement using Frequency Domain Filters
Image Enhancement using Frequency Domain Filters
 
Application of edge detection
Application of edge detectionApplication of edge detection
Application of edge detection
 
Line Detection
Line DetectionLine Detection
Line Detection
 
Frequency Domain Image Enhancement Techniques
Frequency Domain Image Enhancement TechniquesFrequency Domain Image Enhancement Techniques
Frequency Domain Image Enhancement Techniques
 
BASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROU
BASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROUBASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROU
BASICS OF DIGITAL IMAGE PROCESSING,MARIA PETROU
 
Image segmentation with deep learning
Image segmentation with deep learningImage segmentation with deep learning
Image segmentation with deep learning
 
Digital Image Processing: Image Segmentation
Digital Image Processing: Image SegmentationDigital Image Processing: Image Segmentation
Digital Image Processing: Image Segmentation
 
SURF - Speeded Up Robust Features
SURF - Speeded Up Robust FeaturesSURF - Speeded Up Robust Features
SURF - Speeded Up Robust Features
 
Edge detection
Edge detectionEdge detection
Edge detection
 

Similar to Introduction to Computer Vision using OpenCV

Intro_OpenCV.ppt
Intro_OpenCV.pptIntro_OpenCV.ppt
Intro_OpenCV.pptRithikRaj25
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfUmarMustafa13
 
Image processing for robotics
Image processing for roboticsImage processing for robotics
Image processing for roboticsSALAAMCHAUS
 
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...Saeed Ullah
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Luigi De Russis
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorialantiw
 
Color Detection & Segmentation based Invisible Cloak
Color Detection & Segmentation based Invisible CloakColor Detection & Segmentation based Invisible Cloak
Color Detection & Segmentation based Invisible CloakAviral Chaurasia
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...Edge AI and Vision Alliance
 
Python image processing_Python image processing.pptx
Python image processing_Python image processing.pptxPython image processing_Python image processing.pptx
Python image processing_Python image processing.pptxshashikant484397
 
aip basic open cv example
aip basic open cv exampleaip basic open cv example
aip basic open cv exampleSaeed Ullah
 
Open CV - 電腦怎麼看世界
Open CV - 電腦怎麼看世界Open CV - 電腦怎麼看世界
Open CV - 電腦怎麼看世界Tech Podcast Night
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfssuserb4d806
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effectsSergey Kuksenko
 
Week2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptxWeek2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptxfahmi324663
 
Kinect v1+Processing workshot fabcafe_taipei
Kinect v1+Processing workshot fabcafe_taipeiKinect v1+Processing workshot fabcafe_taipei
Kinect v1+Processing workshot fabcafe_taipeiMao Wu
 

Similar to Introduction to Computer Vision using OpenCV (20)

Intro_OpenCV.ppt
Intro_OpenCV.pptIntro_OpenCV.ppt
Intro_OpenCV.ppt
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdf
 
Image processing for robotics
Image processing for roboticsImage processing for robotics
Image processing for robotics
 
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
OpenCV+Android.pptx
OpenCV+Android.pptxOpenCV+Android.pptx
OpenCV+Android.pptx
 
Color Detection & Segmentation based Invisible Cloak
Color Detection & Segmentation based Invisible CloakColor Detection & Segmentation based Invisible Cloak
Color Detection & Segmentation based Invisible Cloak
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
 
Facedetect
FacedetectFacedetect
Facedetect
 
Python image processing_Python image processing.pptx
Python image processing_Python image processing.pptxPython image processing_Python image processing.pptx
Python image processing_Python image processing.pptx
 
aip basic open cv example
aip basic open cv exampleaip basic open cv example
aip basic open cv example
 
Log polar coordinates
Log polar coordinatesLog polar coordinates
Log polar coordinates
 
Open CV - 電腦怎麼看世界
Open CV - 電腦怎麼看世界Open CV - 電腦怎麼看世界
Open CV - 電腦怎麼看世界
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
 
Python OpenCV Real Time projects
Python OpenCV Real Time projectsPython OpenCV Real Time projects
Python OpenCV Real Time projects
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effects
 
Week2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptxWeek2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptx
 
MAJOR PROJECT
MAJOR PROJECT MAJOR PROJECT
MAJOR PROJECT
 
Kinect v1+Processing workshot fabcafe_taipei
Kinect v1+Processing workshot fabcafe_taipeiKinect v1+Processing workshot fabcafe_taipei
Kinect v1+Processing workshot fabcafe_taipei
 

Recently uploaded

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Recently uploaded (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Introduction to Computer Vision using OpenCV

  • 2. I am Dylan Seychell Academic and Software Engineer AI, UX and Computer Vision @DylanSeychell Hello! 2
  • 3. @DylanSeychell Presentation Overview What is Computer Vision? What is OpenCV? Workshop: Image Acquisition Image Processing Image Analysis/Understanding 3
  • 4. Computer Vision Making computers get a high-level understanding from images and videos. 4
  • 5. @DylanSeychell Stages of Computer Vision 5 Acquisition UnderstandingProcessing Covered in this session
  • 6. @DylanSeychell OpenCV - enabling computer vision Open Source Computer Vision library Cross-platform Free for use under open source BSD license Can be easily used with Java, Python, C and C++ Supports Machine Learning libraries such as TensorFlow and Caffe. https://opencv.org 6
  • 7. @DylanSeychell This Session: We’ll be using OpenCV with Python New to Python? Check these slides https://www.slideshare.net/dylsey/introduction-to-python-80851217 7
  • 8. @DylanSeychell CodeLab Part 1: Acquisition of Image Data 8
  • 9. @DylanSeychell Test the library: In terminal/CMD type python >>> import cv2 >>> 9
  • 10. @DylanSeychell Importing an image Create a Python module and write the following code: import cv2 img = cv2.imread('duomo.jpg',1) cv2.imshow("Output Window", img) cv2.waitKey() This code imports an image and outputs it to a window and waits for any user keyboard input to terminate. 10
  • 11. @DylanSeychell cv2.imread() function This function is used to load an image and store it into a variable img = cv2.imread('duomo.jpg',1) This function accepts 2 parameters: 1. The filename of the image 2. Colour Approach: a. 1: Colour, neglecting transparency b. 0: Greyscale c. -1: Colour together with the alpha channel 11
  • 12. @DylanSeychell Different output for different imread() arguments 12 img = cv2.imread('duomo.jpg',1) img = cv2.imread('duomo.jpg',0)
  • 13. @DylanSeychell cv2.imshow() function This function is used to display an image in a window. cv2.imshow("Output Window", img) This function accepts 2 parameters: 1. The name of the output window 2. The image to be displayed in the output window NB 1: The window automatically fits the image size. NB 2: Matplotlib can be used as an alternative 13
  • 14. @DylanSeychell cv2.waitKey() function This is a keyboard binding function cv2.waitKey() A single argument value in milliseconds: 1. 0 or no argument: wait indefinitely for keyboard interrupt 2. Any other value: display the window for the duration of that value in ms This function returns the ASCII value of the key pressed and if stored in a variable, it can be used to perform subsequent logical operations. 14
  • 15. @DylanSeychell Using the webcam feed cap = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = cap.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() 15
  • 16. @DylanSeychell cv2.VideoCapture() Object The video capture object allows us to manipulate captured frames from a camera. cap = cv2.VideoCapture(0) The argument is either the video filename or camera index, 0 for webcam. Allows the handling of each frame. After being used, the capture has to be released: cap.release() 16
  • 17. @DylanSeychell Importing a video cap = cv2.VideoCapture('vtest.avi') while(cap.isOpened()): #returns true when there is another frame to process ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() 17
  • 18. @DylanSeychell CodeLab Part 2: Image Processing 18
  • 19. @DylanSeychell Create a new module and initialise it import cv2 img = cv2.imread('duomo.jpg',0) ##Our Image Processing code goes here cv2.imshow("Output Window", img) cv2.waitKey() 19
  • 20. @DylanSeychell Image Type Try printing these values: print (type(img)) This will return <type 'numpy.ndarray'> Therefore, we’d deal with a numpy array 20
  • 21. @DylanSeychell Image Shape Try printing these values: img = cv2.imread('duomo.jpg',0) print (type(img)) print (img) [[22 22 22 ..., 23 23 24] [22 22 22 ..., 23 23 23] [22 22 22 ..., 23 23 23] ..., [13 13 13 ..., 5 6 6] [13 13 13 ..., 11 11 10] [13 13 13 ..., 12 12 10]] 21 Greyscale
  • 22. @DylanSeychell Try the same thing with a coloured image 22
  • 23. @DylanSeychell Slicing Image Channels (Colours) Load a coloured image and set unwanted channels to zero img = cv2.imread("duomo.jpg", 1) img[:,:,2] = 0 #red img[:,:,1] = 0 #green img[:,:,0] #blue cv2.imshow("Output", img) #returns the blue channel 23
  • 24. @DylanSeychell Slicing by colour channel. 24 img[:,:,2] = 0 #red img[:,:,1] = 0 #green img[:,:,0] #blue img[:,:,2] #red img[:,:,1] = 0 #green img[:,:,0] = 0 #blue img[:,:,2] = 0 #red img[:,:,1] #green img[:,:,0] = 0 #blue
  • 25. @DylanSeychell Blurring images in OpenCV The blur function using average values blur = cv2.blur(img,(5,5)) This method accepts 2 arguments: 1. The source image 2. A tuple with the size of the box filter 25
  • 26. @DylanSeychell Simple blurring using OpenCV. 26 blur = cv2.blur(img,(10,10)) blur = cv2.blur(img,(5,5))
  • 27. @DylanSeychell Detecting Edges Using Canny edge detection: ● Removes the noise using a Gaussian Filter ● Finds intensity gradient of the image ● Non-maximum suppression (remove unwanted pixels) ● Hysteresis Thresholding (difference between min and max values) 27
  • 28. @DylanSeychell Canny Edge Detection in OpenCV edges = cv2.Canny(img,100,200) This method accepts 3 arguments: 1. The source image 2. Min value 3. Max value 28
  • 29. @DylanSeychell Different minVal and maxVal values 29 edges = cv2.Canny(img,50,60) edges = cv2.Canny(img,150,300)
  • 30. @DylanSeychell Choosing a region of interest An inbuilt function to select a region of interest: fromCenter = False r = cv2.selectROI(img, fromCenter) Arguments: 1. The source image 2. Flag to choose the origin of the bounding box 30
  • 31. @DylanSeychell Using the resultant RoI Save the resultant RoI into another image r = cv2.selectROI(img, fromCenter) imCropT = img[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])] Cropping the image using Numpy array slicing in the form: crop= img[yoffset:-yoffset, xoffset:-xoffset] 31
  • 32. @DylanSeychell Selecting a RoI and displaying it 32 r = cv2.selectROI(img, fromCenter) imCropT = img[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])] cv2.imshow("Cropped", imCropT)
  • 33. @DylanSeychell Part 3: Analysis This is a specialised field also known as Artificial Vision. More resources related to this field will follow. 33
  • 34. @DylanSeychell Merging Computer Vision and AI. 34 Image to TextObject Detection & Classification