예제 #1
0
def main(model_addr=0x300000, lcd_rotation=0, sensor_hmirror=False, sensor_vflip=False):
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_hmirror(sensor_hmirror)
    sensor.set_vflip(sensor_vflip)
    sensor.run(1)

    lcd.init(type=1)
    lcd.rotation(lcd_rotation)
    lcd.clear(lcd.WHITE)

    task = kpu.load(model_addr)
    anchors = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
    kpu.init_yolo2(task, 0.5, 0.3, 5, anchors) # threshold:[0,1], nms_value: [0, 1]
    try:
        while(True):
            img = sensor.snapshot()
            t = time.ticks_ms()
            objects = kpu.run_yolo2(task, img)
            t = time.ticks_ms() - t
            if objects:
                for obj in objects:
                    img.draw_rectangle(obj.rect())
            img.draw_string(0, 200, "t:%dms" %(t), scale=2)
            lcd.display(img)
    except Exception as e:
        sys.print_exception(e)
    finally:
        kpu.deinit(task)
예제 #2
0
def run(argv):
    mode = argv
    if (mode == 0):
        #check Arrow
        sensor.reset()
        '''sensor.set_auto_gain(False)
        sensor.set_contrast(1)
        sensor.set_gainceiling(16)
        #sensor.set_windowing((200, 200)) # 240x240 center pixels of VGA
        sensor.set_framesize(sensor.QQVGA)
        sensor.set_pixformat(sensor.GRAYSCALE)
        sensor.set_auto_whitebal(False)
        '''
        sensor.set_pixformat(sensor.GRAYSCALE)
        sensor.set_framesize(sensor.QQVGA)
        sensor.set_vflip(True)
        sensor.set_hmirror(True)
        sensor.skip_frames(time=2000)

        findArrow()
    else:
        #check signal mode
        sensor.reset()
        sensor.set_auto_gain(False)
        sensor.set_auto_whitebal(True)
        sensor.set_contrast(-3)
        sensor.set_brightness(-3)
        sensor.set_gainceiling(8)
        sensor.set_pixformat(sensor.RGB565)
        sensor.set_vflip(True)
        sensor.set_framesize(sensor.VGA)
        sensor.set_windowing((240, 240))  # 240x240 center pixels of VGA
        #sensor.set_windowing((200, 200)) # 200x200 center pixels of VGA
        sensor.skip_frames(time=800)
        checkSignal()
예제 #3
0
파일: boot.py 프로젝트: xpanhhu/maix_train
def main(labels=None,
         model_addr="/sd/m.kmodel",
         sensor_window=(224, 224),
         lcd_rotation=0,
         sensor_hmirror=False,
         sensor_vflip=False):
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_windowing(sensor_window)
    sensor.set_hmirror(sensor_hmirror)
    sensor.set_vflip(sensor_vflip)
    sensor.run(1)

    lcd.init(type=1)
    lcd.rotation(lcd_rotation)
    lcd.clear(lcd.WHITE)

    if not labels:
        with open('labels.txt', 'r') as f:
            exec(f.read())
    if not labels:
        print("no labels.txt")
        img = image.Image(size=(320, 240))
        img.draw_string(90, 110, "no labels.txt", color=(255, 0, 0), scale=2)
        lcd.display(img)
        return 1
    try:
        img = image.Image("startup.jpg")
        lcd.display(img)
    except Exception:
        img = image.Image(size=(320, 240))
        img.draw_string(90,
                        110,
                        "loading model...",
                        color=(255, 255, 255),
                        scale=2)
        lcd.display(img)

    task = kpu.load(model_addr)

    try:
        while (True):
            img = sensor.snapshot()
            t = time.ticks_ms()
            fmap = kpu.forward(task, img)
            t = time.ticks_ms() - t
            plist = fmap[:]
            pmax = max(plist)
            max_index = plist.index(pmax)
            img.draw_string(0,
                            0,
                            "%.2f : %s" % (pmax, labels[max_index].strip()),
                            scale=2)
            img.draw_string(0, 200, "t:%dms" % (t), scale=2)
            lcd.display(img)
    except Exception as e:
        raise e
    finally:
        kpu.deinit(task)
예제 #4
0
 def __init__(self,
              out_range=10,
              ignore_limit=0.02,
              hmirror=False,
              vflip=False,
              lcd_rotation=2,
              lcd_mirror=True):
     self.pitch = 0
     self.roll = 0
     self.out_range = out_range
     self.ignore = ignore_limit
     self.task_fd = kpu.load(0x300000)  # face model addr in flash
     anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658,
               5.155437, 6.92275, 6.718375, 9.01025)
     kpu.init_yolo2(self.task_fd, 0.5, 0.3, 5, anchor)
     lcd.init()
     lcd.rotation(lcd_rotation)
     lcd.mirror(lcd_mirror)
     sensor.reset()
     sensor.set_pixformat(sensor.RGB565)
     sensor.set_framesize(sensor.QVGA)
     if hmirror:
         sensor.set_hmirror(1)
     if vflip:
         sensor.set_vflip(1)
예제 #5
0
    def check(self):
        try:
            self.btn.expand_event()

            if self.btn.home() == 2:
                sipeed_led.w.value(0)
                Report.RearSensor_Test = True
                sample_page.next()

            if self.isconnected == False:
                try:
                    sensor.reset()
                    sensor.set_pixformat(sensor.YUV422)
                    sensor.set_framesize(sensor.QVGA)
                    sensor.set_hmirror(1)
                    sensor.set_vflip(1)
                    sensor.run(1)
                    sensor.skip_frames()
                    self.isconnected = True
                    sipeed_led.w.value(0)
                except Exception as e:
                    Report.RearSensor_Test = False
                    Report.isError = str(e)
                    print(e)
        except Exception as e:
            Report.RearSensor_Test = False
            Report.isError = str(e)
            print(e)
예제 #6
0
 def reset_sensor(self):
     sensor.reset()
     sensor.set_pixformat(sensor.RGB565)
     sensor.set_framesize(sensor.QVGA)
     sensor.set_vflip(True)
     sensor.set_hmirror(True)
     self.logger.trace("skipping frames...")
     sensor.skip_frames(time=2000)
예제 #7
0
 def init():
     sensor.reset(dual_buff=obj.is_dual_buff)
     sensor.set_pixformat(sensor.RGB565)
     sensor.set_framesize(sensor.QVGA)
     sensor.set_hmirror(1)
     sensor.set_vflip(1)
     sensor.run(1)
     sensor.skip_frames()
예제 #8
0
파일: main.py 프로젝트: gaku-hibi/Edge_AIoT
def init_sensor():
    lcd.init()
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)  # VGA is over
    sensor.set_hmirror(1)
    sensor.set_windowing((WINDOW_SIZE, WINDOW_SIZE))
    sensor.set_vflip(1)
    sensor.run(1)
 def init():
     sensor.reset(dual_buff=__class__.is_dual_buff)
     sensor.set_pixformat(sensor.RGB565)
     sensor.set_framesize(sensor.QVGA)
     sensor.set_windowing((320, 224))
     sensor.set_hmirror(1)
     sensor.set_vflip(1)
     sensor.run(1)
     sensor.skip_frames()
예제 #10
0
 def reset_sensor():
     sensor.reset()
     sensor.set_pixformat(
         sensor.RGB565 if COLOR_LINE_FOLLOWING else sensor.GRAYSCALE)
     sensor.set_framesize(FRAME_SIZE)
     sensor.set_vflip(True)
     sensor.set_hmirror(True)
     sensor.set_windowing((int((sensor.width() / 2) - ((sensor.width() / 2) * FRAME_WIDE)), int(sensor.height() * (1.0 - FRAME_REGION)), \
                          int((sensor.width() / 2) + ((sensor.width() / 2) * FRAME_WIDE)), int(sensor.height() * FRAME_REGION) - BOTTOM_PX_TO_REMOVE))
     sensor.skip_frames(time=200)
     if COLOR_LINE_FOLLOWING: sensor.set_auto_gain(False)
     if COLOR_LINE_FOLLOWING: sensor.set_auto_whitebal(False)
