v = VideoReader (“r.avi”);
numberOfFrames = v.NumberOfFrames;
n = numberOfFrames;
为k = 1: n;
b =阅读(v, k);
z = imbinarize (b):
统计= regionprops (“表”, z,“重心”,“MajorAxisLength”,“MinorAxisLength”,“区域”)
z2 = bwareafilt (z, 1000)
imshow (z2)
结束
为k = 1: n;
horizontalProfile = cross (z2, 1);
darkPixels = horizontalProfile < 1
startingColumn = find(darkPixels, 1,“第一”);
endingColumn = find(darkPixels, 1,“最后一次”);
hdistance = abs (endingColumn-startingColumn);
verticalProfile = mean(z2, 2);
darkPixels2 = verticalProfile < 1
startingrow = find(darkPixels2, 1,“第一”);
endingrow = find(darkPixels2, 1,“最后一次”);
vdistance = abs (endingrow-startingrow);
结束