mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-07-05 17:09:57 +02:00
24 lines
913 B
Python
24 lines
913 B
Python
import numpy as np
|
|
from shapely import geometry
|
|
|
|
def filter_contours_area_of_image_tables(self, image, contours, hirarchy, max_area, min_area):
|
|
found_polygons_early = list()
|
|
|
|
jv = 0
|
|
for c in contours:
|
|
if len(c) < 3: # A polygon cannot have less than 3 points
|
|
continue
|
|
|
|
polygon = geometry.Polygon([point[0] for point in c])
|
|
# area = cv2.contourArea(c)
|
|
area = polygon.area
|
|
##print(np.prod(thresh.shape[:2]))
|
|
# Check that polygon has area greater than minimal area
|
|
# print(hirarchy[0][jv][3],hirarchy )
|
|
if area >= min_area * np.prod(image.shape[:2]) and area <= max_area * np.prod(image.shape[:2]): # and hirarchy[0][jv][3]==-1 :
|
|
# print(c[0][0][1])
|
|
found_polygons_early.append(np.array([[point] for point in polygon.exterior.coords], dtype=np.int32))
|
|
jv += 1
|
|
return found_polygons_early
|
|
|
|
|