2023-02-10 20:36:51 +00:00
|
|
|
import cv2
|
|
|
|
import numpy as np
|
2023-02-20 23:16:16 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
username = os.getlogin()
|
2023-02-10 20:36:51 +00:00
|
|
|
|
|
|
|
#outer template
|
2023-02-20 23:16:16 +00:00
|
|
|
outer = cv2.imread(f"/home/{username}/Desktop/running/shot1-scans/image-2-normal.png")
|
2023-02-10 20:36:51 +00:00
|
|
|
#inner image
|
2023-02-20 23:16:16 +00:00
|
|
|
inner = cv2.imread(f"/home/{username}/Desktop/frame.jpg")
|
2023-02-10 20:36:51 +00:00
|
|
|
|
|
|
|
rows, cols, ch = outer.shape
|
|
|
|
ir, ic, ich = inner.shape
|
|
|
|
|
|
|
|
print(f'{cols}x{rows}')
|
|
|
|
print(f'{ic}x{ir}')
|
|
|
|
|
|
|
|
# destination ponts on outer image
|
|
|
|
pts1 = np.float32([[1445, 11429], [1445, 6832], [5009, 11429]])
|
|
|
|
|
|
|
|
# corresponding points on inner image
|
|
|
|
pts2 = np.float32([[0, 0], [ic, 0], [0, ir]])
|
|
|
|
|
|
|
|
# transform inner to points on outer
|
|
|
|
M = cv2.getAffineTransform(pts2, pts1)
|
|
|
|
|
|
|
|
# apply
|
|
|
|
dst = cv2.warpAffine(inner, M, (cols, rows), borderMode=cv2.BORDER_TRANSPARENT)
|
|
|
|
|
|
|
|
final = outer.copy()
|
|
|
|
final[0:rows, 0:cols] = dst
|
2023-02-20 23:16:16 +00:00
|
|
|
|
2023-02-10 20:36:51 +00:00
|
|
|
cv2.imwrite("affine_poc2.png", final)
|