75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
|
|
import base.inference
|
|
import importlib
|
|
|
|
import numpy as np
|
|
|
|
def postprocess_hw(pre_results, func, _type=0, **kwargs):
|
|
if "USER_CONFIG" in kwargs:
|
|
if kwargs["USER_CONFIG"]["post"]["post_mode"] != 'algorithm':
|
|
assert "USER_CONFIG" in kwargs
|
|
config = kwargs.get("USER_CONFIG")
|
|
team=config["post"]["post_mode"]
|
|
kwargs.update(config['post'][team])
|
|
if _type == base.inference.EMULATOR:
|
|
app_name = ".".join(str(config['flow']['app_folder']).split('/')[-2:])
|
|
function = f'{app_name}.sys.runners.src.'+config["post"]["post_type"]
|
|
module, function_name = function.rsplit(".", 1)
|
|
postprocess = importlib.import_module(module)
|
|
func = getattr(postprocess, function_name)
|
|
outputs = func(pre_results, **kwargs)
|
|
return outputs
|
|
def postprocess_sw(pre_results, func, **kwargs):
|
|
outputs = func(pre_results, **kwargs)
|
|
return outputs
|
|
|
|
def coord_scaling_lm(pt, **kwargs):
|
|
'''
|
|
map point from input to original image
|
|
:param pt: [x, y]
|
|
:param kwargs: include scale, padding, and rectangle
|
|
:return: point [x, y]
|
|
'''
|
|
assert np.size(pt) == 2
|
|
scale = kwargs.get('scale', None)
|
|
padding = kwargs.get('padding', None)
|
|
rectangle = kwargs.get('rectangle', None)
|
|
if scale is None or padding is None or rectangle is None:
|
|
print('preinfo missing')
|
|
assert 0
|
|
|
|
x = (pt[0] - padding[0]) * scale[0] + rectangle[0]
|
|
y = (pt[1] - padding[2]) * scale[1] + rectangle[1]
|
|
return [x, y]
|
|
def coord_scaling_box(box, type=0,**kwargs):
|
|
'''
|
|
:param box: type=0: [xmin, ymin, w, h] type=1: [xmin, ymin, xmax, ymax]
|
|
:param type: decide box type
|
|
:param kwargs: include scale, padding, and rectangle
|
|
:return:
|
|
'''
|
|
scale = kwargs.get('scale', None)
|
|
padding = kwargs.get('padding', None)
|
|
rectangle = kwargs.get('rectangle', None)
|
|
if scale is None or padding is None or rectangle is None:
|
|
print('preinfo missing')
|
|
assert 0
|
|
|
|
if type == 0:
|
|
xmin, ymin, w, h = box
|
|
xmax, ymax = xmin+w, ymin+h
|
|
else:
|
|
xmin, ymin, xmax, ymax = box
|
|
|
|
xmin = (xmin - padding[0]) * scale[0] + rectangle[0]
|
|
xmax = (xmax - padding[0]) * scale[0] + rectangle[0]
|
|
|
|
ymin = (ymin - padding[2]) * scale[1] + rectangle[1]
|
|
ymax = (ymax - padding[2]) * scale[1] + rectangle[1]
|
|
|
|
if type == 0:
|
|
return [xmin, ymin, xmax-xmin, ymax-ymin]
|
|
else:
|
|
return [xmin, ymin, xmax, ymax]
|
|
|