how to get the value of a certain pixel-region in video and analyze them?
Show older comments
I have a video of pills moving from left to right slowly. I want to draw a visual line in the original video and when the pills get through that line, the program automatically increase the pills-number by one, namely, n=n+1.
here is my code:
%read the video
avi = aviread('sample.avi');
video = {avi.cdata};
pixels = double(cat(4,video{1:end}))/255;
nFrames = size(pixels,4)
%convert the video to gray scale
for f = 1:nFrames
pixel(:,:,f) = (rgb2gray(pixels(:,:,:,f)));
end
background=(pixel(:,:,1)+pixel(:,:,2)+pixel(:,:,3))/3; %get a background picture
%transfer the video to binary video and counting
for l = 2:1:nFrames
dif(:,:,l)=(abs(pixel(:,:,l)-background));
bw(:,:,l) = im2bw(dif(:,:,l), 0.2);
**if (0==any(bw(:,314,l))) && (0~=any(bw(:,313,l)))
n=n+1;
disp(n)
end**
end
however I don't know why the condition "if (0==any(bw(:,314,l))) && (0~=any(bw(:,313,l)))" never get satisfied and the displayed "n" hence equals 0. I am badly in need of help. Thanks all of you.
Accepted Answer
More Answers (0)
Categories
Find more on Video Formats and Interfaces in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!