From 34e515394863ee93c059fe005b56e103f3c57c72 Mon Sep 17 00:00:00 2001 From: mmattmcw Date: Wed, 8 Feb 2023 15:34:40 -0500 Subject: [PATCH] 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. --- fourcell/apply_image.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fourcell/apply_image.py b/fourcell/apply_image.py index 17148d6..8f4080e 100644 --- a/fourcell/apply_image.py +++ b/fourcell/apply_image.py @@ -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])}')