在上述代码中,与图像目标评估相近的有:
接下来,将应用非最大值抑制:
# apply non-maxima suppression to suppress weak, overlapping
# bounding boxes
idxs = cv2.dnn.NMSBoxes(boxes, confidences, args["confidence"],
args["threshold"])
# ensure at least one detection exists
if len(idxs) > 0:
# loop over the indexes we are keeping
for i in idxs.flatten():
# extract the bounding box coordinates
(x, y) = (boxes[i][0], boxes[i][1])
(w, h) = (boxes[i][2], boxes[i][3])
# draw a bounding box rectangle and label on the frame
color = [int(c) for c in COLORS[classIDs[i]]]
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2)
text = "{}: {:.4f}".format(LABELS[classIDs[i]],
confidences[i])
cv2.putText(frame, text, (x, y - 5),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)

同样的,在上述代码中与图像目标评估相近的有:
最终的部分代码如下:
# check if the video writer is None
if writer is None:
# initialize our video writer
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
writer = cv2.VideoWriter(args["output"], fourcc, 30,
(frame.shape[1], frame.shape[0]), True)
# some information on processing single frame
if total > 0:
elap = (end - start)
print("[INFO] single frame took {:.4f} seconds".format(elap))
print("[INFO] estimated total time to finish: {:.4f}".format(
elap * total))
# write the output frame to disk
writer.write(frame)
# release the file pointers
print("[INFO] cleaning up...")
writer.release()
vs.release()
总结一下:
现在,打开一个终端并执行下面命令:
$ python yolo_video.py --input videos/car_chase_01.mp4 \
--output output/car_chase_01.avi --yolo yolo-coco
[INFO] loading YOLO from disk...
[INFO] 583 total frames in video
[INFO] single frame took 0.3500 seconds
[INFO] estimated total time to finish: 204.0238
[INFO] cleaning up...

图6:YOLO应用于车祸视频对象测试
在视频/ GIF中,你虽然可以看见被检测到的汽车,还可以测试至人员及其交通信号灯!
YOLO目标检测器在该视频中体现相当不错。让这次尝试同一车追逐视频中的不同视频:
$ python yolo_video.py --input videos/car_chase_02.mp4 \
--output output/car_chase_02.avi --yolo yolo-coco
[INFO] loading YOLO from disk...
[INFO] 3132 total frames in video
[INFO] single frame took 0.3455 seconds
[INFO] estimated total time to finish: 1082.0806
[INFO] cleaning up...


图7:在该视频中,使用OpenCV和YOLO对象测试来找到该嫌疑人,嫌疑人现在早已撤离车辆并正位于停车场
YOLO再一次能够测试至行人!或者嫌疑人回到它们的车中并再次追逐:
$ python yolo_video.py --input videos/car_chase_03.mp4 \
--output output/car_chase_03.avi --yolo yolo-coco
[INFO] loading YOLO from disk...
[INFO] 749 total frames in video
[INFO] single frame took 0.3442 seconds
[INFO] estimated total time to finish: 257.8418
[INFO] cleaning up...

图8:YOLO是一种快速深度学习对象检测器,能够在使用GPU的状况下用于实时视频
最后一个例子,让我们说说如何使用YOLO作为构建流量计数器:
$ python yolo_video.py --input videos/overpass.mp4 \
--output output/overpass.avi --yolo yolo-coco
[INFO] loading YOLO from disk...
[INFO] 812 total frames in video
[INFO] single frame took 0.3534 seconds
[INFO] estimated total time to finish: 286.9583
[INFO] cleaning up...

图9:立交桥交通视频说明,YOLO和OpenCV可精确、快速地测试汽车
下面汇总YOLO视频对象测试完整视频:

YOLO目标检测器的最大限制跟特点是:
限制的缘由是鉴于YOLO算法其原本:
因此,如果你的数据集是由许多靠近在一起的小对象组成时,那么就不需要使用YOLO算法。就小物体而言,更快的R-CNN通常效果最好,但是其速度也很慢。在这里也可以使用SSD算法,SSD通常在速率跟准确性方面也是很高的考量。
值得注意的是,在本教程中,YOLO比SSD运行速率慢,大约慢一个数量级。因此,如果你正在使用预先练习的深度学习对象检测器供OpenCV使用,可能必须考量使用SSD算法而不是YOLO算法。
因此,在对于给定问题选取对象检测器时,我倾向于使用下面准则:

图10:在我的书“使用Python进行计算机视觉的深度学习”中,我介绍了多种对象测试算法,包括faster R-CNN、SSD、RetinaNet。书中讲述了怎样建立对象测试图像数据集、训练对象检测器并进行分析。
在本教程中,使用的YOLO模型是在COCO数据集上预先练习的.。但是,如果想在自己的数据集上练习深度学习对象检测器,该怎么操作呢?
大体思路是自己标注数据集,按照darknet网站上的指示及网上博客自己修改相应的参数训练即可。或者在我的书“深度学习计算机视觉与Python”中,详细讲述了怎样将faster R-CNN、SSD和RetinaNet应用于:
书中的所有目标评估章节都包括对算法和代码的具体表明,确保你无法顺利训练自己的对象检测器。在这里可以知道有关我的书的更多信息(并获得免费的样例章节和目录)。
在本教程中,我们学习了怎样使用Deep Learning、OpenCV和Python完成YOLO对象测试。然后,我们详细探讨了YOLO架构,并用Python实现:
在配备的3GHz Intel Xeon W处理器的机器上,YOLO的单次前向传输耗时约0.3秒;但是,使用单次检测器(SSD),检测耗时只需0.03秒,速度提高了一个数量级。对于使用OpenCV和Python在CPU上进行基于即时深度学习的对象测试,你或许应该考量使用SSD算法。
如果你有兴趣在自己的自定义数据集上练习深度学习对象检测器,请尽量参阅写的“使用Python进行计算机视觉深度学习”,其中提供了有关如何顺利训练自己的检测器的具体指南。或者参看本人之前的博客。
原文链接
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-140719-2.html
中国不好战