Create a affineTransform proof of concept script that takes one image, finds points within it and to scale and distort an image to and then places it there.
This commit is contained in:
parent
800b5af94e
commit
80e4d8e251
|
@ -0,0 +1,29 @@
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
#outer template
|
||||||
|
outer = cv2.imread("graph.jpeg")
|
||||||
|
#inner image
|
||||||
|
inner = cv2.imread("emoji.jpeg")
|
||||||
|
|
||||||
|
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([[15, 15], [200, 30], [50, 140]])
|
||||||
|
|
||||||
|
# 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
|
||||||
|
cv2.imwrite("affine_poc.png", final)
|
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue