From 782ef5e45664678310d65bf7e9553fc09c72ba35 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 25 Jan 2026 10:02:36 +0800 Subject: [PATCH] added parameter row_tol for box sorting --- .gitignore | 3 +-- config/prototype_of1.json | 3 ++- config/prototype_of2.json | 3 ++- config/prototype_of3.json | 3 ++- src/orisys/Stitcher.py | 7 ++++--- src/orisys/configs/prototype.json | 3 ++- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index ed2bc36..d334382 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,4 @@ orisys.egg-info/ /old_orisys/ /dist_nuitka/ /build_nuitka -/data/ -/config/ \ No newline at end of file +/data/ \ No newline at end of file diff --git a/config/prototype_of1.json b/config/prototype_of1.json index 0c895a0..58a2067 100644 --- a/config/prototype_of1.json +++ b/config/prototype_of1.json @@ -15,7 +15,8 @@ "index": [1,2,3,6,7,8,11,12,13], "margin": 10, "nominal_ov_pos": 100, - "n": [3,3] + "n": [3,3], + "row_tol": 0.4 }, "tracker": { "adaptive": true, diff --git a/config/prototype_of2.json b/config/prototype_of2.json index 9b6b3d5..873e689 100644 --- a/config/prototype_of2.json +++ b/config/prototype_of2.json @@ -15,7 +15,8 @@ "index": [1,2,3,6,7,8,11,12,13], "margin": 10, "nominal_ov_pos": 100, - "n": [3,3] + "n": [3,3], + "row_tol": 0.4 }, "tracker": { "adaptive": true, diff --git a/config/prototype_of3.json b/config/prototype_of3.json index 12d5082..f371ba2 100644 --- a/config/prototype_of3.json +++ b/config/prototype_of3.json @@ -15,7 +15,8 @@ "index": [1,2,3,6,7,8,11,12,13], "margin": 10, "nominal_ov_pos": 100, - "n": [3,3] + "n": [3,3], + "row_tol": 0.4 }, "tracker": { "adaptive": true, diff --git a/src/orisys/Stitcher.py b/src/orisys/Stitcher.py index 5e50b36..e1a9403 100644 --- a/src/orisys/Stitcher.py +++ b/src/orisys/Stitcher.py @@ -27,6 +27,7 @@ class Stitcher: self.nominal_ov_pos=config_stitcher["nominal_ov_pos"] self.margin=config_stitcher["margin"] self.bound=self.nominal_ov_pos - self.margin + self.row_tol = config_stitcher["row_tol"] if self.verbose: print(f"Stitcher initialized with config: {self.config_stitcher}") @@ -110,7 +111,7 @@ class Stitcher: def find_stitch_boxes(self,img_src,show = False): img_corr = self.__correct_edge_bloom(img_src) - self.__detect_nonblack_regions(img_corr,show = show) + self.__detect_nonblack_regions(img_corr,show = show, row_tol = self.row_tol) return len(self.boxes), self.boxes # return self.boxes @@ -431,7 +432,7 @@ class Stitcher: return pos_list # Computation Functions - def __detect_nonblack_regions(self, img, morph_k=3, n_boxes_target=15, bk_thresh_step=10, bk_thresh_max=100,show = False): + def __detect_nonblack_regions(self, img, morph_k=3, n_boxes_target=15, bk_thresh_step=10, bk_thresh_max=100,show = False, row_tol = 0.4): """ Return binary mask of non-black regions and list of bounding boxes (x,y,w,h). Uses adaptive thresholding on grayscale + small morphology to be robust to illumination. @@ -509,7 +510,7 @@ class Stitcher: heights = [b[3] - b[1] for b in cropped_boxes] median_height = np.median(heights) if heights else target_h # Use a fraction of the box height as tolerance (e.g., 20% of box height) - row_tolerance = max(1, int(median_height * 0.4)) + row_tolerance = max(1, int(median_height * row_tol)) # Quantize y-coordinates to group boxes into rows def get_row_key(box): diff --git a/src/orisys/configs/prototype.json b/src/orisys/configs/prototype.json index f7b841b..06b1820 100644 --- a/src/orisys/configs/prototype.json +++ b/src/orisys/configs/prototype.json @@ -15,7 +15,8 @@ "index": [1,2,3,6,7,8,11,12,13], "margin": 10, "nominal_ov_pos": 100, - "n": [3,3] + "n": [3,3], + "row_tol": 0.4 }, "tracker": { "adaptive": true,