以下为udacity的SDCND的一个项目
ps:这里使用的是用opencv进行特征提取+svm分类器的方法实现物体检测,是在深度学习流行前比较经典的实现方法
项目描述:
使用openCV提取图片特征,训练svm分类器,分类车辆与非车辆。用训练好的模型识别汽车前置摄像头记录视频中的车辆。
代码github地址:yang1688899/CarND-Vehicle-Detection
车辆非车辆数据:https://pan.baidu.com/s/13nCrYRdeK7TydsUiDiuHNA
实现步骤:
- 分析训练数据,提取图片HOG特征。
- 训练分类器
- 应用滑动窗口(sliding windows)实现车辆检测
- 应用热力图(heatMap)过滤错误检测(false positive)
分析训练数据,提取图片HOG特征
训练数据为64x64x3的RBG图片,包含车辆与非车辆图片两类,车辆图片8792张,非车辆图片8968张。 以下为车辆,非车辆图片样例:
提取HOG特征,以下为实现方法:
# Define a function to return HOG features and visualization
def get_hog_features(img, orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True):
if vis == True:
features, hog_image = hog(img, orientations=orient, pixels_per_cell=(pix_per_cell, pix_per_cell),
cells_per_block=(cell_per_block, cell_per_block), transform_sqrt=False,
visualise=True, feature_vector=False)
return features, hog_image
else:
features = hog(img, orientations=orient, pixels_per_cell=(pix_per_cell, pix_per_cell),
cells_per_block=(cell_per_block, cell_per_block), transform_sqrt=False,
visualise=False, feature_vector=feature_vec)
return features
以下为原图与提取的HOG特征图对比: