更新esp-dl 支持简单操作方法

This commit is contained in:
dahanzimin
2025-10-29 12:07:07 +08:00
parent b4e15e68b2
commit a631d74d87
2 changed files with 35 additions and 2 deletions

View File

@@ -15,3 +15,36 @@ def analyze(results, keys=None, num=0):
return len(results)
else:
return results[num][keys]
#简单处理模型运行结果
_onboard_tft = None
def simple_run(molde, camera, keys="len", 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
_img = camera.capture()
_onboard_tft.display(_img, sync=False)
_result = molde.run(_img.image)
_data = None
if _result:
for r in _result:
x = 0
y = 0
if r['box']:
_onboard_tft.rect(r['box'][0], r['box'][1], 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, y=y, size=size, center=0, color=color, sync=False)
else:
_onboard_tft.shows(r['data'], x=x, y=y, size=size, center=0, color=color, sync=False)
if keys == "len":
_data = len(_result)
else:
_data = _result[num][keys]
if sync: _onboard_tft.show()
return _data

View File

@@ -48,7 +48,7 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
if img.width == self.width and img.height == self.height:
self._buffer[:] = img.image
#大于屏幕图像
elif img.width > self.width and img.height > self.height:
elif img.width >= self.width and img.height >= self.height:
_x = ((img.width - self.width) // 2) if x is None else max(0, min(x, img.width - self.width))
_y = ((img.height - self.height) // 2) if y is None else max(0, min(y, img.height - self.height))
for line in range(self.height):
@@ -56,7 +56,7 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
dst_pos = line * self.width * 2
self._buffer[dst_pos:dst_pos + self.width * 2] = img.image[src_pos:src_pos + self.width * 2]
#小于屏幕图像
elif img.width < self.width and img.height < self.height:
elif img.width <= self.width and img.height <= self.height:
_x = ((self.width - img.width) // 2) if x is None else max(0, min(x, self.width - img.width))
_y = ((self.height- img.height) // 2) if y is None else max(0, min(y, self.height - img.width))
for line in range(img.height):