def test_image(): from PIL import Image, ImageDraw image = Image.new("RGB", (100, 60), "#FFFFFF") draw = ImageDraw.Draw(image) draw.text((10, 10), u'hello world', (0, 0, 0)) image = image.rotate(90) # image.show() from maix import display display.show(image, (0, 120))
async def main(packet): if packet["selected"] == "demo": img = camera.capture() if img: out = npu.forward(img, quantize=True) out = nn.F.softmax(out) if out.max() > 0.1: draw = ImageDraw.Draw(img) draw.text((0, 0), "{:.2f}: {}".format(out.max(), labels[out.argmax()]), (255, 0, 0), font) display.show(img) # else: # await asyncio.sleep(0.02) elif packet["selected"] == "main": display.show(canvas) elif packet["selected"] == "exit": display.show(exits) # else: # # await asyncio.sleep(0.02) asyncio.ensure_future(main(packet))
return None def __del__(self): self.cam.release() camera = CvMaixVideo() except Exception as e: pass # registered interface capture = camera.capture read = camera.read config = camera.config height = camera.height width = camera.width close = camera.close if __name__ == '__main__': camera.config((224, 224)) from maix import display display.clear((255, 0, 0)) display.show(camera.capture()) # tmp = camera.read() # import _maix # frame = _maix.rgb2jpg(camera.rgbbuf, camera.width, camera.height) # print(len(frame) // 1024, camera.width, camera.height) # from PIL import Image # from io import BytesIO # img = Image.open(BytesIO(frame)) # img.show()
"norm": [0.00784313725490196, 0.00784313725490196, 0.00784313725490196], } print("-- load model:", model) m = nn.load(model, opt=options) print("-- load ok") print("-- read image") img = Image.open(test_jpg) print("-- read image ok") print("-- forward model with image as input") out = m.forward(img, quantize=True) print("-- read image ok") print("-- out:", out.shape) out = nn.F.softmax(out) print(out.max(), out.argmax()) from classes_label import labels while 1: img = camera.capture() if not img: time.sleep(0.02) continue out = m.forward(img, quantize=True) out = nn.F.softmax(out) msg = "{:.2f}: {}".format(out.max(), labels[out.argmax()]) print(msg) draw = ImageDraw.Draw(img) draw.text((0, 0), msg, fill=(255, 0, 0)) display.show(img)
from maix import display import asyncio import time import os import socket os.system('replug_sensor.sh') def get_host_ip(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 80)) ip = "IP: " + s.getsockname()[0] except Exception as e: ip = "IP does not exist" finally: s.close() return ip font = ImageFont.truetype("/home/res/baars.ttf", 27, encoding="unic") canvas = Image.new("RGB", (240, 240), "#2c3e50") with Image.open('/home/res/logo.png') as logo: canvas.paste(logo, (50, 40, 50 + logo.size[0], 40 + logo.size[1]), logo) draw = ImageDraw.Draw(canvas) draw.text((25, 195), get_host_ip(), "#bdc3c7", font) display.show(canvas)
def test_camera(): from maix import camera, display display.show(camera.capture())