예제 #11
0
def camera_init():
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    # ov2640 id:9794 ,ov5642 id:22082
    if sensor.get_id() == 9794:
        sensor.set_hmirror(1)
        sensor.set_vflip(1)
    else:
        sensor.set_hmirror(0)
        sensor.set_vflip(1)
    lcd.rotation(1)
예제 #12
0
 def shoot(shutdown = False):
     import sensor
     if not Camera.isOn:
         sensor.reset()
         sensor.set_vflip(True)
         sensor.set_hmirror(True)
         sensor.set_pixformat(Camera.mode)
         sensor.set_framesize(Camera.frame)
         sensor.skip_frames(10)
     pic = sensor.snapshot()
     sensor.shutdown(shutdown)
     Camera.isOn = not shutdown
     return pic
예제 #13
0
 def __init__(self):
     """Initialize the LED to show state and setup the camera sensor"""
     self._red_led = pyb.LED(1)  # Turns led on (red color)
     self._red_led.on()
     # Setup sensor settings
     # https://docs.openmv.io/library/omv.sensor.html#constants
     sensor.reset()
     sensor.set_vflip(True)  # Reverse image on vertical axis
     sensor.set_hmirror(True)  # Reverse image on horizontal axis
     sensor.set_pixformat(sensor.RGB565)
     sensor.set_framesize(sensor.QVGA)
     sensor.set_auto_gain(False)  # Must be turned off for color tracking
     # Must be turned off for color tracking
     sensor.set_auto_whitebal(False)
예제 #14
0
def main(anchors, labels = None, model_addr="/sd/m.kmodel", sensor_window=(224, 224), lcd_rotation=0, sensor_hmirror=False, sensor_vflip=False):
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_windowing(sensor_window)
    sensor.set_hmirror(sensor_hmirror)
    sensor.set_vflip(sensor_vflip)
    sensor.run(1)

    lcd.init(type=1)
    lcd.rotation(lcd_rotation)
    lcd.clear(lcd.WHITE)

    if not labels:
        with open('labels.txt','r') as f:
            exec(f.read())
    if not labels:
        print("no labels.txt")
        img = image.Image(size=(320, 240))
        img.draw_string(90, 110, "no labels.txt", color=(255, 0, 0), scale=2)
        lcd.display(img)
        return 1
    try:
        img = image.Image("startup.jpg")
        lcd.display(img)
    except Exception:
        img = image.Image(size=(320, 240))
        img.draw_string(90, 110, "loading model...", color=(255, 255, 255), scale=2)
        lcd.display(img)

    task = kpu.load(model_addr)
    kpu.init_yolo2(task, 0.5, 0.3, 5, anchors) # threshold:[0,1], nms_value: [0, 1]
    try:
        while 1:
            img = sensor.snapshot()
            t = time.ticks_ms()
            objects = kpu.run_yolo2(task, img)
            t = time.ticks_ms() - t
            if objects:
                for obj in objects:
                    pos = obj.rect()
                    img.draw_rectangle(pos)
                    img.draw_string(pos[0], pos[1], "%s : %.2f" %(labels[obj.classid()], obj.value()), scale=2, color=(255, 0, 0))
            img.draw_string(0, 200, "t:%dms" %(t), scale=2, color=(255, 0, 0))
            lcd.display(img)
    except Exception as e:
        raise e
    finally:
        kpu.deinit(task)
예제 #15
0
def uarm_setup(grayscale=False, resolution=2):
    sensor.reset()
    sensor.set_pixformat(sensor.GRAYSCALE if grayscale else sensor.RGB565)
    # image resolution affects the calibration data
    size_lookup = [
        sensor.QQQQVGA, sensor.QQQVGA, sensor.QQVGA, sensor.QVGA, sensor.VGA
    ]
    sensor.set_framesize(size_lookup[resolution])
    # both rotate & mirror the image, so it's coordinates match the uArm's
    sensor.set_hmirror(True)
    # chop off the extra black spaces after rotation
    sensor.set_windowing((int((sensor.width() - sensor.height()) / 2), 0,
                          sensor.height(), sensor.height()))
    # any other sensor configurations go here...
    # finally, skip some frames after configuring
    sensor.skip_frames()
def initialize(uart_timeout):
    """Initialize the camera and lcd."""
    lcd.init(freq=15000000)
    sensor.reset(freq=20000000, set_regs=True, dual_buff=True)
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_hmirror(False)
    sensor.set_vflip(False)
    sensor.skip_frames(time=2000)
    fm.register(board_info.PIN15, fm.fpioa.UART1_TX)
    uart_A = UART(UART.UART1,
                  115200,
                  8,
                  0,
                  0,
                  timeout=uart_timeout,
                  read_buf_len=4096)
    last_time = time()
    return uart_A, last_time
예제 #17
0
 def init(self,
          gain_db=0,
          shutter_us=500000,
          framesize=sensor.WQXGA2,
          force_reset=True,
          flip=False):
     if self.simulate:
         self.shutter = shutter_us
         self.gain = gain_db
         self.snap_started = False
         return
     if force_reset or self.has_error or self.gain != gain_db or self.shutter != shutter_us or self.framesize != framesize or self.flip != flip:
         sensor.reset()
         sensor.set_pixformat(self.pixfmt)
         sensor.set_framesize(framesize)
         if flip:  # upside down camera
             sensor.set_vflip(True)
             sensor.set_hmirror(True)
         self.flip = flip
         self.framesize = framesize
         if shutter_us < 0:
             sensor.set_auto_exposure(True)
         else:
             if shutter_us > 500000:
                 sensor.__write_reg(0x3037, 0x08)  # slow down PLL
                 if shutter_us > 1000000:
                     pyb.delay(100)
                     sensor.__write_reg(0x3037, 0x18)  # slow down PLL
                     if shutter_us > 1500000:
                         pyb.delay(100)
                         sensor.__write_reg(0x3036, 80)  # slow down PLL
                         # warning: doesn't work well, might crash
                 pyb.delay(200)
             sensor.set_auto_exposure(False, shutter_us)
         self.shutter = shutter_us
         if gain_db < 0:
             sensor.set_auto_gain(True)
         else:
             sensor.set_auto_gain(False, gain_db)
         self.gain = gain_db
         self.wait_init = 2
         self.width = sensor.width()
         self.height = sensor.height()
예제 #18
0
def main(model_addr=0x300000,
         lcd_rotation=0,
         sensor_hmirror=False,
         sensor_vflip=False):
    try:
        sensor.reset()
    except Exception as e:
        raise Exception(
            "sensor reset fail, please check hardware connection, or hardware damaged! err: {}"
            .format(e))
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_hmirror(sensor_hmirror)
    sensor.set_vflip(sensor_vflip)
    sensor.run(1)

    lcd.init(type=1)
    lcd.rotation(lcd_rotation)
    lcd.clear(lcd.WHITE)

    anchors = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437,
               6.92275, 6.718375, 9.01025)
    try:
        task = None
        task = kpu.load(model_addr)
        kpu.init_yolo2(task, 0.5, 0.3, 5,
                       anchors)  # threshold:[0,1], nms_value: [0, 1]
        while (True):
            img = sensor.snapshot()
            t = time.ticks_ms()
            objects = kpu.run_yolo2(task, img)
            t = time.ticks_ms() - t
            if objects:
                for obj in objects:
                    img.draw_rectangle(obj.rect())
            img.draw_string(0, 200, "t:%dms" % (t), scale=2)
            lcd.display(img)
    except Exception as e:
        raise e
    finally:
        if not task is None:
            kpu.deinit(task)
