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.
This commit is contained in:
parent
a1a57ef58c
commit
34e5153948
|
@ -19,20 +19,18 @@ def apply_image_to_points (original, target, 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)) #, borderMode=cv2.BORDER_TRANSPARENT
|
||||||
|
|
||||||
output = original.copy()
|
original[0:rows, 0:cols] = dst
|
||||||
output[0:rows, 0:cols] = dst
|
|
||||||
|
|
||||||
return output
|
return original
|
||||||
|
|
||||||
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
|
||||||
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
return cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
|
||||||
return cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
|
|
||||||
|
|
||||||
# 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,9 +77,8 @@ tmpl = read_json(templateFile)
|
||||||
print(f"Image size {tmpl['width']}x{tmpl['height']}")
|
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 = cv2.imread(templateFile.replace('.calibration.json', ''))#blank.copy()
|
|
||||||
|
|
||||||
hp = tmpl['holePunches']
|
hp = tmpl['holePunches']
|
||||||
for i in hp:
|
for i in hp:
|
||||||
|
@ -92,6 +89,8 @@ for i in hp:
|
||||||
|
|
||||||
for i in range(0, len(images)) :
|
for i in range(0, len(images)) :
|
||||||
frame = cv2.imread(images[i])
|
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}']))
|
output = apply_image_to_points(output, frame, to_points(tmpl[f'{i}']))
|
||||||
print(f'Applied {basename(images[i])}')
|
print(f'Applied {basename(images[i])}')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue