Introduction To Computer Vision by Dylan Seychell
Introduction To Computer Vision by Dylan Seychell
Computer Vision
using OpenCV
Dylan Seychell
@DylanSeychell
Hello!
I am Dylan Seychell
Academic and Software Engineer
AI, UX and Computer Vision
@DylanSeychell
2
Presentation Overview
What is Computer Vision?
What is OpenCV?
Workshop:
Image Acquisition
Image Processing
Image Analysis/Understanding
3
@DylanSeychell
Computer Vision
Making computers get a high-level
understanding from images and videos.
4
Stages of Computer Vision
5
@DylanSeychell
OpenCV - enabling computer vision
Open Source Computer Vision library
Cross-platform
https://opencv.org
6
@DylanSeychell
This Session:
We’ll be using OpenCV with Python
7
@DylanSeychell
CodeLab Part 1: Acquisition of Image Data
8
@DylanSeychell
Test the library:
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)
11
@DylanSeychell
img = cv2.imread('duomo.jpg',1) img = cv2.imread('duomo.jpg',0)
cv2.waitKey()
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.
16
@DylanSeychell
Importing a video
cap = cv2.VideoCapture('vtest.avi')
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)
19
@DylanSeychell
Image Type
Try printing these values:
print (type(img))
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]
Greyscale
[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
@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
23
@DylanSeychell
img[:,:,2] = 0 #red img[:,:,2] #red img[:,:,2] = 0 #red
img[:,:,1] = 0 #green img[:,:,1] = 0 #green img[:,:,1] #green
img[:,:,0] #blue img[:,:,0] = 0 #blue img[:,:,0] = 0 #blue
blur = cv2.blur(img,(5,5))
25
@DylanSeychell
blur = cv2.blur(img,(10,10)) blur = cv2.blur(img,(5,5))
27
@DylanSeychell
Canny Edge Detection in OpenCV
edges = cv2.Canny(img,100,200)
28
@DylanSeychell
edges = cv2.Canny(img,50,60) edges = cv2.Canny(img,150,300)
fromCenter = False
r = cv2.selectROI(img, fromCenter)
Arguments:
30
@DylanSeychell
Using the resultant RoI
Save the resultant RoI into another image
r = cv2.selectROI(img, fromCenter)
31
@DylanSeychell
r = cv2.selectROI(img, fromCenter)
cv2.imshow("Cropped", imCropT)
imCropT = img[int(r[1]):int(r[1]+r[3]),
int(r[0]):int(r[0]+r[2])]
33
@DylanSeychell
Object Detection & Classification Image to Text
35
@DylanSeychell