Merge in RR/cv-analysis from add-pdf-coord-conversion to master
Squashed commit of the following:
commit f56b7b45feb78142b032ef0faae2ca8dd020e6c5
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jul 7 11:26:46 2022 +0200
update pyinfra
commit 9086ef0a2059688fb8dd5559cda831bbbd36362b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jul 7 11:21:53 2022 +0200
update inpout metadata keys
commit 55f147a5848e22ea62242ea883a0ce53ef1c04a5
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jul 7 09:16:16 2022 +0200
update to new input metadata signature
commit df4652fb027f734f2613e4adb7bc5b17edee62e9
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jul 6 16:55:36 2022 +0200
refactor
commit e52c674085a9c7411c55a2e0993aa34622284317
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jul 6 16:15:21 2022 +0200
update build script, refactor
commit 1f874aea591f25544aaa3f39a4e38fa50a24615e
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Jul 5 17:01:15 2022 +0200
add rotation formatter
commit b78a69741287a4cd38a90ace98f67e8f1b803737
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Jul 5 09:26:27 2022 +0200
refactor
commit b3155b8e072530f99114f3ee9135e73afc8f85cb
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Jul 1 15:06:45 2022 +0200
made assertion robust to floating point precision
commit 4169102a6b5053500a3db2d789d265c2c77d56a4
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Jul 1 15:06:01 2022 +0200
improve banner
commit dea74593d925c802489e5400297b48a9729038f0
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Jul 1 14:28:08 2022 +0200
introduce derotation logic for rectangles from rotated pdfs, introduce continious option for coordinates in Rectangle class
commit d07e1dc2731ea7ae9887cc02bb98155bf1565a0d
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Jul 1 10:39:38 2022 +0200
introduce table parsing formatter to convert pixel values to inches
commit 67ff6730dd7073a0fc9e9698904325dea9537c5b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Jul 1 08:06:42 2022 +0200
fixed duplicate logging
commit 6c025409415329028f697bb99986cd0912c7ed54
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 30 17:10:32 2022 +0200
add pyinfra mock script
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import gzip
|
|
from operator import itemgetter
|
|
from typing import Callable
|
|
|
|
from funcy import lmap
|
|
from pyinfra.server.utils import make_streamable_and_wrap_in_packing_logic
|
|
|
|
from cv_analysis.server.format import make_formatter
|
|
from cv_analysis.utils.preprocessing import open_img_from_bytes
|
|
|
|
|
|
def make_streamable_analysis_fn(analysis_fn: Callable):
|
|
"""Makes an analysis function streamable for pyinfra server logic. The wrapped function then
|
|
works with data and metadata and returns a tuple or generator of tuples with data and metadata.
|
|
For more information about the server logic, see the PyInfra documentation.
|
|
|
|
Args:
|
|
analysis_fn: cv-analysis function
|
|
|
|
Returns:
|
|
wrapped function
|
|
"""
|
|
|
|
def analyse(data: bytes, metadata: dict):
|
|
|
|
image = open_img_from_bytes(gzip.decompress(data))
|
|
|
|
dpi = metadata["image_info"]["dpi"]
|
|
width, height, rotation = itemgetter("width", "height", "rotation")(metadata["page_info"])
|
|
|
|
formatter = make_formatter(dpi, (width, height), rotation)
|
|
|
|
results = map(lambda x: x.json_xywh(), analysis_fn(image))
|
|
results = {"cells": (lmap(formatter, results))}
|
|
|
|
return b"", {**metadata, **results}
|
|
|
|
return make_streamable_and_wrap_in_packing_logic(analyse, batched=False)
|