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()

 

转载于:https://www.cnblogs.com/cloudrivers/p/11567012.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值