光流场matlab,FPGA代做-matlab图像代写编程光流场的交通汽车检测跟踪

光流场matlab,FPGA代做-matlab图像代写编程光流场的交通汽车检测跟踪核心提示:FPGA代做-matlab图像代写编程光流场的交通汽车检测跟踪…clearallvideofile=’viptraffic.avi’;info=mmfileinfo(videofile);cols=info.Video.Width;rows=info.Video.Height;hReader=vision.VideoFileReader(videofile,…’Im…

光流场matlab,FPGA代做-matlab图像代写编程光流场的交通汽车检测跟踪

核心提示:FPGA代做-matlab图像代写编程光流场的交通汽车检测跟踪…

clear all

videofile = ‘viptraffic.avi’;

info = mmfileinfo(videofile);

cols=info.Video.Width;

rows=info.Video.Height;

hReader = vision.VideoFileReader(videofile,…

‘ImageColorSpace’, ‘RGB’,…

‘VideoOutputDataType’, ‘single’);

hFlow = vision.OpticalFlow( …

‘OutputValue’, ‘Horizontal and vertical components in complex form’, …

‘ReferenceFrameDelay’, 3,…

‘Method’,’Horn-Schunck’);

hMean1 = vision.Mean;

hMean2 = vision.Mean(‘RunningMean’, true);

hFilter = vision.MedianFilter;

hClose = vision.MorphologicalClose(‘Neighborhood’, strel(‘line’,5,45));

hBlob = vision.BlobAnalysis(…

‘CentroidOutputPort’, false,…

‘AreaOutputPort’, true, …

‘BoundingBoxOutputPort’, true,…

‘OutputDataType’, ‘double’, …

‘MinimumBlobArea’, 250,…

‘MaximumBlobArea’, 3600,…

‘MaximumCount’, 80);

hErode = vision.MorphologicalErode(‘Neighborhood’, strel(‘square’,2));

hShape1 = vision.ShapeInserter(…

‘BorderColor’, ‘Custom’, …

‘CustomBorderColor’, [0 1 0]);

hShape2 = vision.ShapeInserter(…

‘Shape’,’Lines’, …

‘BorderColor’, ‘Custom’, …

‘CustomBorderColor’, [255 255 0]);

hText = vision.TextInserter(…

‘Text’, ‘%4d’,…

‘Location’,  [1 1], …

‘Color’, [1 1 1],…

‘FontSize’, 12);

sz = get(0,’ScreenSize’);

pos = [(sz(3)-4*(cols+75))/2, (sz(4)-rows)/2 cols+60 rows+80];

hVideo1 = vision.VideoPlayer(‘Name’,’Original Video’,’Position’,pos);

pos(1) = pos(1)+cols+75;

hVideo2 = vision.VideoPlayer(‘Name’,’Motion Vector’,’Position’,pos);

pos(1) = pos(1)+cols+75;

hVideo3 = vision.VideoPlayer(‘Name’,’Thresholded Video’,’Position’,pos);

pos(1) = pos(1)+cols+75;

hVideo4 = vision.VideoPlayer(‘Name’,’Results Video’,’Position’,pos);

[xpos,ypos]=meshgrid(1:5:cols,1:5:rows);

xpos=xpos(:);

ypos=ypos(:);

locs=sub2ind([rows,cols],ypos,xpos);

while ~isDone(hReader)

pause(0.3);

frame  = step(hReader);

gray = rgb2gray(frame);

flow = step(hFlow, gray);

lines = [xpos, ypos, xpos+20*real(flow(locs)), ypos+20*imag(flow(locs))];

vector = step(hShape2, frame, lines);

magnitude = flow .* conj(flow);

threshold = 0.5 * step(hMean2, step(hMean1, magnitude));

carobj = step(hFilter, magnitude >= threshold);

carobj = step(hClose, step(hErode, carobj));

[area, bbox] = step(hBlob, carobj);

grow=22;

idx = bbox(:,1) > grow;

ratio = zeros(length(idx), 1);

ratio(idx) = single(area(idx,1))./single(bbox(idx,3).*bbox(idx,4));

flag = ratio > 0.4;

count = int32(sum(flag));

bbox(~flag, :) = int32(-1);

result = step(hShape1, frame, bbox);

result(grow:grow+1,:,:) = 1;

result(1:15,1:30,:) = 0;

result = step(hText, result, count);

step(hVideo1, frame);

step(hVideo2, vector);

step(hVideo3, carobj);

step(hVideo4, result);

end

release(hReader);

今天的文章光流场matlab,FPGA代做-matlab图像代写编程光流场的交通汽车检测跟踪分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/32788.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注