matching deskewed text region contours with predicted: improve

- when matching undeskewed and new contours, do not just
  pick the closest centers, respectively, but also of similar
  size (by making the contour area the 3rd dimension of the
  vector norm in the distance calculation)
This commit is contained in:
Robert Sachunsky 2025-10-05 02:45:01 +02:00
parent 73e5a1def8
commit 0f33c21eb3

View file

@ -4610,7 +4610,11 @@ class Eynollah:
for i in range(len(contours_only_text_parent)): for i in range(len(contours_only_text_parent)):
p = np.dot(M_22, centers[:, i:i+1]) # [2, 1] p = np.dot(M_22, centers[:, i:i+1]) # [2, 1]
p -= offset p -= offset
dists = np.linalg.norm(p - centers_d, axis=0) # add dimension for area
#dists = np.linalg.norm(p - centers_d, axis=0)
diffs = (np.append(p, [[areas_cnt_text_parent[i]]], axis=0) -
np.append(centers_d, areas_cnt_text_d[np.newaxis], axis=0))
dists = np.linalg.norm(diffs, axis=0)
contours_only_text_parent_d_ordered.append( contours_only_text_parent_d_ordered.append(
contours_only_text_parent_d[np.argmin(dists)]) contours_only_text_parent_d[np.argmin(dists)])
# cv2.fillPoly(img2, pts=[contours_only_text_parent_d[np.argmin(dists)]], color=i + 1) # cv2.fillPoly(img2, pts=[contours_only_text_parent_d[np.argmin(dists)]], color=i + 1)