def initialize_camera():
    err_counter = 0
    while 1:
        try:
            sensor.reset()  #Reset sensor may failed, let's try some times
            break
        except:
            err_counter = err_counter + 1
            if err_counter == 20:
                lcd.draw_string(lcd.width() // 2 - 100,
                                lcd.height() // 2 - 4,
                                "Error: Sensor Init Failed", lcd.WHITE,
                                lcd.RED)
            time.sleep(0.1)
            continue
    sensor.set_hmirror(1)
    sensor.set_vflip(1)
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.VGA)  #QVGA=320x240, VGA is max!!!
    sensor.run(1)
예제 #20
0
    def shoot(shutdown = False):
        import sensor
        if not Camera.isOn:
            sensor.reset()
            sensor.set_vflip(True)
            sensor.set_hmirror(True)
            sensor.set_pixformat(Camera.mode)
            sensor.set_framesize(Camera.frame)
            sensor.skip_frames(10)

        pic = sensor.snapshot()
        pic.gamma_corr(1, Camera.contrast, Camera.brightness)
        if Camera.filter1 > 0:
            postProcess.applyFilter(Camera.filter1, pic)
        if Camera.filter2 > 0:
            postProcess.applyFilter(Camera.filter2, pic)
        if Camera.postproc == 1:
            postProcess.faceDetect(pic)

        sensor.shutdown(shutdown)
        Camera.isOn = not shutdown
        return pic
예제 #21
0
def main(labels = None, model_addr="/sd/m.kmodel", lcd_rotation=0, sensor_hmirror=False, sensor_vflip=False):
    gc.collect()

    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_windowing((224, 224))
    sensor.set_hmirror(sensor_hmirror)
    sensor.set_vflip(sensor_vflip)
    sensor.run(1)

    lcd.init(type=1)
    lcd.rotation(lcd_rotation)
    lcd.clear(lcd.WHITE)

    if not labels:
        raise Exception("no labels.txt")

    task = kpu.load(model_addr)

    try:
        while(True):
            img = sensor.snapshot()
            t = time.ticks_ms()
            fmap = kpu.forward(task, img)
            t = time.ticks_ms() - t
            plist=fmap[:]
            pmax=max(plist) 
            max_index=plist.index(pmax)
            img.draw_string(0,0, "%.2f\n%s" %(pmax, labels[max_index].strip()), scale=2, color=(255, 0, 0))
            img.draw_string(0, 200, "t:%dms" %(t), scale=2, color=(255, 0, 0))
            lcd.display(img)
    except Exception as e:
        sys.print_exception(e)
    finally:
        kpu.deinit(task)
# Sensor Horizontal Mirror Example
#
# This example shows off horizontally mirroring the image in hardware
# from the camera sensor.

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

# Change this to False to undo the mirror.
sensor.set_hmirror(True)

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.
예제 #23
0
import sensor
import image
import lcd
import time

clock = time.clock()
#lcd.direction(lcd.YX_RLUD)
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(1)
sensor.set_hmirror(1)
sensor.run(1)
sensor.skip_frames(30)
#sensor.set_brightness(17)
while True:
    clock.tick()
    img = sensor.snapshot()
    res = img.find_qrcodes()
    fps = clock.fps()
    if len(res) > 0:
        #img.draw_string(2,2, res[0].payload(), color=(0,128,0), scale=2)
        tupleboxa = res[0].rect()
        img.draw_string(40, 20, res[0].payload(), (236, 36, 36), scale=1.5)
        img.draw_rectangle(tupleboxa, (236, 36, 36))
        print(res[0].payload())
    lcd.display(img)
