Make script more like proof of concept script. Still nothing.

This commit is contained in:
Matt McWilliams 2023-02-08 15:49:23 -05:00
parent 34e5153948
commit e560955537
1 changed files with 28 additions and 9 deletions

View File

@ -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}')