[ Python OpenCV ] 이미지 테두리 만들기 - cv.copyMakeBorder
1. Opencv 연결 및 이미지 불러오기
import cv2 as cv
# 이미지 경로
image = cv.imread('/home/heojungwook/VSCode
/cat.jpeg')
# 이미지 쇼 (Form Title Name)
cv.imshow('ORIGINAL', image)
2. 테두리 만들기 copyMakeBorder
def copyMakeBorder(src, top, bottom, left, right,
borderType, dst=None, value=None, /)
src - 이미지
top - 위쪽
bottom - 아래쪽
left - 왼쪽
right - 오른쪽
borderType - 테두리 종류
3. 기본 테두리 BORDER_DEFAULT
import cv2 as cv
# 이미지 경로
image = cv.imread('/home/heojungwook/VSCode
/cat.jpeg')
nTop = 20
nBottom = 20
nLeft = 20
nRight = 20
DEFAULT = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_DEFAULT)
cv.imshow('DEFAULT', DEFAULT)
4. 끊임없는 테두리 BORDER_CONSTANT
CONSTANT = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_CONSTANT)
cv.imshow('CONSTANT', CONSTANT)
5. 외딴 테두리 BORDER_ISOLATED
ISOLATED = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_ISOLATED)
cv.imshow('ISOLATED', ISOLATED)
6. 반사 테두리 BORDER_REFLECT
REFLECT = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_REFLECT)
cv.imshow('REFLECT', REFLECT)
7. 반사 101 테두리 BORDER_REFLECT101
REFLECT101 = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_REFLECT101)
cv.imshow('REFLECT101', REFLECT101)
8. 반사 _101 테두리 BORDER_REFLECT_101
REFLECT_101 = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_REFLECT_101)
cv.imshow('REFLECT_101', REFLECT_101)
9. 포장 테두리 BORDER_WRAP
WRAP = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_WRAP)
cv.imshow('WRAP', WRAP)
10. 전체 소스
import cv2 as cv
# 이미지 경로
image = cv.imread('/home/heojungwook/VSCode
/cat.jpeg')
# 이미지 쇼 (Form Title Name)
cv.imshow('ORIGINAL', image)
nTop = 20
nBottom = 20
nLeft = 20
nRight = 20
DEFAULT = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_DEFAULT)
cv.imshow('DEFAULT', DEFAULT)
CONSTANT = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_CONSTANT)
cv.imshow('CONSTANT', CONSTANT)
ISOLATED = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_ISOLATED)
cv.imshow('ISOLATED', ISOLATED)
REFLECT = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_REFLECT)
cv.imshow('REFLECT', REFLECT)
REFLECT101 = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_REFLECT101)
cv.imshow('REFLECT101', REFLECT101)
REFLECT_101 = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_REFLECT_101)
cv.imshow('REFLECT_101', REFLECT_101)
REPLICATE = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_REPLICATE)
cv.imshow('REPLICATE', REPLICATE)
WRAP = cv.copyMakeBorder(image, nTop, nBottom,
nLeft, nRight, borderType=cv.BORDER_WRAP)
cv.imshow('WRAP', WRAP)
# 일시정지
cv.waitKey(0)
==========
댓글
댓글 쓰기