""" ESP-DL MicroPython library for the ESP-DL(Inherit C module) ======================================================= @dahanzimin From the Mixly Team """ from espdl import * def analyze(results, keys=None, num=0): if keys is None: return True if results else False if results: if keys == "len": return len(results) else: return results[num][keys] #简单处理模型运行结果 _onboard_tft = None def simple_run(molde, camera, keys="len", keyx=None, num=0, color=0xF800, size=2, sync=True): global _onboard_tft if _onboard_tft is None: from mixgo_sant import onboard_tft _onboard_tft = onboard_tft if sync: _onboard_tft.fill(0, sync=False) _img = camera.capture() _onboard_tft.display(_img, sync=False) _result = molde.run(_img.image) _data = None if _result: _x_of = (camera.get_pixel_width() - _onboard_tft.width) // 2 _y_of = (camera.get_pixel_height() - _onboard_tft.height) // 2 for r in _result: x = 0 y = 0 if r['box']: _onboard_tft.rect(r['box'][0] - _x_of, r['box'][1] - _y_of, r['box'][2], r['box'][3], color, sync=False) x = r['box'][0] y = r['box'][1] + r['box'][3] if "person" in r: _onboard_tft.shows(r['person']['name'], x=x - _x_of, y=y - _y_of, size=size, center=0, color=color, sync=False) else: if r['box']: _onboard_tft.shows(r['data'], x=x - _x_of, y=y - _y_of, size=size, center=0, color=color, sync=False) else: _onboard_tft.shows(r['data'], y=0, size=size, center=True, color=color, sync=False) break if keys == "len": _data = len(_result) else: _data = _result[num][keys] if keyx is None else _result[num][keys][keyx] if sync: _onboard_tft.show() return _data