Skip to content

Commit 12a54f9

Browse files
committed
fix: fix the scope of inner function to support python version 3.12
1 parent bb2cba3 commit 12a54f9

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

jigsaw_puzzle_solver/solver/assembler.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,7 @@ def assemble(self):
116116
Returns:
117117
None
118118
"""
119-
120-
# initialization.
121-
self._compute_similarity_matrix()
122-
s_time = time.time()
123-
self.merge_history = []
124-
unused_ids = [*range(0, len(self.raw_imgs))] # remaining pieces
125-
self.blueprint = PuzzleBlock(self.max_rows if self.max_rows > 0 else len(self.raw_imgs),
126-
self.max_cols if self.max_cols > 0 else len(self.raw_imgs))
127-
p_queue = LinkedHashmapPriorityQueue(len(self.raw_imgs))
128-
129-
# add the first puzzle piece to the priority queue
130-
p_queue.enqueue(0, PuzzlePiece(0, 0, 1.0, self.blueprint.top, self.blueprint.left))
131-
132-
# MST assembly algorithm loop
133-
while not p_queue.is_empty():
134-
# do not consider a position that's already activated by the blueprint
135-
if not self.blueprint.validate_position(*p_queue.peek().pos()):
136-
p_queue.dequeue()
137-
continue
138-
# dequeue puzzle piece from the priority queue, and merge it towards the final image form.
139-
piece, duplicates = _dequeue_and_merge()
140-
# add the best fit puzzle pieces at all frontier positions to the priority queue
141-
_enqueue_all_frontiers(self.blueprint.get_inactive_neighbors(*piece.pos()) + duplicates)
142-
print("MST assembly algorithm:", time.time() - s_time, "seconds")
143-
119+
144120
def _best_fit_piece_at(y, x):
145121
"""
146122
Find the puzzle piece that can be most naturally stitched at the given position.
@@ -202,6 +178,30 @@ def _enqueue_all_frontiers(frontier_pieces_list):
202178
if pc.is_valid():
203179
p_queue.enqueue(pc.img_id, pc)
204180

181+
# initialization.
182+
self._compute_similarity_matrix()
183+
s_time = time.time()
184+
self.merge_history = []
185+
unused_ids = [*range(0, len(self.raw_imgs))] # remaining pieces
186+
self.blueprint = PuzzleBlock(self.max_rows if self.max_rows > 0 else len(self.raw_imgs),
187+
self.max_cols if self.max_cols > 0 else len(self.raw_imgs))
188+
p_queue = LinkedHashmapPriorityQueue(len(self.raw_imgs))
189+
190+
# add the first puzzle piece to the priority queue
191+
p_queue.enqueue(0, PuzzlePiece(0, 0, 1.0, self.blueprint.top, self.blueprint.left))
192+
193+
# MST assembly algorithm loop
194+
while not p_queue.is_empty():
195+
# do not consider a position that's already activated by the blueprint
196+
if not self.blueprint.validate_position(*p_queue.peek().pos()):
197+
p_queue.dequeue()
198+
continue
199+
# dequeue puzzle piece from the priority queue, and merge it towards the final image form.
200+
piece, duplicates = _dequeue_and_merge()
201+
# add the best fit puzzle pieces at all frontier positions to the priority queue
202+
_enqueue_all_frontiers(self.blueprint.get_inactive_neighbors(*piece.pos()) + duplicates)
203+
print("MST assembly algorithm:", time.time() - s_time, "seconds")
204+
205205
def save_assembled_image(self, filepath):
206206
"""
207207
save the reconstructed image to a file

0 commit comments

Comments
 (0)