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

조회 수: 2 (최근 30일)
ravi k
ravi k 2016년 4월 25일
답변: Image Analyst 2016년 5월 7일
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