๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
[Python ์ผ๋ก ์์์ฒ๋ฆฌ (1)] cv2.seamlessClone() ์์์ ์กฐํ๋ก์!! ๋ณธ๋ฌธ
๐ฉ๐ป IoT (Embedded)/Image Processing
[Python ์ผ๋ก ์์์ฒ๋ฆฌ (1)] cv2.seamlessClone() ์์์ ์กฐํ๋ก์!!
์ง์ง์ํ์นด 2023. 12. 28. 10:34728x90
๋ฐ์ํ
๐ NORMAL & MIXED
import cv2
import numpy as np
# ํ๋ ฌ (์ ์ ๋ณด b g r)
logo = cv2.imread('images/logo.png')
lena = cv2.imread('images/lena.jpg')
mask = np.full_like(logo, 255)
height, width = lena.shape[:2]
center = (width//2, height//2)
# ์์ค ์ด๋ฏธ์ง, destination, ๋ณต์ ์ฃผ๋ณ mask, center ์ด๋ฏธ์ง, flag
normal = cv2.seamlessClone(logo, lena, mask, center, cv2.NORMAL_CLONE) # ๋ธ๋ฌ์ฒ๋ฆฌ
mixed = cv2.seamlessClone(logo, lena, mask, center, cv2.MIXED_CLONE) # ์กฐํ๋กญ๊ฒ
cv2.imshow('normal', normal)
cv2.imshow('mixed', mixed)
cv2.waitKey(0)
cv2.destroyAllWindows()
๐ NORMAL & POLY (ํน์ ์ฃ์ง ๋๋ ค๋ด๊ธฐ..)
import cv2
import numpy as np
# Read images
src = cv2.imread("images/airplane2.jpg")
dst = cv2.imread("images/red_sky.jpg")
# Create a rough mask around the airplane.
src_mask = np.zeros(src.shape, src.dtype)
# ์ฃผ๋ณ ๋๋ ค๋ด๊ธฐ...
poly = np.array([ (0,40), (150,60), (203,56), (200,100), (88,103), (1,75) ], np.int32)
# poly = np.array([ [4,80], [30,54], [151,63], [254,37], [298,90], [272,134], [43,122] ], np.int32)
cv2.fillPoly(src_mask, [poly], (255, 255, 255))
# This is where the CENTER of the airplane will be placed
center = (600,150)
# Clone seamlessly.
output = cv2.seamlessClone(src, dst, src_mask, center, cv2.NORMAL_CLONE)
# Save result
cv2.imshow('Output', output)
cv2.waitKey(0)
cv2.destroyAllWindows()
๐ NORMAL & POLY
import cv2
import numpy as np
src = cv2.imread("images/airplane1.jpg")
dst = cv2.imread("images/sunset2.jpg")
src_mask = np.zeros(src.shape, src.dtype)
poly = np.array([ [4,190], [160,220], [640,150], [630,180], [690,240], [340,310], [15,300] ], np.int32)
#poly = np.array([ [0,40], [150,60], [203,56], [200,100], [88,103], [1,75] ], np.int32)
#poly = np.array([ [4,80], [30,54], [151,63], [254,37], [298,90], [272,134], [43,122] ], np.int32)
cv2.fillPoly(src_mask, [poly], (255, 255, 255))
center = (600,300)
output = cv2.seamlessClone(src, dst, src_mask, center, cv2.NORMAL_CLONE)
cv2.imshow('Output', output)
cv2.waitKey(0)
cv2.destroyAllWindows()
๐ NORMAL & POLY & webcam
import cv2
src = cv2.imread("images/airplane2.jpg")
src_mask = np.zeros(src.shape, src.dtype)
poly = np.array([ [0,40], [150,60], [203,56], [200,100], [88,103], [1,75] ], np.int32)
cv2.fillPoly(src_mask, [poly], (255, 255, 255))
center = (200,150)
cap = cv2.VideoCapture(0)
if cap.isOpened():
print(cap.get(cv2.CAP_PROP_FPS))
delay = int(1000 / cap.get(cv2.CAP_PROP_FPS))
while True:
ret, img = cap.read()
if ret:
output = cv2.seamlessClone(src, img, src_mask, center, cv2.NORMAL_CLONE)
cv2.imshow("Movie", output)
if cv2.waitKey(delay) & 0xFF == 27 : # ESCํค
print("ESC Key pressed")
break
else:
print("No Frame")
print(ret, img)
break
else:
print("File not opened")
cap.release()
cv2.destroyAllWindows()
728x90
๋ฐ์ํ
'๐ฉโ๐ป IoT (Embedded) > Image Processing' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python ์ผ๋ก ์์์ฒ๋ฆฌ (3)] cv2.threshold() (0) | 2023.12.28 |
---|---|
[Python ์ผ๋ก ์์์ฒ๋ฆฌ (2)] ์ด์งํ (0) | 2023.12.28 |
[C++ ๋ก OpenCV ๊ตฌํํ๊ธฐ] (11) Project3 - License Plate Detector (0) | 2023.06.14 |
[C++ ๋ก OpenCV ๊ตฌํํ๊ธฐ] (10) Project2 - Document Scanner (1) | 2023.06.14 |
[C++ ๋ก OpenCV ๊ตฌํํ๊ธฐ] (9) Project1 - Virtual Painter (0) | 2023.06.13 |
Comments