Пример #1
0
def takePhoto():
    disp.font(disp.FONT_DejaVu40)
    disp.clear()
    disp.text(30, 110, 'Pose Please!', disp.WHITE)
    utime.sleep(2)
    disp.clear()
    disp.text(40, 110, 'Ready GO!', disp.WHITE)
    utime.sleep(1)
    disp.clear()
    i = 0
    while (i < 15):
        frame = ucamera.capture()
        if frame != None:
            disp.image(0, 0, frame, 0)
            if (i < 5):
                disp.text(150, 110, '3', disp.RED)
            elif (i > 5 and i < 10):
                disp.text(150, 110, '2', disp.RED)
            elif (i > 10 and i < 15):
                disp.text(150, 110, '1', disp.RED)
        i += 1
    utime.sleep(2)
    disp.clear()
    disp.text(60, 110, 'KaCha...', disp.WHITE)
    # 上传拍摄的照片
    image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT,
                              OSS_BUCKET, frame, "oss/face.jpg")
    utime.sleep(2)
    # 清除屏幕内容
    disp.clear()
    disp.text(20, 110, 'Upload Done!', disp.WHITE)
    utime.sleep(2)

    return image
Пример #2
0
def displayThread():
    # 引用全局变量
    global disp, frame, detected, plateNumber
    # 定义清屏局部变量
    clearFlag = False
    # 定义显示文本局部变量
    textShowFlag = False
    while True:
        # 采集摄像头画面
        frame = ucamera.capture()
        if frame != None:
            if detected == True:
                # 清除屏幕内容
                if clearFlag == False:
                    disp.clear()
                    clearFlag = True
                # 设置文字字体
                disp.font(disp.FONT_DejaVu40)
                # 显示识别的车牌号
                disp.text(25, 90, plateNumber, disp.RED)
                disp.text(25, 130, 'Recognized!!!', disp.RED)
                print('License Plate Recognized!!!')
                textShowFlag = False
            else:
                # 显示图像
                disp.image(0, 20, frame, 0)
                if textShowFlag == False:
                    # 设置显示字体
                    disp.font(disp.FONT_DejaVu18)
                    # 显示文字
                    disp.text(2, 0, 'Recognizing License Plate...', disp.WHITE)
                    textShowFlag = True
                clearFlag = False
Пример #3
0
def main():
    global disp, dev, g_score
    dev = Device()
    disp = display.TFT()

    connect_wifi(SSID, PWD)

    dev.on(Device.ON_CONNECT, cb_lk_connect)
    dev.on(Device.ON_SERVICE, cb_lk_service)
    dev.connect(key_info)

    while True:
        if g_lk_connect:
            break

    ucamera.init('uart', 33, 32)
    ucamera.setProp(ucamera.SET_FRAME_SIZE, ucamera.SIZE_320X240)

    while True:
        g_lk_service = False
        start = utime.ticks_ms()
        frame = ucamera.capture()
        time_diff = utime.ticks_diff(utime.ticks_ms(), start)
        print('capture time : %d' % time_diff)

        start = utime.ticks_ms()
        disp.image(0, 0, frame, 0)
        time_diff = utime.ticks_diff(utime.ticks_ms(), start)
        print('image time : %d' % time_diff)

        # fileid = dev.uploadFile('face.jpg', None)
        detectPedestrian(frame, 'pede.jpg', productKey, deviceName,
                         deviceSecret)

        if (g_score > 0.6):
            disp.clear()
            disp.font(disp.FONT_DejaVu40)
            # 显示识别结果
            disp.text(40, 80, 'Pedestrian', disp.RED)
            disp.text(40, 120, 'Deteted!!!', disp.RED)
            print('Pedestrian Detected!!!')
            utime.sleep_ms(1000)
            g_score = 0
