Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
target_step_size = avg_height0
else:
target_step_size = avg_height1
paths = []
for i in range(len(line['baseline'])-1):
i_1 = i+1
p1 = line['baseline'][i]
p2 = line['baseline'][i_1]
p1_c = complex(*p1)
p2_c = complex(*p2)
paths.append(Line(p1_c, p2_c))
# Add a bit on the end
tan = paths[-1].unit_tangent(1.0)
p3_c = p2_c + target_step_size * tan
paths.append(Line(p2_c, p3_c))
path = Path(*paths)
ts = find_t_spacing(path, target_step_size)
#Changing this causes issues in pretraining - not sure why
target_height = 32
rectified_to_warped_x, rectified_to_warped_y, warped_to_rectified_x, warped_to_rectified_y, max_min = generate_offset_mapping(masked_img, ts, path, 0, -2*target_step_size, cube_size = target_height)
warped_above = cv2.remap(line_mask, rectified_to_warped_x, rectified_to_warped_y, cv2.INTER_CUBIC, borderValue=(0,0,0))
p = hull_points
q = hull_points.copy()
for idx in idx_min_max:
x, y = p[idx]
q[idx] = (x + random.gauss(0, x_range), y + y_range * random.gauss(0, y_range))
path_deformed = Path()
for segment in path:
points = []
for v in segment.bpoints():
real, imag = moving_least_square_with_rigid_transformation(p, q, np.array([v.real, v.imag]),
max(x_range, y_range))
point_xformed = complex(real, imag)
points.append(point_xformed)
if len(segment.bpoints()) == 2:
line = Line(points[0], points[1])
path_deformed.append(line)
else:
cubic_bezier = CubicBezier(points[0], points[1], points[2], points[3])
path_deformed.append(cubic_bezier)
path_list.append(path_deformed)
return path_list
doc = minidom.parse(fp)
paths = doc.getElementsByTagName('path')
rects = doc.getElementsByTagName('rect')
if len(paths) != 7:
raise ValueError('expected 7
cp1, cp2 = controlPoints
path.append(CubicBezier(
currentPos,
vec2(cp1.x, (cp1.y + yOffs) * yMul),
vec2(cp2.x, (cp2.y + yOffs) * yMul),
pos))
else:
if len(controlPoints) != 1:
raise Exception('unexpected number of control points for curve')
cp = controlPoints[0]
path.append(QuadraticBezier(currentPos, vec2(cp.x, (cp.y + yOffs) * yMul), pos))
currentPos = pos
controlPoints = []
elif p.type == 'line':
pos = vec2(p.x, (p.y + yOffs) * yMul)
path.append(Line(currentPos, pos))
currentPos = pos
paths.append(path)
if font.has_key('__svgsync'):
font.removeGlyph('__svgsync')
return paths
i_1 = i+1
p1 = line['baseline'][i]
p2 = line['baseline'][i_1]
p1_c = complex(*p1)
p2_c = complex(*p2)
paths.append(Line(p1_c, p2_c))
# Add a bit on the end
tan = paths[-1].unit_tangent(1.0)
p3_c = p2_c + target_step_size * tan
paths.append(Line(p2_c, p3_c))
path = Path(*paths)
ts = find_t_spacing(path, target_step_size)
#Changing this causes issues in pretraining - not sure why
target_height = 32
rectified_to_warped_x, rectified_to_warped_y, warped_to_rectified_x, warped_to_rectified_y, max_min = generate_offset_mapping(masked_img, ts, path, 0, -2*target_step_size, cube_size = target_height)
warped_above = cv2.remap(line_mask, rectified_to_warped_x, rectified_to_warped_y, cv2.INTER_CUBIC, borderValue=(0,0,0))
rectified_to_warped_x, rectified_to_warped_y, warped_to_rectified_x, warped_to_rectified_y, max_min = generate_offset_mapping(masked_img, ts, path, 2*target_step_size, 0, cube_size = target_height)
warped_below = cv2.remap(line_mask, rectified_to_warped_x, rectified_to_warped_y, cv2.INTER_CUBIC, borderValue=(0,0,0))
above_scale = np.max((warped_above.astype(float) / 255).sum(axis=0))
below_scale = np.max((warped_below.astype(float) / 255).sum(axis=0))