【视频识别】基于matlab高斯模型视频车辆检测【含Matlab源码 503期】

89 阅读1分钟

一、简介

在这里插入图片描述
在这里插入图片描述

二、源代码


frameRate = get(trafficObj,'FrameRate');
% video = read(trafficObj);
% implay(video, frameRate);
darkCarValue = 50;
darkCar = rgb2gray(read(trafficObj,71));
noDarkCar = imextendedmax(darkCar, darkCarValue);
imshow(darkCar)
figure, imshow(noDarkCar)

sedisk = strel('disk',2);
noSmallStructures = imopen(noDarkCar, sedisk);
imshow(noSmallStructures)



nframes = get(trafficObj, 'NumberOfFrames');
I = read(trafficObj, 1);
taggedCars = zeros([size(I,1) size(I,2) 3 nframes], class(I));

for k = 1 : nframes
    singleFrame = read(trafficObj, k);

    % Convert to grayscale to do morphological processing.
    I = rgb2gray(singleFrame);

    % Remove dark cars.
    noDarkCars = imextendedmax(I, darkCarValue);

    % Remove lane markings and other non-disk shaped structures.
    noSmallStructures = imopen(noDarkCars, sedisk);

    % Remove small structures.
    noSmallStructures = bwareaopen(noSmallStructures, 150);

    % Get the area and centroid of each remaining object in the frame. The
    % object with the largest area is the light-colored car.  Create a copy
    % of the original frame and tag the car by changing the centroid pixel
    % value to red.
    L = bwlabel(noSmallStructures);
    taggedCars(:,:,:,k) = singleFrame;
    if any(L(:))

三、运行结果

在这里插入图片描述
在这里插入图片描述

四、备注

版本:2014a