1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #!/usr/bin/env python
- #version : 2023.12.31
- #language : ch
- from maix import camera
- from maix import display
- from maix import image
- import numpy as np
- camera.camera.config(size=(320,240))
- ScreenOrientation = False
- image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
- class Edge:
- model = {
- "param": "/root/preset/model/sobel_int8.param",
- "bin": "/root/preset/model/sobel_int8.bin"
- }
- input_size = (224, 224, 3)
- output_size = (222, 222, 3)
- options = {
- "model_type": "awnn",
- "inputs": {
- "input0": input_size
- },
- "outputs": {
- "output0": output_size
- },
- "mean": [127.5, 127.5, 127.5],
- "norm": [0.0078125, 0.0078125, 0.0078125],
- }
- def __init__(self):
- from maix import nn
- print("-- load model:", self.model)
- self.model = nn.load(self.model, opt=self.options)
- print("-- load ok")
- def __del__(self):
- del self.model
- m = Edge()
- def lcdRotation(inputImg,rotationAngle):
- from maix import image
- imageRotationBuffer = inputImg.crop(0, 0, 240, 320)
- if ScreenOrientation:
- imgRotationAim = image.new(size = (240, 320))
- else:
- imgRotationAim = image.new(size = (320, 240))
- return imgRotationAim.draw_image(imageRotationBuffer.rotate(rotationAngle, adjust=1),0,0,alpha=1)
- if ScreenOrientation:
- CAMERAROTATE = +180
- else:
- CAMERAROTATE = +90
- canvas = image.new(size = (320, 240))
- while True:
- canvas.clear()
- img_edgedetection = camera.capture()
- img_edgedetection = img_edgedetection.resize(224, 224, padding = 0)
- out = m.model.forward(img_edgedetection, quantize=True, layout="hwc")
- out = out.astype(np.float32).reshape(m.output_size)
- out = (np.ndarray.__abs__(out) * 255 / out.max()).astype(np.uint8)
- data = out.tobytes()
- edgeModel = img_edgedetection.load(data,(222, 222), mode="RGB")
- # canvas = edgeModel
- if ScreenOrientation:
- canvasVER = canvas.crop(0,0,240,320)
- canvasVER = canvasVER.rotate(-90, adjust=1)
- display.show(canvasVER)
- else:
- canvas.draw_image(edgeModel,48,8)
- canvas.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
- display.show(canvas)
|