예제 #24
0
파일: main.py 프로젝트: duan1229/learngit
    if last_key_state == 1 and val == 0:
        key_pressed = 1
    else:
        key_pressed = 0
    last_key_state = val


fm.register(7, fm.fpioa.UART1_RX, force=True)  #配置uart  7接收
uart = UART(UART.UART1, 115200, 8, None, 1, timeout=1000,
            read_buf_len=4096)  #配置uart
lcd.init()  # 初始化lcd
lcd.rotation(2)
sensor.reset()  #初始化sensor 摄像头
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)  #设置摄像头镜像
sensor.set_vflip(0)  #设置摄像头翻转
sensor.run(1)  #使能摄像头
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275,
          6.718375, 9.01025)  #anchor for face detect 用于人脸检测的Anchor
dst_point = [
    (44, 59), (84, 59), (64, 82), (47, 105), (81, 105)
]  #standard face key point position 标准正脸的5关键点坐标 分别为 左眼 右眼 鼻子 左嘴角 右嘴角
a = kpu.init_yolo2(task_fd, 0.5, 0.3, 5, anchor)  #初始化人脸检测模型
img_lcd = image.Image()  # 设置显示buf
img_face = image.Image(size=(128, 128))  #设置 128 * 128 人脸图片buf
a = img_face.pix_to_ai()  # 将图片转为kpu接受的格式
record_ftr = []  #空列表 用于存储当前196维特征
record_ftrs = []  #空列表 用于存储按键记录下人脸特征, 可以将特征以txt等文件形式保存到sd卡后,读取到此列表,即可实现人脸断电存储。
names = []  # 人名标签,与上面列表特征值一一对应。
with open("/sd/recordftr3.txt", "r") as f:
pulse = 0
counter = 0


# HALL EFFECT SENSOR PIN
pin = pyb.Pin("P9", pyb.Pin.IN)
#time.sleep(500)
extint = pyb.ExtInt(pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_DOWN, callback=callback1)



sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.skip_frames(time = 2000)
clock = time.clock()




# Using line object, following function returns shortest distance from center of image window
# to extended line's left boundary, as well as two important deviations: theta_deviation, which is the deviation
# of the camera alignment from the straight line, and rho_deviation, which is the deviation
# of the alignment from the perpendicular normal to the left boundary of the line. Both angular deviations could
# be more aptly described as the "SHORTEST TURN ANGLE TO ALIGN WITH RESPECTIVE DIRECTION",
# where the two directions in question are clearly orthogonal.

# "distance" = SHORTEST DISTANCE FROM POSITION TO INNER TURN (+8 PX) OF DISCOVERED LINE. This
# is so that car stays on the inside track (going left).
예제 #26
0
if OV77XX_EN:
    #sensor.reset(freq=20000000, set_regs=True, dual_buff=False) #OV7740  Loop Time :155ms, run fps:6.451613
    sensor.reset(freq=20000000,
                 dual_buff=True)  #OV7740  Loop Time :91ms, run fps:10.98901
    #sensor.reset(freq=20000000)
else:
    sensor.reset()  # OV2640 Reset and initialize the sensor. It will
    # run automatically, call sensor.run(0) to stop
#sensor.shutdown(enable)
gc.collect()
sensor.set_pixformat(
    sensor.RGB565)  # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.VGA)
#sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
#sensor.set_auto_whitebal(True)  #OV2640
sensor.set_hmirror(1)  #for unit V
sensor.set_vflip(1)  #for unit V

img_w = sensor.width()
img_h = sensor.height()
sensor_ID = sensor.get_id()
print("image sensor is " + str(sensor_ID) + ", with size " + str(img_w) +
      " x " + str(img_h))
