0% found this document useful (0 votes)
26 views

Drawing Functions

The document discusses various drawing functions in OpenCV like drawing lines, arrows, rectangles, circles, text and ellipses on images. It shows code snippets to use these functions and customize properties like color, thickness. It also discusses creating blank images to draw on and changing background color to black or white.

Uploaded by

Raj Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Drawing Functions

The document discusses various drawing functions in OpenCV like drawing lines, arrows, rectangles, circles, text and ellipses on images. It shows code snippets to use these functions and customize properties like color, thickness. It also discusses creating blank images to draw on and changing background color to black or white.

Uploaded by

Raj Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Drawing Functions

Lec 9
Image Print

import cv2

img = cv2.imread("F:\Taj.jpg")

cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Image
Line Drawing On Image
import cv2

img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))

#here Line Accept 5 parameter(img,starting,ending,color,thickness)


img = cv2.line(img,(0,0),(200,200),(154,92,424),8) #color format BGR

cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
RGB COLOR 0-255
• Open Web Browser and write Online Color Picker
• Chose the value of RGB and Write it in BGR
Arrowed Line
import cv2

img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))

#here Line Accept 5


parameter(img,starting,ending,color,thickness)
img = cv2.line(img,(0,0),(200,200),
(245,7,31),10) #color format BGR

#arrowed Line accept also 5 parameter (img,


starting, ending,color, thickness)
img = cv2.arrowedLine(img, (0,125), (255,255),
(255,0,125),10)

cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Rectangle
Rectangle
import cv2

img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))

#here Line Accept 5 parameter(img,starting,ending,color,thickness)


img = cv2.line(img,(0,0),(200,200),(245,7,31),10) #color format BGR

#arrowed Line accept also 5 parameter (img, starting, ending,color, thickness)


img = cv2.arrowedLine(img, (0,125), (255,255), (255,0,125),10)

#Rectangle - accept parameter(img,start_co, ending_co, color, thickness )


img = cv2.rectangle(img,(384,10), (510,128),(128,0,255),8)

cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Rectangle (-1)
Rectangle (-1)
import cv2

img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))

#here Line Accept 5 parameter(img,starting,ending,color,thickness)


img = cv2.line(img,(0,0),(200,200),(245,7,31),10) #color format BGR

#arrowed Line accept also 5 parameter (img, starting, ending,color, thickness)


img = cv2.arrowedLine(img, (0,125), (255,255), (255,0,125),10)

#Rectangle - accept parameter(img,start_co, ending_co, color, thickness )


img = cv2.rectangle(img,(384,10), (510,128),(128,0,255),-1)

cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))
Circle
#here Line Accept 5
parameter(img,starting,ending,color,thickness)
img = cv2.line(img,(0,0),(200,200),(245,7,31),10)
#color format BGR
#arrowed Line accept also 5 parameter (img,
starting, ending,color, thickness)
img = cv2.arrowedLine(img, (0,125), (255,255),
(255,0,125),10)
#Rectangle - accept parameter(img,start_co,
ending_co, color, thickness )
img = cv2.rectangle(img,(384,10), (510,128),
(128,0,255),5)
#Circle - accept parameter(img,
start_co,ending_co, radius, color, thickness)
img = cv2.circle((img), (247,125,), 63,
(214,255,0), 5)
cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))
#here Line Accept 5
Circle -5
parameter(img,starting,ending,color,thickness)
img = cv2.line(img,(0,0),(200,200),
(245,7,31),10) #color format BGR
#arrowed Line accept also 5 parameter (img,
starting, ending,color, thickness)
img = cv2.arrowedLine(img, (0,125), (255,255),
(255,0,125),10)
#Rectangle - accept parameter(img,start_co,
ending_co, color, thickness )
img = cv2.rectangle(img,(384,10), (510,128),
(128,0,255),5)
#Circle - accept parameter(img,
start_co,ending_co, radius, color, thickness)
img = cv2.circle((img), (247,125,), 63,
(214,255,0),-5)
cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
TEXT
font = cv2.FONT_ITALIC
#put text accept(img, text,start_co,font,
fontsize, color, thickness, Linetype)
img = cv2.putText((img), 'Umair', (20,500), font,
4, (0,125,255),10,cv2.LINE_AA)
import cv2
img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))
#here Line Accept 5 parameter(img,starting,ending,color,thickness)
img = cv2.line(img,(0,0),(200,200),(245,7,31),10) #color format BGR
#arrowed Line accept also 5 parameter (img, starting, ending,color, thickness)
img = cv2.arrowedLine(img, (0,125), (255,255), (255,0,125),10)
#Rectangle - accept parameter(img,start_co, ending_co, color, thickness )
img = cv2.rectangle(img,(384,10), (510,128),(128,0,255),5)
#Circle - accept parameter(img, start_co,ending_co, radius, color, thickness)
img = cv2.circle((img), (247,125,), 63, (214,255,0),-5)