Пример #4
0
def main():
    # 创建lcd display对象
    global disp
    disp = display.TFT()
    disp.font(disp.FONT_Default)

    # 连接网络
    connect_wifi(SSID, PWD)

    # 初始化摄像头, UART Rx PIN=33, TX PIN=32,M5STACK-CORE2上对应PORTA
    ucamera.init('uart', 33, 32)

    # 拍照上传人脸比对图片到OSS
    compareFaceImage = takePhoto()
    if (compareFaceImage == None):
        print('take photo fail, please restart!')
        disp.text(10, 110, 'Take Photo Fail, restart!', disp.WHITE)
        return

    # 创建AI对象
    ai = uai.AI(uai.AI_ENGINE_ALIYUN, ACCESS_KEY, ACCESS_SECRET)

    while True:
        # 抓取一帧图像
        frame = ucamera.capture()
        if (frame != None):
            # 显示图像
            disp.image(0, 0, frame, 0)
            # 设置显示字体
            disp.font(disp.FONT_DejaVu18)
            # 显示文字
            disp.text(10, 30, 'Recognizing face...', disp.WHITE)
            # 上传图片到OSS
            image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT,
                                      OSS_BUCKET, frame, "oss/test.jpg")
            print('content: %s' % image)
            if image != None:
                # 抓取一帧图像
                frame = ucamera.capture()
                # 显示图像
                disp.image(0, 0, frame, 0)
                # 显示文字
                disp.text(10, 30, 'Recognizing face...', disp.WHITE)
                # 人脸识别
                resp = ai.compareFace(image, compareFaceImage)
                print(resp)
                if (resp != None):
                    # 解析识别结果
                    confidence = resp['confidence']
                    x = resp['x']
                    y = resp['y']
                    w = resp['w']
                    h = resp['h']
                    # 置信度 > 60,表示识别成功
                    if confidence > 60:
                        # 清除屏幕内容
                        disp.clear()
                        # 设置文字字体
                        disp.font(disp.FONT_DejaVu40)
                        # 显示识别结果
                        disp.text(40, 90, 'Recognize', disp.RED)
                        disp.text(30, 130, 'successfully!', disp.RED)
                        print('Recognize successfully!!!')
                        utime.sleep(2)
                # 释放当前帧内存
                del frame
Пример #5
0
def main():
    # 创建lcd display对象
    global disp
    disp = display.TFT()
    disp.font(disp.FONT_Default)

    # 连接网络
    connect_wifi(SSID, PWD)

    # 初始化摄像头, UART Rx PIN=33, TX PIN=32,M5STACK-CORE2上对应PORTA
    ucamera.init('uart', 33, 32)

    # 创建AI对象
    ai = uai.AI(uai.AI_ENGINE_ALIYUN, ACCESS_KEY, ACCESS_SECRET)

    while True:
        # 抓取一帧图像
        frame = ucamera.capture()
        if (frame != None):
            # 显示图像
            disp.image(0, 0, frame, 0)
            # 设置显示字体
            disp.font(disp.FONT_DejaVu18)
            # 显示文字
            disp.text(10, 30, 'Recognizing face...', disp.WHITE)
            # 上传图片到OSS
            image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT,
                                      OSS_BUCKET, frame, "oss/test.jpg")
            print('content: %s' % image)
            if image != None:
                # 抓取一帧图像
                frame = ucamera.capture()
                # 显示图像
                disp.image(0, 0, frame, 0)
                # 显示文字
                disp.text(10, 30, 'Detecting Pedestrian...', disp.WHITE)
                # 人体检测
                resp = ai.detectPedestrian(image)
                print(resp)
                if (resp != None):
                    i = 0
                    # 解析识别结果
                    while (i < len(resp)):
                        type = resp[i]['type']
                        score = resp[i]['score']
                        x = resp[i]['x']
                        y = resp[i]['y']
                        w = resp[i]['w']
                        h = resp[i]['h']
                        # 当得分 > 0.6,表示识别成功
                        if score > 0.6:
                            # 清除屏幕内容
                            disp.clear()
                            # 设置文字字体
                            disp.font(disp.FONT_DejaVu40)
                            # 显示识别结果
                            disp.text(30, 90, 'Pedestrian', disp.RED)
                            disp.text(30, 130, 'Detected!!!', disp.RED)
                            print('Pedestrian Detected!!!')
                            utime.sleep(2)
                        i += 1
            # 释放当前帧内容
            del frame
