How to perform object detection correctly?

15 vues (au cours des 30 derniers jours)
Manisha Jaiswal
Manisha Jaiswal le 18 Avr 2018
I have a code in which background subtraction is used to detect the number of cars in parking lot. But, the output is not desirable i.e. it does not detect the number of cars correctly. N = 1; % num of frames to use to make averaged background tps=10; status = [0 0 0 0 0 0 0 0 0 0]; img = zeros(960,540,N); for i = 1:N img_tmp = imread(f_list(i).name); img(:,:,i) = img_tmp(:,:,1); img(:,:,i) = rgb2gray(img_tmp); end bck_img = (mean(img,3)); %average background template %subplot(121); imagesc(bck_img) %subplot(122); imagesc(img(:,:,1)) clear img; pause(5) %gaussian filter hsize = 80; sigma = 20; gaus_filt = fspecial('gaussian',hsize , sigma); %gaus_filt = fspecial('log',hsize , sigma); %subplot(121); imagesc(gaus_filt) %subplot(122); mesh(gaus_filt) colormap(gray)
SE = strel('diamond', 0); %this makes a matrice object for passing into imdilate())
%% Operations on frames cd('C:\Users\USER\Desktop\final year project\FFF\car'); f_list= dir('*jpeg'); for i = N:1:length(f_list)
img_tmp = double(imread(f_list(i).name)); %load image and convert to double for computation
img = img_tmp(:,:,1); %reduce to just the first dimension
% img = rgb2gray(img_tmp)
%subplot(221);
imagesc(img);
title('Raw');
%subtract background from the image
sub_img = (img - bck_img);
% subplot(222);
imagesc(sub_img);
title('background subtracted');
%gaussian blurr the image
gaus_img = filter2(gaus_filt,sub_img,'same');
% subplot(223);
imagesc(gaus_img);
title('gaussian smoothed');
%threshold the image
% subplot(224);
hist(gaus_img(:));
thres_img = (gaus_img < 20);
thres_img = ~thres_img;
thres_img = bwareaopen(thres_img,20);
se2 = strel('disk',1);
thres_img = imerode(thres_img,se2);
%counting no of blobs
[L, num] = bwlabel(thres_img);
stats = regionprops(L, 'Centroid');
thres_img = ~thres_img;
% subplot(224);
imagesc(thres_img);
%subplot(224);imagesc(gaus_img);
title('thresholded');
clc
fprintf('Total parking spaces : %i\n',tps)
fprintf('filled parking spaces : %i\n',num)
fprintf('vacant parking spaces : %i\n',tps-num)
Can you help me with the code? Also, sometimes greeen and blue cars are not detected.

Réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by