From 268329a57fce901c224814a46cedeecdf3ba6ec1 Mon Sep 17 00:00:00 2001 From: Isaac Riley Date: Mon, 20 Jun 2022 13:48:16 +0200 Subject: [PATCH] add pyinfra_compat.py --- .../{pyinfra_compat => pyinfra_compat.py} | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) rename cv_analysis/{pyinfra_compat => pyinfra_compat.py} (54%) 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