diff --git a/cv_analysis/pyinfra_compat b/cv_analysis/pyinfra_compat.py similarity index 54% rename from cv_analysis/pyinfra_compat rename to cv_analysis/pyinfra_compat.py index 4c346f2..96013e0 100644 --- a/cv_analysis/pyinfra_compat +++ b/cv_analysis/pyinfra_compat.py @@ -13,20 +13,21 @@ task_dict = { } -def analyze_byteslist(img_bytes_list, task="table"): - +def analyze_bytes(img_bytes, page_num, task="table"): analysis_function = task_dict[task] + page = open_img_from_bytes(img_bytes) + cells = list(map(lambda x: x.json_xywh(), analysis_function(page))) + page_dict = { + "page": page_num, + "pageWidth": page.shape[1], + "pageHeight": page.shape[0], + "cells": cells + } + return page_dict + +def analyze_bytes_list(img_bytes_list, task="table"): result = [] for i, img_bytes in enumerate(img_bytes_list): - page = open_img_from_bytes(img_bytes) - cells = list(map(lambda x: x.json_xywh(), analysis_function(page))) - page_dict = { - "page": i, - "pageWidth": page.shape[1], - "pageHeight": page.shape[0], - "cells": cells - } - result.append(page_dict) - + result.append(analyze_bytes(img_bytes, i, task=task)) return result \ No newline at end of file