font = cv2.FONT_ITALIC
#put text accept(img, text,start_co,font, fontsize, color, thickness, Linetype)
img = cv2.putText((img), 'Umair', (20,500), font, 4, (0,125,255),10,cv2.LINE_AA)
cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Elipse

#Elipse - accept (img, start_cor, (length,


height),color, thickness)

img = cv2.ellipse(img, (400,600),


(100,50),0,0,360,155,5)
import cv2
img = cv2.imread("F:\Taj.jpg")
img = cv2.resize(img,(600,700))
#here Line Accept 5 parameter(img,starting,ending,color,thickness)
img = cv2.line(img,(0,0),(200,200),(245,7,31),10) #color format BGR
#arrowed Line accept also 5 parameter (img, starting, ending,color, thickness)
img = cv2.arrowedLine(img, (0,125), (255,255), (255,0,125),10)
#Rectangle - accept parameter(img,start_co, ending_co, color, thickness )
img = cv2.rectangle(img,(384,10), (510,128),(128,0,255),5)
#Circle - accept parameter(img, start_co,ending_co, radius, color, thickness)
img = cv2.circle((img), (247,125,), 63, (214,255,0),-5)

font = cv2.FONT_ITALIC
#put text accept(img, text,start_co,font, fontsize, color, thickness, Linetype)
img = cv2.putText((img), 'Umair', (20,500), font, 4, (0,125,255),10,cv2.LINE_AA)

#Elipse - accept (img, start_cor, (length, height),color, thickness)

img = cv2.ellipse(img, (400,600),(100,50),0,0,360,155,5)

cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Blank Image
import numpy as np
import cv2
#img = cv2.imread("F:\Taj.jpg")
#img = cv2.resize(img,(600,700))
img = np.zeros([512,512,3],np.uint8)*255 #for black screen
#here Line Accept 5 parameter(img,starting,ending,color,thickness)
img = cv2.line(img,(0,0),(200,200),(245,7,31),10) #color format BGR
#arrowed Line accept also 5 parameter (img, starting, ending,color, thickness)
img = cv2.arrowedLine(img, (0,125), (255,255), (255,0,125),10)
#Rectangle - accept parameter(img,start_co, ending_co, color, thickness )
img = cv2.rectangle(img,(384,10), (510,128),(128,0,255),5)
#Circle - accept parameter(img, start_co,ending_co, radius, color, thickness)
img = cv2.circle((img), (247,125,), 63, (214,255,0),5)

font = cv2.FONT_ITALIC
#put text accept(img, text,start_co,font, fontsize, color, thickness, Linetype)
img = cv2.putText((img), 'Umair', (20,500), font, 4, (0,125,255),10,cv2.LINE_AA)

#Elipse - accept (img, start_cor, (length, height),color, thickness)

img = cv2.ellipse(img, (400,600),(100,50),0,0,360,125,-2)

cv2.imshow("res", img)
cv2.waitKey(0)
For White Screen
img = np.ones([512,512,3],np.uint8)*255
import numpy as np
import cv2
#img = cv2.imread("F:\Taj.jpg")
#img = cv2.resize(img,(600,700))
#img = np.zeros([512,512,3],np.uint8)*255 #for black screen
img = np.ones([512,512,3],np.uint8)*255
#here Line Accept 5 parameter(img,starting,ending,color,thickness)
img = cv2.line(img,(0,0),(200,200),(245,7,31),10) #color format BGR
#arrowed Line accept also 5 parameter (img, starting, ending,color, thickness)
img = cv2.arrowedLine(img, (0,125), (255,255), (255,0,125),10)
#Rectangle - accept parameter(img,start_co, ending_co, color, thickness )
img = cv2.rectangle(img,(384,10), (510,128),(128,0,255),5)
#Circle - accept parameter(img, start_co,ending_co, radius, color, thickness)
img = cv2.circle((img), (247,125,), 63, (214,255,0),5)

font = cv2.FONT_ITALIC
#put text accept(img, text,start_co,font, fontsize, color, thickness, Linetype)
img = cv2.putText((img), 'Umair', (20,500), font, 4, (0,125,255),10,cv2.LINE_AA)

#Elipse - accept (img, start_cor, (length, height),color, thickness)


img = cv2.ellipse(img, (400,600),(100,50),0,0,360,125,-2)
cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

You might also like