sensor.run(1)
sensor.skip_frames(time=1000)  # Wait for settings take effect.
#sensor.skip_frames(30)             #Wait for settings take effect.
clock = time.clock()  # Create a clock object to track the FPS.
Zeit_end = 600 * 1000
condition = True
Zeit_Anfang = time.ticks_ms()
run_cnt = 0
예제 #27
0
# AprilTags
#
# Rotates the image based on the AprilTag
# Tested with TAG36H11

import sensor, image, time, math, pyb

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(
    sensor.QQVGA)  # we run out of memory if the resolution is much bigger...

flipped = True

sensor.set_hmirror(flipped)
sensor.set_vflip(flipped)
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)


def degrees(radians):
    return (180 * radians) / math.pi


def line_filter_call_back(src, dst):
    global length
    length = len(src)
    for i in range(len(src)):
        dst[i] = src[i >> 1]
import sensor
import image
import lcd
import time
from fpioa_manager import fm
from machine import UART
from board import board_info
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)  # Mirrors image
sensor.run(1)

fm.register(board_info.PIN15, fm.fpioa.UART1_TX,
            force=True)  # Sets pin15 as new TX-pin
# fm.register(board_info.PIN17, fm.fpioa.UART1_RX, force=True)
# fm.register(board_info.PIN9, fm.fpioa.UART2_TX, force=True)
# fm.register(board_info.PIN10, fm.fpioa.UART2_RX, force=True)

uart_A = UART(UART.UART1, 115200, 8, None, 1, timeout=1000, read_buf_len=4096)

green_threshold = (100, 0, -16, -128, 5, 15)

while True:
    img = sensor.snapshot()
    greenblobs = img.find_blobs([green_threshold],
                                area_threshold=40,
                                merge=True,
                                margin=10)
    if greenblobs:
import sensor,image,lcd,time
import KPU as kpu

from Maix import GPIO
from fpioa_manager import *
from board import board_info

lcd.init()
lcd.rotation(2)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)
sensor.set_vflip(0)
sensor.run(1)

fm.register(board_info.LED_R, fm.fpioa.GPIO4)
led_r = GPIO(GPIO.GPIO4, GPIO.OUT)
led_r.value(1)

clock = time.clock()

classes = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
task = kpu.load("/sd/model/20class.kmodel")
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)

try:
    while(True):
        clock.tick()
예제 #30
0
import sensor, image, time, lcd, math

lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)

sensor.set_contrast(-2)
sensor.set_gainceiling(16)
sensor.set_vflip(False)
sensor.set_hmirror(False)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
IMG_HEIGHT = 224
IMG_WIDTH = 224
sensor.set_windowing((IMG_HEIGHT, IMG_WIDTH))

sensor.run(1)
sensor.skip_frames(time = 500)

COLOR_THRESHOLD = [(96, 100, -128, 127, -128, 127)]
AREA_THRESHOLD = 40
PIXELS_THRESHOLD = 40
LANE_ROI = (0, 112, IMG_WIDTH, 112)
BINARY_VIEW = True

MAG_THRESHOLD = 0
MIXING_RATE = 0.9

THROTTLE_OFFSET = 1000.0
THROTTLE_GAIN = 1.0
예제 #31
0
#k210阈值测试codes
import sensor
import image
import lcd
import time
import pyb
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(1)  #摄像头镜像
sensor.set_vflip(1)
sensor.run(1)
sensor.skip_frames(30)  #跳过指定帧数或者跳过指定时间内的图像,让相机图像稳定
test_threshold = (30, 53, 24, 50, 22, 42)  #所测试区域的阈值
while True:
    img = sensor.snapshot()
    blobs1 = img.find_blobs([test_threshold])
    if blobs1:
        for b in blobs1:
            tmp = img.draw_rectangle(b[0:4])  #画矩阵
            tmp = img.draw_cross(b[5], b[6])  #画中心交叉点
            c = img.get_pixel(b[5], b[6])
            print('find it')
            pyb.delay(500)
    lcd.display(img)