Minoru Inoue
Published © MIT

Detecting Object for Vehicle Blind Spot by M5StickV

Detect cars and people which is blinding by drivers. You need only putting M5Stack and you aren't doing dedicated construction.

BeginnerShowcase (no instructions)5 hours6,046
Detecting Object for Vehicle Blind Spot by M5StickV

Things used in this project

Hardware components

M5Stack M5StickV
×1
Flash Memory Card, MicroSDHC Card
Flash Memory Card, MicroSDHC Card
I bought 32GB and choose lexar. https://www.amazon.com/dp/B012PLSCQ0
×1

Software apps and online services

M5Stack V-Training
I processed it. https://docs.m5stack.com/#/en/related_documents/v-training

Story

Read more

Code

boot.py

MicroPython
This code is detecting object by XXXXXX.kmodel and blinking LED.
If you using this code, please make kmodel from V-Train. And you need coping sd card this code with *.kmodel.

[Blink pattern]
* Not Detecting Object: White
* Detecting Vehicle: Green
* Detecting human: Red
import image
import lcd
import sensor
import sys
import time
import KPU as kpu
from fpioa_manager import fm
from machine import UART
from Maix import GPIO

import KPU as kpu

# UART
fm.register(35, fm.fpioa.UART2_TX, force=True)
fm.register(34, fm.fpioa.UART2_RX, force=True)
uart_port = UART(UART.UART2, 115200, 8, 0, 0,\
    timeout=1000, read_buf_len=4096)

# LED
fm.register(6, fm.fpioa.GPIO0)
fm.register(9, fm.fpioa.GPIO1)
fm.register(8, fm.fpioa.GPIO2)
fm.register(7, fm.fpioa.GPIO3)
led_r = GPIO(GPIO.GPIO0, GPIO.OUT)
led_r.value(1)
led_g = GPIO(GPIO.GPIO1, GPIO.OUT)
led_g.value(1)
led_b = GPIO(GPIO.GPIO2, GPIO.OUT)
led_b.value(1)
led_w = GPIO(GPIO.GPIO3, GPIO.OUT)
led_w.value(1)


lcd.init()
lcd.rotation(2)

task = kpu.load("/sd/XXXXXX.kmodel")

labels=["1","2"] #You can check the numbers here to real names.

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.run(1)

lcd.clear()


while(True):
    img = sensor.snapshot()
    fmap = kpu.forward(task, img)
    plist=fmap[:]
    pmax=max(plist)
    max_index=plist.index(pmax)
    a = lcd.display(img)
    if pmax > 0.95:
        lcd.draw_string(40, 60, "Accu:%.2f Type:%s"%(pmax, labels[max_index].strip()))
        if labels[max_index] == "1":
            led_r.value(0)
            led_g.value(1)
            led_b.value(1)
            led_w.value(1)
        elif labels[max_index] == "2":
            led_r.value(1)
            led_g.value(0)
            led_b.value(1)
            led_w.value(1)
        uart_port.write(bytearray("LEDON"))
        time.sleep_ms(10)
    else:
        led_r.value(1)
        led_g.value(1)
        led_b.value(0)
        led_w.value(0)
        uart_port.write(bytearray("LEDOFF"))
        time.sleep_ms(10)

a = kpu.deinit(task)

Credits

Minoru Inoue

Minoru Inoue

1 project • 3 followers

Comments