Tried more approaches
This commit is contained in:
parent
e560955537
commit
28d959ff1b
|
@ -23,15 +23,16 @@ def apply_image_to_points (original, target, points) :
|
||||||
|
|
||||||
original[0:rows, 0:cols] = dst
|
original[0:rows, 0:cols] = dst
|
||||||
|
|
||||||
return original
|
#return original
|
||||||
|
return cv2.cvtColor(original, cv2.COLOR_BGR2BGRA)
|
||||||
|
|
||||||
def create_blank(width, height):
|
def create_blank(width, height):
|
||||||
rgb_color=(255,255,255)
|
rgb_color=(255,255,255)
|
||||||
image = np.zeros((height, width, 3), np.uint8)
|
image = np.zeros((height, width, 3), np.uint8)
|
||||||
color = tuple(reversed(rgb_color))
|
color = tuple(reversed(rgb_color))
|
||||||
image[:] = color
|
image[:] = color
|
||||||
return image
|
#return image
|
||||||
#return cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
|
return cv2.cvtColor(image, cv2.COLOR_BGR2BGRA)
|
||||||
|
|
||||||
# get points 0, 1 and 3 = top left, top right and bottom left
|
# get points 0, 1 and 3 = top left, top right and bottom left
|
||||||
def to_points (d) :
|
def to_points (d) :
|
||||||
|
@ -79,8 +80,8 @@ print(f"Image size {tmpl['width']}x{tmpl['height']}")
|
||||||
|
|
||||||
hole = round(tmpl['width'] * holeConstant)
|
hole = round(tmpl['width'] * holeConstant)
|
||||||
blank = create_blank(tmpl['width'], tmpl['height'])
|
blank = create_blank(tmpl['width'], tmpl['height'])
|
||||||
#output = blank.copy() #
|
output = blank.copy() #
|
||||||
output = cv2.imread(templateFile.replace('.calibration.json', ''))
|
#output = cv2.imread(templateFile.replace('.calibration.json', ''))
|
||||||
|
|
||||||
hp = tmpl['holePunches']
|
hp = tmpl['holePunches']
|
||||||
for i in hp:
|
for i in hp:
|
||||||
|
@ -97,6 +98,7 @@ for i in hp:
|
||||||
# print(f'Applied {basename(images[i])}')
|
# print(f'Applied {basename(images[i])}')
|
||||||
|
|
||||||
target = cv2.imread(images[0])
|
target = cv2.imread(images[0])
|
||||||
|
target = cv2.cvtColor(target, cv2.COLOR_BGR2BGRA)
|
||||||
points = to_points(tmpl['0'])
|
points = to_points(tmpl['0'])
|
||||||
|
|
||||||
rows, cols, ch = output.shape
|
rows, cols, ch = output.shape
|
||||||
|
@ -109,9 +111,13 @@ atPts = np.float32(points)
|
||||||
targetPts = np.float32([[0, 0], [ic, 0], [0, ir]])
|
targetPts = np.float32([[0, 0], [ic, 0], [0, ir]])
|
||||||
|
|
||||||
M = cv2.getAffineTransform(targetPts, atPts)
|
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
|
output[0:rows, 0:cols] = dst
|
||||||
|
|
||||||
cv2.imwrite(outputFile, output)
|
display(output)
|
||||||
print(f'Wrote {outputFile}')
|
#cv2.imwrite(outputFile, output)
|
||||||
|
##print(f'Wrote {outputFile}')
|
||||||
|
|
Loading…
Reference in New Issue