Пример #6
0
def main():
    # 创建lcd display对象
    global disp
    disp = display.TFT()
    disp.font(disp.FONT_Default)

    # 连接网络
    connect_wifi(SSID, PWD)

    # 初始化摄像头, UART Rx PIN=33, TX PIN=32,M5STACK-CORE2上对应PORTA
    ucamera.init('uart', 33, 32)

    # 创建AI对象
    ai = uai.AI(uai.AI_ENGINE_ALIYUN, ACCESS_KEY, ACCESS_SECRET)

    while True:
        # 抓取一帧图像
        frame = ucamera.capture()
        if (frame != None):
            # 显示图像
            disp.image(0, 0, frame, 0)
            # 设置显示字体
            disp.font(disp.FONT_DejaVu18)
            # 显示文字
            disp.text(10, 30, 'Recognizing face...', disp.WHITE)
            # 上传图片到OSS
            image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT,
                                      OSS_BUCKET, frame, "oss/test.jpg")
            print('content: %s' % image)
            #image = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectFruits/DetectFruits1.jpg'
            if image != None:
                frame = ucamera.capture()
                disp.image(0, 0, frame, 0)
                disp.text(10, 30, 'Detecting Fruits...', disp.WHITE)
                # 水果识别
                resp = ai.detectFruits(image)
                print(resp)
                if (resp != None):
                    i = 0
                    # 解析识别结果
                    while (i < len(resp)):
                        name = resp[i]['name']
                        score = resp[i]['score']
                        x = resp[i]['x']
                        y = resp[i]['y']
                        w = resp[i]['w']
                        h = resp[i]['h']
                        # 当得分 > 0.6,表示识别成功
                        if score > 0.6:
                            name = translateName(name)
                            # 清除屏幕内容
                            disp.clear()
                            # 设置文字字体
                            disp.font(disp.FONT_DejaVu40)
                            # 显示识别结果
                            disp.text(40, 80, name, disp.RED)
                            disp.text(40, 120, 'Deteted!!!', disp.RED)
                            utime.sleep(2)
                        i += 1
            # 释放当前帧内存
            del frame
Пример #7
0
def main():
    # 创建lcd display对象
    global disp
    disp = display.TFT()
    disp.font(disp.FONT_Default)

    # 连接网络
    connect_wifi(SSID, PWD)

    # 初始化摄像头, UART Rx PIN=33, TX PIN=32,M5STACK-CORE2上对应PORTA
    ucamera.init('uart', 33, 32)

    # 创建AI对象
    ai = uai.AI(uai.AI_ENGINE_ALIYUN, ACCESS_KEY, ACCESS_SECRET)

    while True:
        # 抓取一帧图像
        frame = ucamera.capture()
        if (frame != None):
            # 显示图像
            disp.image(0, 0, frame, 0)
            # 设置显示字体
            disp.font(disp.FONT_DejaVu18)
            # 显示文字
            disp.text(10, 30, 'Recognizing face...', disp.WHITE)
            # 上传图片到OSS
            image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT, OSS_BUCKET, frame, "oss/test.jpg")
            print('content: %s' %image)
            #image = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectFruits/DetectFruits1.jpg'
            if image != None:
                frame = ucamera.capture()
                disp.image(0, 0, frame, 0)
                disp.text(0, 30, 'Recognizing License Plate...', disp.WHITE)
                # 车牌识别
                resp = ai.recognizeLicensePlate(image)
                print(resp)
                if (resp != None):
                    i = 0
                    # 解析识别结果
                    while (i < len(resp)):
                        plateNumber = resp[i]['plateNumber']
                        plateType = resp[i]['plateType']
                        confidence = resp[i]['confidence']
                        plateTypeConfidence = resp[i]['plateTypeConfidence']
                        x = resp[i]['x']
                        y = resp[i]['y']
                        w = resp[i]['w']
                        h = resp[i]['h']
                        # 当置信度 > 0.6,表示识别成功
                        if confidence > 0.6:
                            # 清除屏幕内容
                            disp.clear()
                            # 设置文字字体
                            disp.font(disp.FONT_DejaVu40)
                            # 显示识别的车牌号
                            disp.text(25, 90, plateNumber, disp.RED)
                            disp.text(25, 130, 'Deteted!!!', disp.RED)
                            utime.sleep(2)
                        else:
                            print('Recognizing license plate...')
                        i += 1
                else:
                    print('Recognizing license plate...')
            # 释放当前帧内存
            del frame