-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.py
38 lines (28 loc) · 862 Bytes
/
basic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#basic functions of opencv
import cv2 as cv
img = cv.imread('Photos/park.jpg')
cv.imshow('Park',img)
#Converting an image to grayscale
gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.imshow('gray',gray)
#Blur
blur = cv.GaussianBlur(img,(7,7),cv.BORDER_DEFAULT)# here 7,7 helps in bluring the image and it should be an odd number
cv.imshow('blur',blur)
#Edge cascade
canny = cv.Canny(img,125,175)
cv.imshow('edges',canny)
canny1 = cv.Canny(blur,125,175)#for blur
cv.imshow('Edges',canny1)
#Dilating the image
dilated = cv.dilate(canny,(3,3),iterations= 3)
cv.imshow('dilate',dilated)
#Eroding
eroded = cv.erode(dilated,(3,3),iterations=1)
cv.imshow('Erode',eroded)
#Resize
resize = cv.resize(img,(500,500))
cv.imshow("resized",resize)
#Cropping
cropped = img[50:200, 200:400]
cv.imshow('Cropped',cropped)
cv.waitKey(0)