12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/env python
- #version : 2023.12.31
- #language : ch
- from maix import camera
- from maix import display
- from maix import image
- from maix import nn
- from maix.nn import decoder
- camera.camera.config(size=(320,240))
- image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
- model = {
- "param": "/root/preset/model/yolo2_face_awnn.param",
- "bin": "/root/preset/model/yolo2_face_awnn.bin"
- }
- labels = ["person"]
- options = {
- "model_type": "awnn",
- "inputs": {
- "input0": (224, 224, 3)
- },
- "outputs": {
- "output0": (7, 7, (1+4+len(labels))*5)
- },
- "mean": [127.5, 127.5, 127.5],
- "norm": [0.0078125, 0.0078125, 0.0078125],
- }
- anchors = [1.19, 1.98, 2.79, 4.59, 4.53, 8.92, 8.06, 5.29, 10.32, 10.65]
- m = nn.load(model, opt=options)
- yolo2_decoder = decoder.Yolo2(len(labels), anchors, net_in_size=(options["inputs"]["input0"][0], options["inputs"]["input0"][1]), net_out_size=(7, 7))
- canvasImg = image.new(size = (240, 320))
- while True:
- canvasImg.clear()
- img_facedetection = camera.capture()
- img_facedetection = img_facedetection.crop(0, 0,224, 224)
- out = m.forward(img_facedetection.tobytes(), quantize=True, layout="hwc")
- boxes, probs = yolo2_decoder.run(out, nms=0.3, threshold=0.3, img_size=(options["inputs"]["input0"][0], options["inputs"]["input0"][1]))
- if len(boxes):
- for i in (boxes):
- img_facedetection.draw_rectangle(i[0],i[1], int(i[0]+i[2]),int(i[1]+i[3]), color=(255,0,0), thickness=1)
- canvasImg.draw_image(img_facedetection,48,8)
- canvasImg.draw_image(image.open("/root/preset/img/exit_ff0000_24x24.png"),288,216,alpha=1)
- display.show(canvasImg)
|