how to counting the number car in a image?

5 ビュー (過去 30 日間)
vu chung
vu chung 2015 年 5 月 10 日
編集済み: Image Analyst 2015 年 5 月 10 日
I'm working about detecting and counting cars but am counting wrong. In image I have 1 car but am counting many cars.
My code:
A=imread('1image_72.jpg');
figure,imshow(A); title('Original Image');
%Convert the Image to binary
B=im2bw(A);
%Fill the holes
C=imfill(B,'holes');
%Label the connected components
[Label,Total]=bwlabel(C,8);
figure,imshow(C); title('Labelled Image');
%Rectangle containing the region
Sdata=regionprops(Label,'BoundingBox');
%Crop all the Cars
for i=1:Total
Img=imcrop(A,Sdata(i).BoundingBox);
Name=strcat('Object Number:',num2str(i));
figure,imshow(Img); title(Name);
end

採用された回答

Image Analyst
Image Analyst 2015 年 5 月 10 日
You're simply doing a auto threshold, which most likely gives a terrible segmentation, and then basically counting all bright blobs regardless if they're a car, a reflection, a part of a car, or anything else. You can't do anything as simplistic as a global threshold. Maybe you should try stdfilt() and try to get areas that have a lot of variation in them, assuming that the road or parking lot will be smooth. Then threshold the stdfilt() image.
  2 件のコメント
vu chung
vu chung 2015 年 5 月 10 日
Thanks your ans when i try to do this code below, only count one car more two car count wrong. why?please help
imshow(I) background = imopen(I,strel('disk',15)); I2 = I - background; % figure, imshow(I2) I2=rgb2gray(I2); I3 = imadjust(I2); % figure, imshow(I3); level = graythresh(I3); bw = im2bw(I3,level); bw = bwareaopen(bw, 250); figure, imshow(bw) se = strel('square', 2); % Apply morphological operations to remove noise and fill in holes. filteredForeground = imopen(bw, se); filteredForeground=imclose(filteredForeground,strel('rectangle',[30,30])); filteredForeground=imfill(filteredForeground,'holes');
filteredForeground = imopen(filteredForeground, strel('square', 7)); filteredForeground=imclose(filteredForeground,strel('rectangle',[20,20])); filteredForeground=imfill(filteredForeground,'holes');
figure; imshow(filteredForeground); title('Clean Foreground');
cc = bwconncomp(filteredForeground, 4); msgbox(['so luong o to: ' num2str(cc.NumObjects)])
Image Analyst
Image Analyst 2015 年 5 月 10 日
編集済み: Image Analyst 2015 年 5 月 10 日
It doesn't look like you used stdfilt() like I recommended. Anyway, that's a different image and could use a different algorithm. For that image you should detect red. See my File Exchange for color segmentation methods. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by