[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,
|
remove_included,
|
||||||
has_no_parent,
|
has_no_parent,
|
||||||
)
|
)
|
||||||
|
|
||||||
from cv_analysis.utils.rectangle import Rectangle
|
from cv_analysis.utils.rectangle import Rectangle
|
||||||
|
|
||||||
|
|
||||||
def parse_layout(image: np.array):
|
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 = find_segments(image)
|
||||||
rectangles = meta_detection(original, rectangles)
|
|
||||||
|
|
||||||
rectangles = remove_included(rectangles)
|
rectangles = remove_included(rectangles)
|
||||||
rectangles = lmap(rectangle_to_box, rectangles)
|
rectangles = lmap(rectangle_to_box, rectangles)
|
||||||
@ -35,7 +29,13 @@ def parse_layout(image: np.array):
|
|||||||
return rectangles
|
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)
|
contours, hierarchies = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
mask1 = map(is_likely_segment, contours)
|
mask1 = map(is_likely_segment, contours)
|
||||||
mask2 = map(has_no_parent, hierarchies[0])
|
mask2 = map(has_no_parent, hierarchies[0])
|
||||||
@ -43,6 +43,10 @@ def find_segments(image):
|
|||||||
contours = compress(contours, mask)
|
contours = compress(contours, mask)
|
||||||
rectangles = lmap(compose(box_to_rectangle, cv2.boundingRect), contours)
|
rectangles = lmap(compose(box_to_rectangle, cv2.boundingRect), contours)
|
||||||
|
|
||||||
|
if meta:
|
||||||
|
image = meta_detection(original, rectangles)
|
||||||
|
rectangles = find_segments(image, 0)
|
||||||
|
|
||||||
return rectangles
|
return rectangles
|
||||||
|
|
||||||
|
|
||||||
@ -67,9 +71,7 @@ def meta_detection(image: np.ndarray, rectangles: Iterable[Rectangle]):
|
|||||||
image = invert_image(image)
|
image = invert_image(image)
|
||||||
image = normalize_to_gray_scale(image)
|
image = normalize_to_gray_scale(image)
|
||||||
|
|
||||||
rectangles = find_segments(image)
|
return image
|
||||||
|
|
||||||
return rectangles
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_to_gray_scale(image):
|
def normalize_to_gray_scale(image):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user