Perform action in BGRA and then reduce back to BGA for export

This commit is contained in:
Matt McWilliams 2023-02-20 18:41:11 -05:00
parent 370e76aaaa
commit 0af8b43606
1 changed files with 10 additions and 3 deletions

View File

@ -12,8 +12,10 @@ username = os.getlogin()
#outer template #outer template
outer = cv2.imread(f"/home/{username}/Desktop/running/shot1-scans/image-2-normal.png") outer = cv2.imread(f"/home/{username}/Desktop/running/shot1-scans/image-2-normal.png")
outer = cv2.cvtColor(outer, cv2.COLOR_BGR2BGRA)
#inner image #inner image
inner = cv2.imread(f"/home/{username}/Desktop/frame.jpg") inner = cv2.imread(f"/home/{username}/Desktop/frame.jpg")
inner = cv2.cvtColor(inner, cv2.COLOR_BGR2BGRA)
rows, cols, ch = outer.shape rows, cols, ch = outer.shape
ir, ic, ich = inner.shape ir, ic, ich = inner.shape
@ -31,14 +33,19 @@ pts2 = np.float32([[0, 0], [ic, 0], [0, ir]])
M = cv2.getAffineTransform(pts2, pts1) M = cv2.getAffineTransform(pts2, pts1)
# apply # apply
dst = cv2.warpAffine(inner, M, (cols, rows), borderMode=cv2.BORDER_TRANSPARENT) dst = cv2.warpAffine(inner, M, (cols, rows),
flags = cv2.INTER_CUBIC,
borderMode = cv2.BORDER_CONSTANT,
borderValue = [0, 0, 0, 0]
)
lower = np.array([0,0,0]) lower = np.array([0,0,0,0])
upper= np.array([0,0,0]) upper= np.array([0,0,0,0])
# Create a mask. Threshold the HSV image to get only yellow colors # Create a mask. Threshold the HSV image to get only yellow colors
mask = cv2.inRange(dst, lower, upper) mask = cv2.inRange(dst, lower, upper)
mask = cv2.bitwise_not(mask) mask = cv2.bitwise_not(mask)
final = combine_images(outer, dst, mask) final = combine_images(outer, dst, mask)
final = cv2.cvtColor(final, cv2.COLOR_BGRA2BGR)
cv2.imwrite("affine_poc3.png", final) cv2.imwrite("affine_poc3.png", final)