From e560955537b0628d467ba5cc7b25c92c2cdcd7f4 Mon Sep 17 00:00:00 2001 From: mmattmcw Date: Wed, 8 Feb 2023 15:49:23 -0500 Subject: [PATCH] Make script more like proof of concept script. Still nothing. --- fourcell/apply_image.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/fourcell/apply_image.py b/fourcell/apply_image.py index 8f4080e..d9a4e1b 100644 --- a/fourcell/apply_image.py +++ b/fourcell/apply_image.py @@ -30,11 +30,12 @@ def create_blank(width, height): image = np.zeros((height, width, 3), np.uint8) color = tuple(reversed(rgb_color)) image[:] = color - return cv2.cvtColor(image, cv2.COLOR_RGB2RGBA) + return image + #return cv2.cvtColor(image, cv2.COLOR_RGB2RGBA) # get points 0, 1 and 3 = top left, top right and bottom left def to_points (d) : - return ((d['0']['x'], d['0']['y']),(d['1']['x'], d['1']['y']),(d['3']['x'], d['3']['y']),) + return [[d['0']['x'], d['0']['y']], [d['1']['x'], d['1']['y']], [d['3']['x'], d['3']['y']]] if len(sys.argv) < 2 : print('Please provide an output destination file') @@ -78,7 +79,8 @@ print(f"Image size {tmpl['width']}x{tmpl['height']}") hole = round(tmpl['width'] * holeConstant) blank = create_blank(tmpl['width'], tmpl['height']) -output = blank.copy() +#output = blank.copy() # +output = cv2.imread(templateFile.replace('.calibration.json', '')) hp = tmpl['holePunches'] for i in hp: @@ -87,12 +89,29 @@ for i in hp: #cv2.imwrite(outputFile, output) -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])}') +#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])}') + +target = cv2.imread(images[0]) +points = to_points(tmpl['0']) + +rows, cols, ch = output.shape +ir, ic, ich = target.shape + +print('Using points: ') +print(points) + +atPts = np.float32(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) + +output[0:rows, 0:cols] = dst cv2.imwrite(outputFile, output) print(f'Wrote {outputFile}')