Skip to content

Commit bc5af1b

Browse files
author
Olexandr Dubchak
committed
fix building rectangle graph
1 parent 5213ec9 commit bc5af1b

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

core/logic/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def add_to_graph(self, node: Node):
105105
def remove_from_graph(self, node: Node):
106106
pass
107107

108-
def get_node_by_id(self, id:int):
108+
def get_node_by_id(self, id:int)->Node:
109109
index = self._nodes_ids.get(id)
110110
if index is None:
111111
return None

core/logic/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import cv2
44
import numpy as np
55

6-
from core.logic.rectangle_graph import Point, YoloRectangle, DocumentGraph
6+
from core.logic.rectangle_graph import Point, YoloRectangle, DocumentGraph, RectangleDocumentGraph
77

88
bboxes_example = np.load('res_bboxes_example.npy')
99
# center_x, center_y, width, height, class_id, probability
@@ -18,8 +18,8 @@
1818
rec1, rec2 = recs[0], recs[5]
1919

2020

21-
#graph = DocumentGraph(recs)
22-
#graph.build_rectangle_graph()
21+
graph = RectangleDocumentGraph(recs)
22+
graph.build_rectangle_graph()
2323

2424
json_example = json.load(open('v3.json', encoding='utf-8'))
2525

core/logic/rectangle_graph.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55

6-
from core.logic.graph import Node
6+
from core.logic.graph import Node, DocumentGraph
77

88

99
class Point:
@@ -146,18 +146,20 @@ def __init__(self, rectangles: List[Rectangle]):
146146
self.rectangles = rectangles
147147
self.n = len(rectangles)
148148
self.distances = np.zeros(shape=(self.n, self.n))
149-
self.head = Node(data=None)
150-
self.nodes = [Node(data=rec) for rec in rectangles]
151149
self.calculate_distances()
150+
self.graph = DocumentGraph()
151+
for i in range(self.n):
152+
node = Node(node_id=i, value=f'{self.rectangles[i].top_left_point} ___ {self.rectangles[i].bottom_right_point}')
153+
self.graph.add_to_graph(node)
152154

153155
def build_rectangle_graph(self):
154156
indeces_of_sorted = np.argsort(self.distances, axis=1)
155157
for rect_index in range(self.n):
156158
for dist_index in indeces_of_sorted[rect_index, 1:]:
157159
position = self.rectangles[rect_index].get_relative_position(self.rectangles[dist_index])
158-
node = self.nodes[rect_index]
159-
if not node.get_corresponding_attr(position):
160-
node.set_to_corresponding_attr(position, self.nodes[dist_index])
160+
node = self.graph.get_node_by_id(rect_index)
161+
other_node = self.graph.get_node_by_id(dist_index)
162+
node.set_relation(other_node, position)
161163

162164
def calculate_distances(self):
163165
for i in range(self.n):

0 commit comments

Comments
 (0)