mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-06-10 04:39:54 +02:00
simplify calculate_page_coords
This commit is contained in:
parent
ddeb6938e5
commit
6398579a72
1 changed files with 9 additions and 18 deletions
|
@ -576,19 +576,14 @@ class eynollah:
|
||||||
self.logger.debug("enter extract_page")
|
self.logger.debug("enter extract_page")
|
||||||
model_page, session_page = self.start_new_session_and_model(self.model_page_dir)
|
model_page, session_page = self.start_new_session_and_model(self.model_page_dir)
|
||||||
img = cv2.GaussianBlur(self.image, (5, 5), 0)
|
img = cv2.GaussianBlur(self.image, (5, 5), 0)
|
||||||
|
|
||||||
img_page_prediction = self.do_prediction(False, img, model_page)
|
img_page_prediction = self.do_prediction(False, img, model_page)
|
||||||
|
|
||||||
imgray = cv2.cvtColor(img_page_prediction, cv2.COLOR_BGR2GRAY)
|
imgray = cv2.cvtColor(img_page_prediction, cv2.COLOR_BGR2GRAY)
|
||||||
_, thresh = cv2.threshold(imgray, 0, 255, 0)
|
_, thresh = cv2.threshold(imgray, 0, 255, 0)
|
||||||
|
|
||||||
thresh = cv2.dilate(thresh, KERNEL, iterations=3)
|
thresh = cv2.dilate(thresh, KERNEL, iterations=3)
|
||||||
contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
|
||||||
cnt_size = np.array([cv2.contourArea(contours[j]) for j in range(len(contours))])
|
cnt_size = np.array([cv2.contourArea(contours[j]) for j in range(len(contours))])
|
||||||
cnt = contours[np.argmax(cnt_size)]
|
cnt = contours[np.argmax(cnt_size)]
|
||||||
x, y, w, h = cv2.boundingRect(cnt)
|
x, y, w, h = cv2.boundingRect(cnt)
|
||||||
|
|
||||||
if x <= 30:
|
if x <= 30:
|
||||||
w += x
|
w += x
|
||||||
x = 0
|
x = 0
|
||||||
|
@ -602,9 +597,7 @@ class eynollah:
|
||||||
|
|
||||||
box = [x, y, w, h]
|
box = [x, y, w, h]
|
||||||
croped_page, page_coord = crop_image_inside_box(box, self.image)
|
croped_page, page_coord = crop_image_inside_box(box, self.image)
|
||||||
|
|
||||||
self.cont_page.append(np.array([[page_coord[2], page_coord[0]], [page_coord[3], page_coord[0]], [page_coord[3], page_coord[1]], [page_coord[2], page_coord[1]]]))
|
self.cont_page.append(np.array([[page_coord[2], page_coord[0]], [page_coord[3], page_coord[0]], [page_coord[3], page_coord[1]], [page_coord[2], page_coord[1]]]))
|
||||||
|
|
||||||
session_page.close()
|
session_page.close()
|
||||||
|
|
||||||
K.clear_session()
|
K.clear_session()
|
||||||
|
@ -1071,19 +1064,17 @@ class eynollah:
|
||||||
def calculate_page_coords(self):
|
def calculate_page_coords(self):
|
||||||
self.logger.debug('enter calculate_page_coords')
|
self.logger.debug('enter calculate_page_coords')
|
||||||
points_page_print = ""
|
points_page_print = ""
|
||||||
for lmm in range(len(self.cont_page[0])):
|
for lmm, contour in enumerate(self.cont_page[0]):
|
||||||
if len(self.cont_page[0][lmm]) == 2:
|
if len(contour) == 2:
|
||||||
points_page_print += str(int((self.cont_page[0][lmm][0] ) / self.scale_x))
|
points_page_print += str(int((contour[0]) / self.scale_x))
|
||||||
points_page_print += ','
|
points_page_print += ','
|
||||||
points_page_print += str(int((self.cont_page[0][lmm][1] ) / self.scale_y))
|
points_page_print += str(int((contour[1]) / self.scale_y))
|
||||||
else:
|
else:
|
||||||
points_page_print += str(int((self.cont_page[0][lmm][0][0]) / self.scale_x))
|
points_page_print += str(int((contour[0][0]) / self.scale_x))
|
||||||
points_page_print += ','
|
points_page_print += ','
|
||||||
points_page_print += str(int((self.cont_page[0][lmm][0][1] ) / self.scale_y))
|
points_page_print += str(int((contour[0][1] ) / self.scale_y))
|
||||||
|
|
||||||
if lmm < len( self.cont_page[0] ) - 1:
|
|
||||||
points_page_print = points_page_print + ' '
|
points_page_print = points_page_print + ' '
|
||||||
return points_page_print
|
return points_page_print[:-1]
|
||||||
|
|
||||||
def xml_reading_order(self, page, order_of_texts, id_of_texts, id_of_marginalia, found_polygons_marginals):
|
def xml_reading_order(self, page, order_of_texts, id_of_texts, id_of_marginalia, found_polygons_marginals):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue