본문 바로가기
OpenCV

[OpenCV] basic.py

by Lizardee 2024. 4. 10.
Basic Functions in OpenCV
import cv2 as cv

# Reading an image
img = cv.imread('Photos/boston.jpg')
cv.imshow('Boston', img)

# 1. Converting to grayscale
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)


# 2. Blur
blur = cv.GaussianBlur(img, (7,7), cv.BORDER_DEFAULT)
cv.imshow('Blur', blur)


# 3. Edge cascade
canny = cv.Canny(img, 125, 175)
cv.imshow('Canny Edges', canny)


# 4. Dilating the image
dilated = cv.dilate(canny, (7,7), iterations=3)
cv.imshow('Dilated', dilated)


# 5. Eroding
eroded = cv.erode(dilated, (3,3), iterations=3)
cv.imshow('Eroded', eroded)


# 6. Resize
resized = cv.resize(img, (500,500), interpolation=cv.INTER_CUBIC)
cv.imshow('Resize', resized)


# 7. Cropping
cropped = img[50:200, 200:400]
cv.imshow('Cropped', cropped)


cv.waitKey(0)

 

'OpenCV' 카테고리의 다른 글

[OpenCV] contours.py  (0) 2024.04.10
[OpenCV] transformations.py  (0) 2024.04.10
[OpenCV] draw.py  (0) 2024.04.10
[OpenCV] rescale.py  (0) 2024.04.10
[OpenCV] read.py  (0) 2024.04.10