Image overwriting continues even after loading a valid image and drawing the hole punches on
This commit is contained in:
parent
aabdac74b5
commit
a1a57ef58c
|
@ -5,13 +5,15 @@ from json import load
|
||||||
from os.path import exists, basename
|
from os.path import exists, basename
|
||||||
from common import image_resize, display, read_json
|
from common import image_resize, display, read_json
|
||||||
|
|
||||||
|
holeConstant = .0156862745 # 160/10200
|
||||||
|
|
||||||
# use top left, top right, bottom left
|
# use top left, top right, bottom left
|
||||||
def apply_image_to_points (original, target, points) :
|
def apply_image_to_points (original, target, points) :
|
||||||
rows, cols, ch = original.shape
|
rows, cols, ch = original.shape
|
||||||
ir, ic, ich = target.shape
|
ir, ic, ich = target.shape
|
||||||
|
|
||||||
print(f'{cols}x{rows}')
|
print('Using points: ')
|
||||||
print(f'{ic}x{ir}')
|
print(points)
|
||||||
|
|
||||||
atPts = np.float32(points)
|
atPts = np.float32(points)
|
||||||
targetPts = np.float32([[0, 0], [ic, 0], [0, ir]])
|
targetPts = np.float32([[0, 0], [ic, 0], [0, ir]])
|
||||||
|
@ -19,9 +21,10 @@ def apply_image_to_points (original, target, points) :
|
||||||
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)
|
||||||
|
|
||||||
original[0:rows, 0:cols] = dst
|
output = original.copy()
|
||||||
|
output[0:rows, 0:cols] = dst
|
||||||
|
|
||||||
return original
|
return output
|
||||||
|
|
||||||
def create_blank(width, height):
|
def create_blank(width, height):
|
||||||
rgb_color=(255,255,255)
|
rgb_color=(255,255,255)
|
||||||
|
@ -75,11 +78,22 @@ tmpl = read_json(templateFile)
|
||||||
|
|
||||||
print(f"Image size {tmpl['width']}x{tmpl['height']}")
|
print(f"Image size {tmpl['width']}x{tmpl['height']}")
|
||||||
|
|
||||||
blank = create_blank(tmpl['width'], tmpl['height'])
|
hole = round(tmpl['width'] * holeConstant)
|
||||||
output = blank.copy()
|
|
||||||
|
#blank = create_blank(tmpl['width'], tmpl['height'])
|
||||||
|
output = cv2.imread(templateFile.replace('.calibration.json', ''))#blank.copy()
|
||||||
|
|
||||||
|
hp = tmpl['holePunches']
|
||||||
|
for i in hp:
|
||||||
|
print(hp[i])
|
||||||
|
cv2.circle(output, (hp[i]['x'], hp[i]['y'],), hole, (0, 0, 0,), -1)
|
||||||
|
|
||||||
|
#cv2.imwrite(outputFile, output)
|
||||||
|
|
||||||
for i in range(0, len(images)) :
|
for i in range(0, len(images)) :
|
||||||
frame = cv2.imread(images[i])
|
frame = cv2.imread(images[i])
|
||||||
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])}')
|
||||||
|
|
||||||
cv2.imwrite(outputFile, output)
|
cv2.imwrite(outputFile, output)
|
||||||
print(f'Wrote {outputFile}')
|
print(f'Wrote {outputFile}')
|
||||||
|
|
Loading…
Reference in New Issue