7

OpenVINO + OpenCV 实现车辆检测与道路分割

 3 years ago
source link: https://bbs.cvmart.net/articles/4304
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

OpenVINO + OpenCV 实现车辆检测与道路分割

1个月前 ⋅ 570 ⋅ 0 ⋅ 0

来源:OpenCV学堂

模型介绍

OpenVINO支持道路分割与车辆检测,预训练模型分别为:

- road-segmentation-adas-0001
- vehicle-detection-adas-0002

其中道路分割模型的输出四个分类,格式如下:

BG, road, curb, mark, 输出格式[NCHW]=[1x4x512x896]

车辆检测模型基于SSD MobileNetv1实现,输出格式为:

NCHW = [1x1xNx7],其中N表示检测到boxes数目

道路分割模型加载与推理

首先加载道路分割模型,代码如下:

 1# 道路分割 2net = ie.read_network(model=model_xml, weights=model_bin) 3input_blob = next(iter(net.input_info)) 4out_blob = next(iter(net.outputs)) 5 6n, c, h, w = net.input_info[input_blob].input_data.shape 7print(n, c, h, w) 8 9cap = cv.VideoCapture("D:/images/video/project_video.mp4")10exec_net = ie.load_network(network=net, device_name="CPU")

推理与解析

 1# 推理道路分割

车辆检测模型加载与推理解析

加载车辆检测模型,推理与解析SSD输出结果的代码如下:

 1# 车辆检测 2vnet = ie.read_network(model=vehicel_xml, weights=vehicel_bin) 3vehicle_input_blob = next(iter(vnet.input_info)) 4vehicle_out_blob = next(iter(vnet.outputs)) 5 6vn, vc, vh, vw = vnet.input_info[vehicle_input_blob].input_data.shape 7print(n, c, h, w) 8vehicle_exec_net = ie.load_network(network=vnet, device_name="CPU") 910# 车辆检测11inf_start = time.time()12image = cv.resize(frame, (vw, vh))13image = image.transpose(2, 0, 1)14vec_res = vehicle_exec_net.infer(inputs={vehicle_input_blob:[image]})1516# 解析车辆检测结果17ih, iw, ic = frame.shape18vec_res = vec_res[vehicle_out_blob]19for obj in vec_res[0][0]:20    if obj[2] > 0.5:21        xmin = int(obj[3] * iw)22        ymin = int(obj[4] * ih)23        xmax = int(obj[5] * iw)24        ymax = int(obj[6] * ih)25        cv.rectangle(frame, (xmin, ymin), (xmax, ymax), (0, 0, 255), 2, 8)26        cv.putText(frame, str(obj[2]), (xmin, ymin), cv.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 255), 1)

运行结果如下:
file

视频文件(截图)
file

基于OpenVINO的参考用例,利用这些参考用例可以快速生成完整的OpenVINO应用:

基于OpenVINO的智能交通管理:https://software.intel.com/iot/edgesoftwarehub/download/home/ri/intelligent_traffic_management/

基于OpenVINO的驾驶员状态监控:https://software.intel.com/iot/edgesoftwarehub/download/home/ri/driver_management

极市 & 英特尔OpenVINO™联合(中级)认证入口:https://www.cvmart.net/list/OV2020

(官方权威认证证书 + 丰厚礼品 + 10分钟 实操认证视频教程:https://www.bilibili.com/video/BV1TZ4y137nn

 推荐阅读 

OpenVINO + OpenCV 实现点头与摇头识别验证

版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK