How I can make automatic program to detect the spots!

5 次查看(过去 30 天)
Hi everyone, I have a problem which is I have a small parking and I need to detect the spots automatic rather than manually, in the figure below this my parking and I did a program to take image from my camera and cut it to get each spot alone but the problem if I move the camera I have to change the Coordinates see the code..
data1 = imread('data_car_01.png');
data1_gray = rgb2gray(data1);
A1 = imcrop(data1_gray,[140 0 240 300]);
subplot(3,3,2);
imshow(A1);
% % % Second Spot Picture 1
B1 = imcrop(data1_gray,[370 0 230 300]);
subplot(3,3,3);
imshow(B1);
% % % Third Spot Picture 1
C1 = imcrop(data1_gray,[590 0 235 300]);
subplot(3,3,4);
imshow(C1);
% % % Forth Spot Picture 1
D1 = imcrop(data1_gray,[820 0 500 300]);
subplot(3,3,4);
imshow(D1);
so how I can make it in automatic way..

回答(1 个)

KSSV
KSSV 2017-3-13
data = imread('data_car_01.png');
[r, c, n] = size(data);
% Convert to monochrome.
redPlane = data(:, :, 1);
greenPlane = data(:, :, 2);
bluePlane = data(:, :, 3);
% Find the standard deviation of each color channel.
redStdDev = std(single(redPlane(:)));
greenStdDev = std(single(greenPlane(:)));
blueStdDev = std(single(bluePlane(:)));
% Take the color channel with the highest contrast.
% Transfer it into a monochrome image. This will be the one that we use.
if redStdDev >= greenStdDev && redStdDev >= blueStdDev
% Red has most contrast - use that channel.
monoImage = single(redPlane);
elseif greenStdDev >= redStdDev && greenStdDev >= blueStdDev
% Green has most contrast - use that channel.
monoImage = single(greenPlane);
else
% Blue has most contrast - use that channel.
monoImage = single(bluePlane);
end
maxValue = max(max(monoImage));
minValue = min(min(monoImage));
monoImage = uint8(255 * (single(monoImage) - minValue) / (maxValue - minValue));
% Threshold to get the walls. This will also sharpen up blurry, fuzzy wall edges.
thresholdValue = uint8((maxValue + minValue) / 2);
binaryImage = 255 * (monoImage < thresholdValue);
I = binaryImage ;
I(I==0) = 100 ;
I(I==255) = 0 ;
[L,num] = bwlabel(I,4) ;
vislabels(L)
Use vislabels from the link: https://in.mathworks.com/matlabcentral/fileexchange/19665-visualize-output-of-bwlabel/content/vislabels.m. You can get your region of interest using L==1. L==2 etc.
Please note that the above code is taken from https://in.mathworks.com/matlabcentral/fileexchange/27175-maze-solution by Image Analyst.
  1 个评论
Khaled Al-Faleh
Khaled Al-Faleh 2017-3-13
thanks for your answering but sir I want to cut every spot alone in above code it determine the lines and its good but I need each spot alone save in different variable did you get the idea please ??

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for IP Cameras 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by