import cv2
import matplotlib.pyplot as plt
import numpy as np
import dlib
my_image_path = './camera_sticker/images/image.png'
img_bgr = cv2.imread(my_image_path) # OpenCV๋ก ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฌ์ต๋๋ค
img_show = img_bgr.copy() # ์ถ๋ ฅ์ฉ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ก ๋ณด๊ดํฉ๋๋ค
plt.imshow(img_bgr) # ์ด๋ฏธ์ง ์ถ๋ ฅํ๊ธฐ
plt.show()
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
plt.show()
# detector๋ฅผ ์ ์ธํฉ๋๋ค
detector_hog = dlib.get_frontal_face_detector()
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
dlib_rects = detector_hog(img_rgb, 1) # (image, num of image pyramid)
print(dlib_rects)
for dlib_rect in dlib_rects:
l = dlib_rect.left()
t = dlib_rect.top()
r = dlib_rect.right()
b = dlib_rect.bottom()
cv2.rectangle(img_show, (l,t), (r,b), (0,255,0), 2, lineType=cv2.LINE_AA)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
rectangles[[(141, 201) (409, 468)]]
# ๋๋๋งํฌ ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ
model_path = './camera_sticker/models/shape_predictor_68_face_landmarks.dat'
landmark_predictor = dlib.shape_predictor(model_path)
list_landmarks = []
# ์ผ๊ตด ์์ญ ๋ฐ์ค ๋ง๋ค face landmark๋ฅผ ์ฐพ์๋
๋๋ค
for dlib_rect in dlib_rects:
points = landmark_predictor(img_rgb, dlib_rect)
# face landmark ์ขํ๋ฅผ ์ ์ฅํด๋ก๋๋ค
list_points = list(map(lambda p: (p.x, p.y), points.parts()))
list_landmarks.append(list_points)
print(len(list_landmarks[0]))
68
# landmark ์ ์ฐ๊ธฐ
for landmark in list_landmarks:
for point in landmark:
cv2.circle(img_show, point, 2, (0, 255, 255), -1)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
for dlib_rect, landmark in zip(dlib_rects, list_landmarks):
print (landmark[30]) # ์ฝ์ index๋ 30 ์
๋๋ค
x = landmark[30][0]
y = landmark[30][1]
w = h = dlib_rect.width()
print("(x, y) : ({}, {})".format(x, y))
print("(w, h) : ({}, {})".format(w, h))
(295, 339)
(x, y) : (295, 339)
(w, h) : (269, 269)
# ์คํฐ์ปค ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฌ์ต๋๋ค
sticker_path = './camera_sticker/images/cat-whiskers.png'
img_sticker = cv2.imread(sticker_path)
# ์ด๋ฏธ์ง Resize
img_sticker = cv2.resize(img_sticker, (w, h))
print (img_sticker.shape)
(269, 269, 3)
# RGB ์ด๋ฏธ์ง๋ก ๋ฐ๊พธ๊ธฐ
img_sticker_rgb = cv2.cvtColor(img_sticker, cv2.COLOR_BGR2RGB)
plt.imshow(img_sticker_rgb)
print (img_sticker_rgb.shape)
(269, 269, 3)
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ (์์ข)
refined_x = x - w // 2 # left
refined_y = y - h // 2 # top
print("(x, y) : ({}, {})".format(refined_x, refined_y))
(x, y) : (161, 205)
# ์คํฐ์ปค๊ฐ ์๋ณธ ์ด๋ฏธ์ง์ ๋ฒ์๋ฅผ ๋ฒ์ด๋ ๋
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('(x, y): (%d, %d)' %(refined_x, refined_y))
(x, y): (161, 205)
# img_show[from: to] ํ์
# ์๋ณธ ์ด๋ฏธ์ง์์ ์คํฐ์ปค ์ ์ฉํ ์์น cropํ ์ด๋ฏธ์ง
sticker_area = img_show[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]]
img_show[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]] = \
np.where(img_sticker==0, img_sticker, sticker_area).astype(np.uint8)
plt.imshow(cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB))
plt.show()
# ๊น๋ํ๊ฒ ์ ๋ฆฌ
# img_show ๋์ img_rbg ์ด์ฉํด๋ณด๊ธฐ
sticker_area = img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]]
img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]] = \
np.where(img_sticker==0, img_sticker, sticker_area).astype(np.uint8)
plt.imshow(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
plt.show()
## ๊ฐ๋ ๋ฐ๊ฟ๋ณด๊ธฐ
my_image_path = './camera_sticker/images/image2.png'
img_bgr = cv2.imread(my_image_path) # OpenCV๋ก ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_show = img_bgr.copy() # ์ถ๋ ฅ ์ด๋ฏธ์ง ๋ฐ๋ก ๋ณด๊ด
# RGB ๋ณํ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
plt.show()
# detector ์ ์ธ
detector_hog = dlib.get_frontal_face_detector()
# detector_hog๋ฅผ ์ด์ฉํด ์ผ๊ตด์ bounding box ์ถ์ถ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
dlib_rects = detector_hog(img_rgb, 1) # (image, # of image pyramid)
# ์ฐพ์ ์ผ๊ตด ์์ญ ๋ฐ์ค ๋ฆฌ์คํธ
print(dlib_rects)
for dlib_rect in dlib_rects:
l = dlib_rect.left() # ์ผ์ชฝ ์๋
t = dlib_rect.top() # ์ผ์ชฝ ์
r = dlib_rect.right() # ์ค๋ฅธ์ชฝ ์
b = dlib_rect.bottom() # ์ค๋ฅธ์ชฝ ์๋
cv2.rectangle(img_show, (l, t), (r, b), (0, 255, 0), 2, lineType=cv2.LINE_AA)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
rectangles[[(134, 206) (455, 527)]]
์ค ๋๋ค????
# ์ ์ฅํ landmark ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ
landmark_predictor = dlib.shape_predictor(model_path)
list_landmarks = []
# ์ผ๊ตด ์์ญ ๋ฐ์ค๋ง๋ค face landmark๋ฅผ ์ฐพ์๋ด๊ธฐ
for dlib_rect in dlib_rects:
points = landmark_predictor(img_rgb, dlib_rect) # (RGB, rectangle)
# face landmark ์ขํ ์ ์ฅํ๊ธฐ
list_points = list(map(lambda p: (p.x, p.y), points.parts()))
list_landmarks.append(list_points)
print(len(list_landmarks[0]))
# landmark ์ ์ฐ๊ธฐ
for landmark in list_landmarks:
for point in landmark:
cv2.circle(img_show, point, 2, (0, 255, 255), -1)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
68
# ์ขํ ํ์ธํ๊ธฐ
for dlib_rect, landmark in zip(dlib_rects, list_landmarks):
print(landmark[33]) # ์ฝ ๋์ index = 33
x = landmark[33][0]
y = landmark[33][1]
w = h = dlib_rect.width()
print('์ฝ์ ์์น (x, y) : (%d, %d)' %(x, y))
print('box ํฌ๊ธฐ (w, h) : (%d, %d)' %(w, h))
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ (top-left ์ขํ)
refined_x = x - w//2 # left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('์คํฐ์ปค ์ขํ (x, y): (%d, %d)' %(refined_x, refined_y))
(301, 421)
์ฝ์ ์์น (x, y) : (301, 421)
box ํฌ๊ธฐ (w, h) : (322, 322)
์คํฐ์ปค ์ขํ (x, y): (140, 260)
img_sticker = cv2.imread(sticker_path) # ์คํฐ์ปค ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_sticker = cv2.resize(img_sticker, (w, h)) # ์คํฐ์ปค resize
print(img_sticker.shape)
(322, 322, 3)
# (์ฝ์) x, y ์ขํ ์กฐ์ (top-left ์ขํ)
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ
refined_x = x - w//2# left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('(x, y): (%d, %d)' %(refined_x, refined_y))
(x, y): (140, 260)
# img_show ๋์ img_rbg ์ด์ฉํด๋ณด๊ธฐ
sticker_area = img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]]
img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]] = \
np.where(img_sticker==0, img_sticker, sticker_area).astype(np.uint8)
plt.imshow(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
plt.show()
my_image_path = './camera_sticker/images/image1.png'
img_bgr = cv2.imread(my_image_path) # OpenCV๋ก ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_show = img_bgr.copy() # ์ถ๋ ฅ ์ด๋ฏธ์ง ๋ฐ๋ก ๋ณด๊ด
# RGB ์ด๋ฏธ์ง๋ก ๋ณํ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
plt.show()
# detector ์ ์ธ
detector_hog = dlib.get_frontal_face_detector()
# detector_hog๋ฅผ ์ด์ฉํด ์ผ๊ตด์ bounding box ์ถ์ถ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
dlib_rects = detector_hog(img_rgb, 1) # (image, # of image pyramid)
# ์ฐพ์ ์ผ๊ตด ์์ญ ๋ฐ์ค ๋ฆฌ์คํธ
print(dlib_rects)
for dlib_rect in dlib_rects:
l = dlib_rect.left() # ์ผ์ชฝ ์๋
t = dlib_rect.top() # ์ผ์ชฝ ์
r = dlib_rect.right() # ์ค๋ฅธ์ชฝ ์
b = dlib_rect.bottom() # ์ค๋ฅธ์ชฝ ์๋
cv2.rectangle(img_show, (l, t), (r, b), (0, 255, 0), 2, lineType=cv2.LINE_AA)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
rectangles[[(141, 201) (409, 468)]]
์ค...์ธ์ํ๋ค???
# ์ ์ฅํ landmark ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ
landmark_predictor = dlib.shape_predictor(model_path)
list_landmarks = []
# ์ผ๊ตด ์์ญ ๋ฐ์ค๋ง๋ค face landmark๋ฅผ ์ฐพ์๋ด๊ธฐ
for dlib_rect in dlib_rects:
points = landmark_predictor(img_rgb, dlib_rect) # (RGB, rectangle)
# face landmark ์ขํ ์ ์ฅํ๊ธฐ
list_points = list(map(lambda p: (p.x, p.y), points.parts()))
list_landmarks.append(list_points)
print(len(list_landmarks[0]))
# landmark ์ ์ฐ๊ธฐ
for landmark in list_landmarks:
for point in landmark:
cv2.circle(img_show, point, 2, (0, 255, 255), -1)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
68
์ค~ ์ ๋ ์ฐํ.
# ์ขํ ํ์ธํ๊ธฐ
for dlib_rect, landmark in zip(dlib_rects, list_landmarks):
print(landmark[33]) # ์ฝ ๋์ index = 33
x = landmark[33][0]
y = landmark[33][1]
w = h = dlib_rect.width()
print('์ฝ์ ์์น (x, y) : (%d, %d)' %(x, y))
print('box ํฌ๊ธฐ (w, h) : (%d, %d)' %(w, h))
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ (top-left ์ขํ)
refined_x = x - w//2 # left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('์คํฐ์ปค ์ขํ (x, y): (%d, %d)' %(refined_x, refined_y))
(284, 337)
์ฝ์ ์์น (x, y) : (284, 337)
box ํฌ๊ธฐ (w, h) : (269, 269)
์คํฐ์ปค ์ขํ (x, y): (150, 203)
img_sticker = cv2.imread(sticker_path) # ์คํฐ์ปค ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_sticker = cv2.resize(img_sticker, (w, h)) # ์คํฐ์ปค resize
print(img_sticker.shape)
(269, 269, 3)
# (์ฝ์) x, y ์ขํ ์กฐ์ (top-left ์ขํ)
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ
refined_x = x - w//2# left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('(x, y): (%d, %d)' %(refined_x, refined_y))
(x, y): (150, 203)
# img_show ๋์ img_rbg ์ด์ฉํด๋ณด๊ธฐ
sticker_area = img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]]
img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]] = \
np.where(img_sticker==0, img_sticker, sticker_area).astype(np.uint8)
plt.imshow(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
plt.show()
์ค~ ๋ง์คํฌ ์ด ๊ณ ์์ด.
my_image_path = './camera_sticker/images/image3.png'
img_bgr = cv2.imread(my_image_path) # OpenCV๋ก ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_show = img_bgr.copy() # ์ถ๋ ฅ ์ด๋ฏธ์ง ๋ฐ๋ก ๋ณด๊ด
# RGB ์ด๋ฏธ์ง๋ก ๋ณํ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
plt.show()
# detector ์ ์ธ
detector_hog = dlib.get_frontal_face_detector()
# detector_hog๋ฅผ ์ด์ฉํด ์ผ๊ตด์ bounding box ์ถ์ถ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
dlib_rects = detector_hog(img_rgb, 1) # (image, # of image pyramid)
# ์ฐพ์ ์ผ๊ตด ์์ญ ๋ฐ์ค ๋ฆฌ์คํธ
print(dlib_rects)
for dlib_rect in dlib_rects:
l = dlib_rect.left() # ์ผ์ชฝ ์๋
t = dlib_rect.top() # ์ผ์ชฝ ์
r = dlib_rect.right() # ์ค๋ฅธ์ชฝ ์
b = dlib_rect.bottom() # ์ค๋ฅธ์ชฝ ์๋
cv2.rectangle(img_show, (l, t), (r, b), (0, 255, 0), 2, lineType=cv2.LINE_AA)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
rectangles[[(544, 296) (619, 370)]]
# ์ ์ฅํ landmark ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ
landmark_predictor = dlib.shape_predictor(model_path)
list_landmarks = []
# ์ผ๊ตด ์์ญ ๋ฐ์ค๋ง๋ค face landmark๋ฅผ ์ฐพ์๋ด๊ธฐ
for dlib_rect in dlib_rects:
points = landmark_predictor(img_rgb, dlib_rect) # (RGB, rectangle)
# face landmark ์ขํ ์ ์ฅํ๊ธฐ
list_points = list(map(lambda p: (p.x, p.y), points.parts()))
list_landmarks.append(list_points)
print(len(list_landmarks[0]))
# landmark ์ ์ฐ๊ธฐ
for landmark in list_landmarks:
for point in landmark:
cv2.circle(img_show, point, 1, (0, 255, 255), -1)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
68
# ์ขํ ํ์ธํ๊ธฐ
for dlib_rect, landmark in zip(dlib_rects, list_landmarks):
print(landmark[33]) # ์ฝ ๋์ index = 33
x = landmark[33][0]
y = landmark[33][1]
w = h = dlib_rect.width()
print('์ฝ์ ์์น (x, y) : (%d, %d)' %(x, y))
print('box ํฌ๊ธฐ (w, h) : (%d, %d)' %(w, h))
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ (top-left ์ขํ)
refined_x = x - w//2 # left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('์คํฐ์ปค ์ขํ (x, y): (%d, %d)' %(refined_x, refined_y))
(579, 338)
์ฝ์ ์์น (x, y) : (579, 338)
box ํฌ๊ธฐ (w, h) : (76, 76)
์คํฐ์ปค ์ขํ (x, y): (541, 300)
img_sticker = cv2.imread(sticker_path) # ์คํฐ์ปค ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_sticker = cv2.resize(img_sticker, (w, h)) # ์คํฐ์ปค resize
print(img_sticker.shape)
(76, 76, 3)
# (์ฝ์) x, y ์ขํ ์กฐ์ (top-left ์ขํ)
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ
refined_x = x - w//2# left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('(x, y): (%d, %d)' %(refined_x, refined_y))
(x, y): (541, 300)
# img_show ๋์ img_rbg ์ด์ฉํด๋ณด๊ธฐ
sticker_area = img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]]
img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]] = \
np.where(img_sticker==0, img_sticker, sticker_area).astype(np.uint8)
plt.imshow(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
plt.show()
my_image_path = './camera_sticker/images/image4.png'
img_bgr = cv2.imread(my_image_path) # OpenCV๋ก ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_show = img_bgr.copy() # ์ถ๋ ฅ ์ด๋ฏธ์ง ๋ฐ๋ก ๋ณด๊ด
# RGB ์ด๋ฏธ์ง๋ก ๋ณํ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
plt.show()
# detector ์ ์ธ
detector_hog = dlib.get_frontal_face_detector()
# detector_hog๋ฅผ ์ด์ฉํด ์ผ๊ตด์ bounding box ์ถ์ถ
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
dlib_rects = detector_hog(img_rgb, 1) # (image, # of image pyramid)
# ์ฐพ์ ์ผ๊ตด ์์ญ ๋ฐ์ค ๋ฆฌ์คํธ
print(dlib_rects)
for dlib_rect in dlib_rects:
l = dlib_rect.left() # ์ผ์ชฝ ์๋
t = dlib_rect.top() # ์ผ์ชฝ ์
r = dlib_rect.right() # ์ค๋ฅธ์ชฝ ์
b = dlib_rect.bottom() # ์ค๋ฅธ์ชฝ ์๋
cv2.rectangle(img_show, (l, t), (r, b), (0, 255, 0), 2, lineType=cv2.LINE_AA)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
rectangles[[(167, 242) (390, 464)]]
# ์ ์ฅํ landmark ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ
landmark_predictor = dlib.shape_predictor(model_path)
list_landmarks = []
# ์ผ๊ตด ์์ญ ๋ฐ์ค๋ง๋ค face landmark๋ฅผ ์ฐพ์๋ด๊ธฐ
for dlib_rect in dlib_rects:
points = landmark_predictor(img_rgb, dlib_rect) # (RGB, rectangle)
# face landmark ์ขํ ์ ์ฅํ๊ธฐ
list_points = list(map(lambda p: (p.x, p.y), points.parts()))
list_landmarks.append(list_points)
print(len(list_landmarks[0]))
# landmark ์ ์ฐ๊ธฐ
for landmark in list_landmarks:
for point in landmark:
cv2.circle(img_show, point, 2, (0, 255, 255), -1)
img_show_rgb = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)
plt.imshow(img_show_rgb)
plt.show()
68
# ์ขํ ํ์ธํ๊ธฐ
for dlib_rect, landmark in zip(dlib_rects, list_landmarks):
print(landmark[33]) # ์ฝ ๋์ index = 33
x = landmark[33][0]
y = landmark[33][1]
w = h = dlib_rect.width()
print('์ฝ์ ์์น (x, y) : (%d, %d)' %(x, y))
print('box ํฌ๊ธฐ (w, h) : (%d, %d)' %(w, h))
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ (top-left ์ขํ)
refined_x = x - w//2 # left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('์คํฐ์ปค ์ขํ (x, y): (%d, %d)' %(refined_x, refined_y))
(293, 383)
์ฝ์ ์์น (x, y) : (293, 383)
box ํฌ๊ธฐ (w, h) : (224, 224)
์คํฐ์ปค ์ขํ (x, y): (181, 271)
img_sticker = cv2.imread(sticker_path) # ์คํฐ์ปค ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
img_sticker = cv2.resize(img_sticker, (w, h)) # ์คํฐ์ปค resize
print(img_sticker.shape)
(224, 224, 3)
# (์ฝ์) x, y ์ขํ ์กฐ์ (top-left ์ขํ)
# ์คํฐ์ปค ์ด๋ฏธ์ง ์์ ์ขํ
refined_x = x - w//2# left
refined_y = y - h//2 # top
if refined_x < 0:
img_sticker = img_sticker[:, -refined_x:]
refined_x = 0
if refined_y < 0:
img_sticker = img_sticker[-refined_y:, :]
refined_y = 0
print('(x, y): (%d, %d)' %(refined_x, refined_y))
(x, y): (181, 271)
# img_show ๋์ img_rbg ์ด์ฉํด๋ณด๊ธฐ
sticker_area = img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]]
img_bgr[refined_y: refined_y+img_sticker.shape[0],
refined_x: refined_x+img_sticker.shape[1]] = \
np.where(img_sticker==0, img_sticker, sticker_area).astype(np.uint8)
plt.imshow(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
plt.show()
์์์ ๊ฒฐ๊ณผ์ ๋ฐ๋ผ ๋ง์คํฌ๋ฅผ ์ฐ๋ฉด ์ธ์์ด ์๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ์
์ ๊ฑธ...์ ์ธ์์ด ๋์ง???
๋ง์คํฌ๊ฐ ๋พฐ์กฑํด์ ์ฝ๋ก ์ธ์ํ๊ณ ์ ๋ถ๋ถ ์์์ด ์ ์ผ๋ก ์ธ์์ด ๋์๋ ํ๋ ์๊ฐ์ด ๋ฌ.
๋ง์คํฌ ์ฝ๋ถ๋ถ์ ๊ณ ์ ์ ๋ถ๋ถ์ด ํ์ด๋์์์ด ์ฝ๋ก ์ธ์๋ ๊ฒ ๊ฐ์.
์ ์ฒด ์ ์ 70%์ ๋๋ง ์ธ์์ด ๋๋ฉด ๋ ๊ฒ ๊ฐ๋ค๋ ์ถ์ธก.
-> ์ด๊ฑธ ์ด๋์ ํ์ธ ํ ์ ์์๊ฒ ๊ฐ์๋ฐ..
ํ๋ก์ ํธ๋ ํผ๋๋ฐฑ์ด ์์ด์ ์์ฌ์
์ผ๊ตด ๊ฐ๋์ ๋ฐ๋ผ ์คํฐ์ปค๋ฅผ ํ์ ์ํค๋ ๊ฒ๋ ์ ์ฉํด์ผ ํ ๋ฏ.
๋ฉ๋ฆฌ์ ์ดฌ์ํ๋ฉด ์ ์๋ ๊น์..
->> ๋๋๋ฐ์ ใ ใ
->> ๋๋๋ฐ์.. ใ ใ
->> ์ฌ์ง์ ์ธ์ํ ๋ ์คํ์๋๊ฐ ๋๋ฆฌ๋ฉด ์ฌ์ง์ด ์ ๋๋ก ์๋ํ์ง ์๋ ๊ฒ๊ณผ ๊ฐ์ง ์์๊น?
->> ์ธ์๋ฅ ์ด ์ข์์ผ ๊ทธ ํจ์จ ๊ฐ์น๊ฐ ์๋ ๊ฒ์ด๋..
๊ถ๊ธํด์ง ์ฌํญ์