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

ComputerGraphicsStudyNotes0313 Week3 01

The document discusses OpenCV tutorials for Python including downloading OpenCV, reading image file formats, and drawing basic shapes like lines, rectangles, circles, ellipses, and polygons onto images using OpenCV functions. Code examples are provided for each OpenCV drawing function.

Uploaded by

MD KAMRUZZAMAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

ComputerGraphicsStudyNotes0313 Week3 01

The document discusses OpenCV tutorials for Python including downloading OpenCV, reading image file formats, and drawing basic shapes like lines, rectangles, circles, ellipses, and polygons onto images using OpenCV functions. Code examples are provided for each OpenCV drawing function.

Uploaded by

MD KAMRUZZAMAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

StudyNotes0313-Week3-01
1.1. Study Material
1.1.1. PDF file
opencv24-python-tutorials-readthedocs-io-en-stable.pdf

1.1.2. Online website


just search openCV python tutorial on internet

https://www.javatpoint.com/opencv

OpenCV Tutorial | OpenCV using Python

1.2. Start Jupyter


run command “jupyter notebook d:/demo0314” in Anaconda Prompt

1.2.1. get openCV version

1.2.2. file formats


The imread() of OpenCV function returns a matrix, if the image cannot be read because of
unsupported file format, missing file, unsupported or invalid format. Currently, the following file
formats are supported.
Window bitmaps - *.bmp, *.dib
JPEG files - *.jpeg, *.jpg, *.jpe
Portable Network Graphics - *.png
Portable image format- *.pbm, *.pgm, *.ppm
TIFF files - *.tiff, *.tif

1.3. Drawing Shapes


1.3.1. Drawing Line

import cv2
import numpy as np

#Create a black image

img = np.zeros((512,512,3), np.uint8)

#Draw a diagonal blue line with thickness of 5 px

img = cv2.line(img,(50,50),(150,50),(255,255,0),5)
cv2.imshow('Draw Line',img)
cv2.waitKey(0)
cv2.destroyAllWindows() #Press Tab after 'de' will prompt full name of API
1.3.2. Drawing Rectangle
img = cv2.rectangle(img,(384,0),(510,128),(0,255,0),3)

import cv2
import numpy as np
#Create a black image
img = np.zeros((512,512,3), np.uint8)
#Draw a diagonal blue line with thickness of 5 px
img = cv2.rectangle(img,(50,50),(150,150),(0,255,0),3)
cv2.imshow('Draw Rectange',img)
cv2.waitKey(0)
cv2.destroyAllWindows() #Press Tab after 'de' will prompt full name of API
1.3.3. Drawing Circle
img = cv2.circle(img,(447,63), 63, (0,0,255), -1)

print(help(cv2.circle))

import cv2
import numpy as np
#Create a black image
img = np.zeros((512,512,3), np.uint8)
#Draw a diagonal blue line with thickness of 5 px
img = cv2.rectangle(img,(50,50),(150,150),(0,255,0),3)
img = cv2.circle(img,(100,100), 50, (0,0,255), -1)
cv2.imshow('Draw Rectange',img)
cv2.waitKey(0)
cv2.destroyAllWindows() #Press Tab after 'de' will prompt full name of API

1.3.4. Drawing Ellipse


img = cv2.ellipse(img,(256,256),(100,50),0,0,180,255,-1)

1.3.5. Drawing Polygon


pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)

pts = pts.reshape((-1,1,2))

img = cv2.polylines(img,[pts],True,(0,255,255))
1.3.6. Adding Text to Images
font = cv2.FONT_HERSHEY_SIMPLEX

cv2.putText(img,'OpenCV',(10,500), font, 4,(255,255,255),2,cv2.LINE_AA)

1.4. No HomeWork
 

You might also like