zoukankan      html  css  js  c++  java
  • OpenVINO 对象识别 real_time_object_detection Movidius

    MP4 识别结果

    https://v.youku.com/v_show/id_XNDM3MTEyNDY2OA==.html

     

    from imutils.video import VideoStream
    import numpy as np
    import argparse
    import imutils
    import time
    import cv2
    
    
    # python3 mp4-video-realtime-label.py --config MobileNetSSD_deploy.prototxt --model MobileNetSSD_deploy.caffemodel --video pexels-video2.mp4
    ap = argparse.ArgumentParser()
    ap.add_argument("-c", "--config", required=True, help="filename of caffe network configuration")
    ap.add_argument("-m", "--model", required=True, help="filename of trained caffe model")
    ap.add_argument("-v", "--video", help="filename of the video (optional)")
    args = vars(ap.parse_args())
    
    
    use_camera = False
    if not args.get("video", False):
        use_camera = True
    
    
    CLASSES = ("background","warcraft", "bicycle", "bird", "boat","bottle", "bus", "car", "cat", "chair","cow", 
            "diningtable", "dog", "horse","motorbike", "person", "pottedplant","sheep", "sofa", "train", "tvmonitor")
    COLORS = np.random.uniform(0, 255, size=(len(CLASSES), 3))
    
    net = cv2.dnn.readNetFromCaffe(args["config"], args["model"])
    
    net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
    
    
    if use_camera:
        print("Camera...")
        vs = VideoStream(src=0).start()
        time.sleep(2.0)
    else:
        vs = cv2.VideoCapture(args["video"])
    
    
    while True:
        frame = vs.read()
        frame = frame if use_camera else frame[1]
        if frame is None:
            break
        frame = imutils.resize(frame, width=400)
    
        blob = cv2.dnn.blobFromImage(frame, 0.007843, (512, 393), 127.5)
    
    
        net.setInput(blob)
        detections = net.forward()
    
        for detection in detections.reshape(-1, 7):
            index = int(detection[1])
            confidence = float(detection[2])
    
    
            if confidence > 0.5:
                xmin = int(detection[3] * frame.shape[1])
                ymin = int(detection[4] * frame.shape[0])
                xmax = int(detection[5] * frame.shape[1])
                ymax = int(detection[6] * frame.shape[0])
                label = "{}: {:.2f}%".format(CLASSES[index], confidence * 100)
                cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), COLORS[index], 1)
                # Label
                cv2.rectangle(frame, (xmin-1, ymin-1),(xmin+70, ymin-10), COLORS[index], -1)
                # Labeltext
                cv2.putText(frame, label, (xmin, ymin -2), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (0,0,0),1)
    
        cv2.imshow("RaspBerry with Movidius", frame)
    
        key = cv2.waitKey(1) & 0xFF
        if key == ord('q'):
            break
    
    cv2.destroyAllWindows()
    if use_camera:
        vs.stop()
    else:
        vs.release()
  • 相关阅读:
    2021,6,10 xjzx 模拟考试
    平衡树(二)——Treap
    AtCoder Beginner Contest 204 A-E简要题解
    POJ 2311 Cutting Game 题解
    Codeforces 990G GCD Counting 题解
    NOI2021 SDPTT D2T1 我已经完全理解了 DFS 序线段树 题解
    第三届山东省青少年创意编程与智能设计大赛总结
    Luogu P6042 「ACOI2020」学园祭 题解
    联合省选2021 游记
    Codeforces 1498E Two Houses 题解 —— 如何用结论吊打标算
  • 原文地址:https://www.cnblogs.com/cloudrivers/p/11567012.html
Copyright © 2011-2022 走看看