I need to create AI which transform pixilated image to vector. The input data are photos of manually drawn flowcharts. Their vector representations have been created. I plan to use TensorFlow. As I understand it, vector images need to be converted to a numpy array, but I can’t find a way to convert. How can this problem be solved?
for element in path_elements:
d = element.get("d")
path_data = d.split()
prev_x = None
prev_y = None
print(type(path_data[0]))
for i, segment in enumerate(path_data):
if segment.startswith("M") or segment.startswith("L"):
coords = path_data[i+1].split(",")
print(coords)
if len(coords) == 2:
x, y = map(float, coords)
nodes.append((x, y))
if prev_x is not None and prev_y is not None:
edges.append(((prev_x, prev_y), (x, y)))
prev_x = x
prev_y = y
if not nodes:
print(f"В элементе path '{element.get('id')}' нет корректных координат.")
if not nodes:
print("Массив nodes пуст, невозможно выполнить нормализацию.")
else:
nodes_norm = (np.array(nodes) - np.array(nodes).min(axis=0)) / (np.array(nodes).max(axis=0) - np.array(nodes).min(axis=0)
vector_representation = np.concatenate([nodes_norm.flatten(), np.array(edges).flatten()])
This code extracts only the coordinates of points and lines. However, what about other commands if I need a two-dimensional array?
Ольга Савинова is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.