[WIP] Refactoring meta-detection
This commit is contained in:
parent
8824c5c3ea
commit
b540cfd0f2
@ -13,18 +13,12 @@ from cv_analysis.utils.postprocessing import (
|
||||
remove_included,
|
||||
has_no_parent,
|
||||
)
|
||||
|
||||
from cv_analysis.utils.rectangle import Rectangle
|
||||
|
||||
|
||||
def parse_layout(image: np.array):
|
||||
original = image.copy()
|
||||
|
||||
image = normalize_to_gray_scale(image)
|
||||
image = dilate_page_components(image)
|
||||
|
||||
rectangles = find_segments(image)
|
||||
rectangles = meta_detection(original, rectangles)
|
||||
|
||||
rectangles = remove_included(rectangles)
|
||||
rectangles = lmap(rectangle_to_box, rectangles)
|
||||
@ -35,7 +29,13 @@ def parse_layout(image: np.array):
|
||||
return rectangles
|
||||
|
||||
|
||||
def find_segments(image):
|
||||
def find_segments(image, meta=1):
|
||||
|
||||
if meta:
|
||||
original = image.copy()
|
||||
image = normalize_to_gray_scale(image)
|
||||
image = dilate_page_components(image)
|
||||
|
||||
contours, hierarchies = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
mask1 = map(is_likely_segment, contours)
|
||||
mask2 = map(has_no_parent, hierarchies[0])
|
||||
@ -43,6 +43,10 @@ def find_segments(image):
|
||||
contours = compress(contours, mask)
|
||||
rectangles = lmap(compose(box_to_rectangle, cv2.boundingRect), contours)
|
||||
|
||||
if meta:
|
||||
image = meta_detection(original, rectangles)
|
||||
rectangles = find_segments(image, 0)
|
||||
|
||||
return rectangles
|
||||
|
||||
|
||||
@ -67,9 +71,7 @@ def meta_detection(image: np.ndarray, rectangles: Iterable[Rectangle]):
|
||||
image = invert_image(image)
|
||||
image = normalize_to_gray_scale(image)
|
||||
|
||||
rectangles = find_segments(image)
|
||||
|
||||
return rectangles
|
||||
return image
|
||||
|
||||
|
||||
def normalize_to_gray_scale(image):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user