Open CVIntro
Open CVIntro
OpenCV – Introduction
} OpenCV stands for the Open Source Computer Vision Library.
} It was founded at Intel in 1999, went through some lean years a@er the .bust but is now u
2
OpenCV History
● History :
● 1999 : Original version
by Intel Research
● 2006 : Version 1.0
● 2008 : Support by
Willow Garage
● 2009 : Version 2.0 (OpenCV 2)
● 2012 : Support by OpenCV.org
● 2015 : Version 3.0 (OpenCV 3)
Source: http://fr.slideshare.net/embeddedvision/e04-open-cvbradsk
● 2018 : Version 4.0 (OpenCV 4)
OpenCV - Features
} Cross PlaHorm
} Windows, Linux, Mac OS
} Portable
} iPhone
} Android.
} Language Support
} C/C++
} Python
4
OpenCV-Python
Geometric
Descriptors
Segmentation Camera
Calibration,
Stereo, 3D
Features
Transforms Utilities and
Data Structures
Tracking
Machine
Learning: Fitting
• Detection,
• Recognition
Matrix Math
6
OpenCV First Steps - Reading
Now that OpenCV is installed, the first thing to do is to import the module and opening an
image which is fairly simple.
import cv2
# LOAD AN IMAGE USING 'IMREAD’ : Lena is a well know image used by the vision community
img = cv2.imread("Resources/lena.png") # the image will be stored in img
# DISPLAY
cv2.imshow("Lena Soderberg",img) #two arguments the first one is the name of the window and the second the name
of the image we want to show
cv2.waitKey(0) #we add a delay - 0 means infinite delay unAl a key is pressed - an other number will be interpreted in
milliseconds
OpenCV First Steps – Read Video
Now that OpenCV is installed, the first thing to do is to import the module and opening an
image which is fairly simple.
import cv2
import numpy as np
img = cv2.imread("Resources/lena.png")
kernel = np.ones((5,5),np.uint8)
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
imgBlur = cv2.GaussianBlur(imgGray,(7,7),0)
imgCanny = cv2.Canny(img,150,200)
imgDialaAon = cv2.dilate(imgCanny,kernel,iteraAons=1)
imgEroded = cv2.erode(imgDialaAon,kernel,iteraAons=1)
cv2.imshow("Gray Image",imgGray)
cv2.imshow("Blur Image",imgBlur)
cv2.imshow("Canny Image",imgCanny)
OpenCV First Steps – Basic functions
Here are some basic function you can try --> we will explain, the idea behind later
import cv2
import numpy as np # you should add numpy to your project (as you added OpenCV)
img = cv2.imread("Resources/lena.png")
kernel = np.ones((5,5),np.uint8) #This will creat a 5x5 matrix with ones inside
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #convert your image from BGR into grayscale
imgBlur = cv2.GaussianBlur(imgGray,(7,7),0) #add a gaussian blur to your image with variance sigam =0
imgCanny = cv2.Canny(img,150,200) #extract the contours of your image
imgDialaAon = cv2.dilate(imgCanny,kernel,iteraAons=1) #this one possible operaAon on your image
imgEroded = cv2.erode(imgDialaAon,kernel,iteraAons=1) #this is an other psossible operaAon on your image
cv2.imshow("Gray Image",imgGray)
cv2.imshow("Blur Image",imgBlur)
cv2.imshow("Canny Image",imgCanny)
cv2.imshow("DialaAon Image",imgDialaAon)
cv2.imshow("Eroded Image",imgEroded)
cv2.waitKey(0)
# You can have a look on the difference between the different images
OpenCV First Steps – Resizing and Cropping
Have a look on this and explain it !!!!!!!!!
import cv2
import numpy as np
img = cv2.imread("Resources/lambo.png")
print(img.shape)
imgResize = cv2.resize(img,(1000,500))
print(imgResize.shape)
imgCropped = img[0:200,200:500]
cv2.imshow("Image",img) OpenCV Frame convenAons
cv2.imshow("ImageResize",imgResize)
#cv2.imshow("Image Resize",imgResize)
cv2.imshow("Image Cropped",imgCropped)
cv2.waitKey(0)
OpenCV First Steps – Shapes and Texts
Have a look on this and explain it !!!!!!!!!
mport cv2
import numpy as np
img = np.zeros((512,512,3),np.uint8) #we create here a matrix with thre dimensions
#print(img)
img[:]= 255,0,0 #we can change the values between 0 and 255 to see what happens
cv2.line(img,(0,0),(img.shape[1],img.shape[0]),(0,255,0),3)
cv2.rectangle(img,(0,0),(250,350),(0,0,255),cv2.FILLED)
cv2.circle(img,(400,50),30,(255,255,0),5)
cv2.putText(img," OPENCV ",(300,200),cv2.FONT_HERSHEY_COMPLEX,0.5,(0,150,0),3)
cv2.imshow("Image",img)
cv2.waitKey(0)