Moved everything into RGBA from RGB in case alpha channel allowed for proper use. Not working. Cannot understand why proof of concept works but not this.

This commit is contained in:
Matt McWilliams 2023-02-08 15:34:40 -05:00
parent a1a57ef58c
commit 34e5153948
1 changed files with 8 additions and 9 deletions

View File

@ -19,20 +19,18 @@ def apply_image_to_points (original, target, points) :
targetPts = np.float32([[0, 0], [ic, 0], [0, ir]])
M = cv2.getAffineTransform(targetPts, atPts)
dst = cv2.warpAffine(target, M, (cols, rows), borderMode=cv2.BORDER_TRANSPARENT)
dst = cv2.warpAffine(target, M, (cols, rows)) #, borderMode=cv2.BORDER_TRANSPARENT
output = original.copy()
output[0:rows, 0:cols] = dst
original[0:rows, 0:cols] = dst
return output
return original
def create_blank(width, height):
rgb_color=(255,255,255)
image = np.zeros((height, width, 3), np.uint8)
color = tuple(reversed(rgb_color))
image[:] = color
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
return cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
return cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
# get points 0, 1 and 3 = top left, top right and bottom left
def to_points (d) :
@ -79,9 +77,8 @@ tmpl = read_json(templateFile)
print(f"Image size {tmpl['width']}x{tmpl['height']}")
hole = round(tmpl['width'] * holeConstant)
#blank = create_blank(tmpl['width'], tmpl['height'])
output = cv2.imread(templateFile.replace('.calibration.json', ''))#blank.copy()
blank = create_blank(tmpl['width'], tmpl['height'])
output = blank.copy()
hp = tmpl['holePunches']
for i in hp:
@ -92,6 +89,8 @@ for i in hp:
for i in range(0, len(images)) :
frame = cv2.imread(images[i])
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2RGBA)
cv2.imwrite(f'test{i}.png', output)
output = apply_image_to_points(output, frame, to_points(tmpl[f'{i}']))
print(f'Applied {basename(images[i])}')