3. Table of contents
• Introduction
• Drawing shapes and lines
• Simple & Logical operations on images
• Threshold & Watermark
• Morphologic transformations
• Edge & Corner Detection
4. Table of contents
• Object recognition with Template & Feature Matching
• Histogram of images
• Color spaces (RGB, BGR, HSV)
• Video and Color detection
• Video – Face detection
• Video – Hand gesture Detection
5. Drawing shapes and lines
import cv2
import numpy as np
#creating a black square
image=np.zeros((512,512,3),np.uint8)
#we can also create this in black and white,however there would not be any changes
image_bw=np.zeros((512,512),np.uint8)
cv2.imshow("black rectangle(color)",image)
cv2.imshow("black rectangle(B&W)",image_bw)
6. • #create a line over black square
• #cv2.line(image, starting coordinates, ending coordinates, color, thickness)
• #drawing a diagonal line of thickness 6 pixels
• image=np.zeros((512,512,3),np.uint8)
• cv2.line(image,(0,0),(511,511),(255,127,0),6)
• cv2.imshow("blue line",image)
Drawing shapes and lines
7. • #create a rectangle over a black square
• #cv2.rectangle(image,starting coordinates, ending coordinates,
color, thickness)
• #drawing a rectangle of thickness 5 pixels
• image=np.zeros((512,512,3),np.uint8)
• cv2.rectangle(image,(30,50),(100,150),(255,127,0),5)
• cv2.imshow("rectangle",image)
Drawing shapes and lines
8. • #creating a circle over a black square
• #cv2.circle(image,center,radius,color,fill)
• image=np.zeros((512,512,3),np.uint8)
• cv2.circle(image,(100,100),(50),(255,127,0),-1)
• cv2.imshow("circle",image)
Drawing shapes and lines
9. • #creating a polygon
• image=np.zeros((512,512,3),np.uint8)
• #lets define four points
• pts=np.array([[10,50], [400,60], [30,89], [90,68]], np.int32)
• #lets now reshape our points in form required by polylines
• pts=pts.reshape((-1,1,2))
• cv2.polylines(image, [pts], True, (0,255,255), 3)
• cv2.imshow("polygon",image)
Drawing shapes and lines
10. • #putting text using opencv
• #cv2.putText(image,'text to display',bootom left starting point, font,font
size, color, thickness)
• image=np.zeros((512,512,3),np.uint8)
• cv2.putText(image,"hello world", (75,290),
cv2.FONT_HERSHEY_COMPLEX,2,(100,170,0),3)
• cv2.imshow("hello world",image)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
Drawing shapes and lines
hello world