【发布时间】:2014-11-28 09:16:25
【问题描述】:
我正在尝试检测 video frame 中的车辆。更具体地说是检测车辆,然后统计检测到的车辆数量。
顺便说一下,我用的是MathWorks的MATLAB代码:Open this link
所以您可以在上面的链接中找到更多详细信息...
假设我们提取视频的特定帧。我需要的是通过添加更多行来扩展代码,这些行能够进一步指定检测到的车辆的类型(例如,如果它是汽车或轨道?)。
Concerning the original code used by Mathworks:
1) 导入视频(待处理)并初始化前景颜色检测器:
动机是使视频的处理更容易。因此,我们可以在一个帧中应用我们的处理,而不是处理整个视频,在该帧中,所有移动对象都从背景中分割出来。前景检测器需要一定数量的视频帧才能初始化高斯混合模型。本示例使用前 50 帧初始化混合模型中的三个高斯模式。
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 50);
videoReader = vision.VideoFileReader('visiontraffic.avi');
for i = 1:150
frame = step(videoReader); % read the next video frame
foreground = step(foregroundDetector, frame);
end
2) 检测视频帧中的车辆:
不幸的是,前景颜色检测器并不完美,因为它会产生一些附加噪声。因此,实现“形态学思想”以消除添加的噪声会很有趣:
se = strel('square', 3);
filteredForeground = imopen(foreground, se);
figure; imshow(filteredForeground); title('Clean Foreground');
3) 接下来,我们使用 vision.BlobAnalysis 对象找到对应于移动汽车的每个连接组件的边界框。对象通过拒绝包含少于 150 个像素的斑点进一步过滤检测到的前景。
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 150);
bbox = step(blobAnalysis, filteredForeground);
4) 让我们用一个小矩形框突出显示每个检测到的车辆:
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
5) 统计视频帧中出现的车辆数量:
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
'FontSize', 14);
非常感谢您的帮助。
【问题讨论】:
-
就目前而言,太宽泛了。首先考虑如何区分卡车和汽车(例如尺寸或形状)。
标签: matlab image-processing computer-vision video-processing matlab-cvst