Counting line in video

3 ビュー (過去 30 日間)
Daniel Hamilton
Daniel Hamilton 2018 年 2 月 5 日
So I'm doing a project in automatic people counting using optical flow. I've managed to get the optical flow applied to the video and working quite well but I'm really struggling to implement a line onto the video that will actively tell when it has been crossed. I have attached the code i have for applying the optical flow and simply putting a line in where I'd like it to be but the line is purely for visual basis, it doesn't react to people crossing it. I've seen a few videos that have lines that when they are crossed change colour and allow for the count to go up or down. Any help would be greatly appreciated!
%% Initialisation step to clear up command window close all clear clc %% Set up video reader videoReader = vision.VideoFileReader('vtest.avi','ImageColorSpace','Intensity');
%This is a quicker way of carrying out rgb2gray for video %%Trigger line
%RGB = insertShape('videoReader','line',[135 500 335 200]); p1 = [200 300]; p2 = [275 200]; %plot([p1(2),p2(2)],[p1(1),p2(1)],'color','r','LineWidth',2); %% Set up optical flow of = opticalFlowHS; of.Smoothness = 0.1;
%Smoothness is the assumption that neighbouring pixels will have similar %values, so a if the change between frames is large, so should this be
%% Loop algorithm while(~isDone(videoReader)) %looping through for e\ach frame
% Acquire frame
vidFrame = step(videoReader); %Takes a screenshot
% Estimate flow
flowField = estimateFlow(of,vidFrame); %Estimate Flow gets the of between
%the specified frame and the previous one
% Visualize flow field
%subplot(2,2,[1 3]);
imshow(vidFrame)
hold on
plot(flowField,...
'DecimationFactor',[5 5],... %Divides the amount of arrows for less cluttered view, uses 2x2 matrix for x and y components
'ScaleFactor',5); %Scales the of vectors
title('Optical Flow')
hold on
plot([p1(2),p2(2)],[p1(1),p2(1)],'color','r','LineWidth',2);
hold off
% Update figures
drawnow;
end
%% Clean up release(videoReader);

回答 (0 件)

カテゴリ

Help Center および File ExchangeTracking and Motion Estimation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by