行人检测

from openvino.inference_engine import IECore
import time
import cv2 as cv


def ssd_video_demo():
    ie = IECore()
    for device in ie.available_devices:
        print(device)

    model_xml = "/home/bhc/BHC/model/intel/pedestrian-and-vehicle-detector-adas-0001/FP16/pedestrian-and-vehicle-detector-adas-0001.xml"
    model_bin = "/home/bhc/BHC/model/intel/pedestrian-and-vehicle-detector-adas-0001/FP16/pedestrian-and-vehicle-detector-adas-0001.bin"

    net = ie.read_network(model=model_xml, weights=model_bin)
    input_blob = next(iter(net.input_info))
    out_blob = next(iter(net.outputs))

    n, c, h, w = net.input_info[input_blob].input_data.shape
    print(n, c, h, w)

    cap = cv.VideoCapture("1.mp4")
    exec_net = ie.load_network(network=net, device_name="CPU")

    while True:
        ret, frame = cap.read()
        if ret is not True:
            break
        image = cv.resize(frame, (w, h))
        image = image.transpose(2, 0, 1)
        inf_start = time.time()
        res = exec_net.infer(inputs={input_blob:[image]})
        inf_end = time.time() - inf_start
        print("infer time(ms):%.3f"%(inf_end*1000))
        ih, iw, ic = frame.shape
        res = res[out_blob]                                         #输出结果(1, 1, N, 7,)
        for obj in res[0][0]:                                       # [image_id, label, conf, x_min, y_min, x_max, y_max]
            if obj[2] > 0.5:
                xmin = int(obj[3] * iw)
                ymin = int(obj[4] * ih)
                xmax = int(obj[5] * iw)
                ymax = int(obj[6] * ih)
                cv.rectangle(frame, (xmin, ymin), (xmax, ymax), (0, 255, 255), 2, 8)
        cv.putText(frame, "infer time(ms): %.3f, FPS: %.2f"%(inf_end*1000, 1/inf_end), (10, 50),
                   cv.FONT_HERSHEY_SIMPLEX, 1.0, (255, 0, 255), 2, 8)
        cv.imshow("Pedestrian Detection", frame)
        c = cv.waitKey(1)
        if c == 27:
            break
    cv.waitKey(0)
    cv.destroyAllWindows()


if __name__ == "__main__":
    ssd_video_demo()

 

上一篇:上货软件增加脚本


下一篇:ptootcms修改查询功能,例子:按条件查询出注册会员列表