Tried more approaches

This commit is contained in:
Matt McWilliams 2023-02-09 22:17:18 -05:00
parent e560955537
commit 28d959ff1b
1 changed files with 14 additions and 8 deletions

View File

@ -23,15 +23,16 @@ def apply_image_to_points (original, target, points) :
original[0:rows, 0:cols] = dst
return original
#return original
return cv2.cvtColor(original, cv2.COLOR_BGR2BGRA)
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
return image
#return cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
#return image
return cv2.cvtColor(image, cv2.COLOR_BGR2BGRA)
# get points 0, 1 and 3 = top left, top right and bottom left
def to_points (d) :
@ -79,8 +80,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 = cv2.imread(templateFile.replace('.calibration.json', ''))
output = blank.copy() #
#output = cv2.imread(templateFile.replace('.calibration.json', ''))
hp = tmpl['holePunches']
for i in hp:
@ -97,6 +98,7 @@ for i in hp:
# print(f'Applied {basename(images[i])}')
target = cv2.imread(images[0])
target = cv2.cvtColor(target, cv2.COLOR_BGR2BGRA)
points = to_points(tmpl['0'])
rows, cols, ch = output.shape
@ -109,9 +111,13 @@ 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)
dst = cv2.warpAffine(target, M, (cols, rows),
flags = cv2.INTER_CUBIC,
borderMode = cv2.BORDER_CONSTANT,
borderValue = [0, 0, 0, 0])
output[0:rows, 0:cols] = dst
cv2.imwrite(outputFile, output)
print(f'Wrote {outputFile}')
display(output)
#cv2.imwrite(outputFile, output)
##print(f'Wrote {outputFile}')