mirror of
https://github.com/qurator-spk/eynollah.git
synced 2026-05-26 07:39:22 +02:00
contour: drop unused functions depending on rotation_image_new()
This commit is contained in:
parent
87cce6c963
commit
be4fe8c263
2 changed files with 1 additions and 93 deletions
|
|
@ -11,7 +11,7 @@ from shapely.geometry.polygon import orient
|
|||
from shapely import set_precision, affinity
|
||||
from shapely.ops import unary_union, nearest_points
|
||||
|
||||
from .rotate import rotate_image, rotation_image_new
|
||||
from .rotate import rotate_image
|
||||
|
||||
def contours_in_same_horizon(cy_main_hor):
|
||||
"""
|
||||
|
|
@ -120,94 +120,6 @@ def return_contours_of_interested_region(region_pre_p, label, min_area=0.0002, d
|
|||
dilate=dilate)
|
||||
return contours_imgs
|
||||
|
||||
def do_work_of_contours_in_image(contour, index_r_con, img, slope_first):
|
||||
img_copy = np.zeros(img.shape[:2], dtype=np.uint8)
|
||||
img_copy = cv2.fillPoly(img_copy, pts=[contour], color=1)
|
||||
|
||||
img_copy = rotation_image_new(img_copy, -slope_first)
|
||||
_, thresh = cv2.threshold(img_copy, 0, 255, 0)
|
||||
|
||||
cont_int, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||
|
||||
cont_int[0][:, 0, 0] = cont_int[0][:, 0, 0] + np.abs(img_copy.shape[1] - img.shape[1])
|
||||
cont_int[0][:, 0, 1] = cont_int[0][:, 0, 1] + np.abs(img_copy.shape[0] - img.shape[0])
|
||||
|
||||
return cont_int[0], index_r_con
|
||||
|
||||
def get_textregion_contours_in_org_image_multi(cnts, img, slope_first, map=map):
|
||||
if not len(cnts):
|
||||
return [], []
|
||||
results = map(partial(do_work_of_contours_in_image,
|
||||
img=img,
|
||||
slope_first=slope_first,
|
||||
),
|
||||
cnts, range(len(cnts)))
|
||||
return tuple(zip(*results))
|
||||
|
||||
def get_textregion_contours_in_org_image(cnts, img, slope_first):
|
||||
cnts_org = []
|
||||
# print(cnts,'cnts')
|
||||
for i in range(len(cnts)):
|
||||
img_copy = np.zeros(img.shape[:2], dtype=np.uint8)
|
||||
img_copy = cv2.fillPoly(img_copy, pts=[cnts[i]], color=1)
|
||||
|
||||
# plt.imshow(img_copy)
|
||||
# plt.show()
|
||||
|
||||
# print(img.shape,'img')
|
||||
img_copy = rotation_image_new(img_copy, -slope_first)
|
||||
##print(img_copy.shape,'img_copy')
|
||||
# plt.imshow(img_copy)
|
||||
# plt.show()
|
||||
|
||||
_, thresh = cv2.threshold(img_copy, 0, 255, 0)
|
||||
|
||||
cont_int, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||
cont_int[0][:, 0, 0] = cont_int[0][:, 0, 0] + np.abs(img_copy.shape[1] - img.shape[1])
|
||||
cont_int[0][:, 0, 1] = cont_int[0][:, 0, 1] + np.abs(img_copy.shape[0] - img.shape[0])
|
||||
# print(np.shape(cont_int[0]))
|
||||
cnts_org.append(cont_int[0])
|
||||
|
||||
return cnts_org
|
||||
|
||||
def get_textregion_confidences_old(cnts, img, slope_first):
|
||||
zoom = 3
|
||||
img = cv2.resize(img, (img.shape[1] // zoom,
|
||||
img.shape[0] // zoom),
|
||||
interpolation=cv2.INTER_NEAREST)
|
||||
cnts_org = []
|
||||
for cnt in cnts:
|
||||
img_copy = np.zeros(img.shape[:2], dtype=np.uint8)
|
||||
img_copy = cv2.fillPoly(img_copy, pts=[cnt // zoom], color=1)
|
||||
|
||||
img_copy = rotation_image_new(img_copy, -slope_first).astype(np.uint8)
|
||||
_, thresh = cv2.threshold(img_copy, 0, 255, 0)
|
||||
|
||||
cont_int, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||
cont_int[0][:, 0, 0] = cont_int[0][:, 0, 0] + np.abs(img_copy.shape[1] - img.shape[1])
|
||||
cont_int[0][:, 0, 1] = cont_int[0][:, 0, 1] + np.abs(img_copy.shape[0] - img.shape[0])
|
||||
cnts_org.append(cont_int[0] * zoom)
|
||||
|
||||
return cnts_org
|
||||
|
||||
def do_back_rotation_and_get_cnt_back(contour_par, index_r_con, img, slope_first, confidence_matrix):
|
||||
img_copy = np.zeros(img.shape[:2], dtype=np.uint8)
|
||||
img_copy = cv2.fillPoly(img_copy, pts=[contour_par], color=1)
|
||||
confidence_matrix_mapped_with_contour = confidence_matrix * img_copy
|
||||
confidence_contour = np.sum(confidence_matrix_mapped_with_contour) / float(np.sum(img_copy))
|
||||
|
||||
img_copy = rotation_image_new(img_copy, -slope_first).astype(np.uint8)
|
||||
_, thresh = cv2.threshold(img_copy, 0, 255, 0)
|
||||
|
||||
cont_int, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||
if len(cont_int)==0:
|
||||
cont_int = [contour_par]
|
||||
confidence_contour = 0
|
||||
else:
|
||||
cont_int[0][:, 0, 0] = cont_int[0][:, 0, 0] + np.abs(img_copy.shape[1] - img.shape[1])
|
||||
cont_int[0][:, 0, 1] = cont_int[0][:, 0, 1] + np.abs(img_copy.shape[0] - img.shape[0])
|
||||
return cont_int[0], index_r_con, confidence_contour
|
||||
|
||||
def get_region_confidences(cnts, confidence_matrix):
|
||||
if not len(cnts):
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -2,10 +2,6 @@ import math
|
|||
import cv2
|
||||
|
||||
|
||||
def rotation_image_new(img, thetha):
|
||||
rotated = rotate_image(img, thetha)
|
||||
return rotate_max_area_new(img, rotated, thetha)
|
||||
|
||||
def rotate_image(img_patch, slope):
|
||||
(h, w) = img_patch.shape[:2]
|
||||
center = (w // 2, h // 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue