trafficObj = mmreader('viptraffic.avi');
frameRate = get(trafficObj,'FrameRate');
% video = read(trafficObj);
% implay(video, frameRate);
darkCarValue = 50;
darkCar = rgb2gray(read(trafficObj,71));
noDarkCar = imextendedmax(darkCar, darkCarValue);
% imshow(darkCar)
figure(1), imshow(noDarkCar)
sedisk = strel('disk',2);
noSmallStructures = imopen(noDarkCar, sedisk);
figure(2)
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(:))
stats = regionprops(L, {'centroid','area'});
areaArray = [stats.Area];
[junk,idx] = max(areaArray);
c = stats(idx).Centroid;
c = floor(fliplr(c));
width = 2;
row = c(1)-width:c(1)+width;
col = c(2)-width:c(2)+width;
taggedCars(row,col,1,k) = 255;
taggedCars(row,col,2,k) = 0;
taggedCars(row,col,3,k) = 0;
end
end
implay(taggedCars, frameRate);
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【达摩老生出品,必属精品,亲测校正,质量保证】 资源名:MATLAB目标跟踪_matlab_目标检测_实现对动态车辆的实时检测、跟踪和标记matlab(推荐)_动态车辆检测_车辆跟踪 资源类型:matlab项目全套源码 源码说明: 全部项目源码都是经过测试校正后百分百成功运行的,如果您下载后不能运行可联系我进行指导或者更换。 适合人群:新手及有一定经验的开发人员
资源推荐
资源详情
资源评论
收起资源包目录
MATLAB目标跟踪_matlab_目标检测_实现对动态车辆的实时检测、跟踪和标记matlab(推荐)_动态车辆检测_车辆跟踪.zip (3个子文件)
MATLAB目标跟踪_matlab_目标检测_实现对动态车辆的实时检测、跟踪和标记matlab(推荐)_动态车辆检测_车辆跟踪
Matlab实现无约束条件下普列姆(Prim)算法.docx 14KB
Image
viptraffic.avi 204KB
videopro.m 2KB
共 3 条
- 1
阿里matlab建模师
- 粉丝: 3193
- 资源: 2782
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页