How to select a particular region in a image, and segment it & compare it ?

2 次查看(过去 30 天)
Hi all, I'm doing a project on Vacant parking space detection. I can able to detect the change in the entire frame but I want to detect for only particular space. can any one help? Thanks in advance.
video = VideoReader('demo_parking.mp4');
I = read(video,1);
Background = read(video,1);
Background1 =abs(Background - I);
for k = 1:500
if k== 1
Background = read(video,1);
else
% Change background slightly at each frame
% Background(t+1)=(1-alpha)*I+alpha*Background
Background1 =abs(Background - I);
end
I=k;
k=k+12;
grayImage = rgb2gray(Background1); % Convert to gray level
thresholdLevel = graythresh(grayImage); % Get threshold.
binaryImage = im2bw( grayImage, thresholdLevel); % Do the binarization
binaryImage = bwareaopen(binaryImage,1000);
se = strel('square', 5);
binaryImage=imdilate(binaryImage,se);
figure,imshow(binaryImage);
labeledImage = bwlabel(binaryImage, 8);
stats = regionprops(labeledImage,'BoundingBox','Area');
count=0;
total=8;
for j = 1 : length(stats)
thisBB = stats(j).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','g','LineWidth',1 );
count=count+1;
end
disp(['No of parked vehicles are ',num2str(count)]);
disp(['No of available slots ',num2str(total-count)]);
end

回答(1 个)

Image Analyst
Image Analyst 2016-5-7
Use a template. Use roipoly() or roipolyold() to define the spaces on one of the frames. You can save the vertex coordinates in a .mat file if you want.

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by