How can I eliminate ghost detection?

I am tracking an object but I got a problem because my program detects a ghost object. How can I eliminate this? A screenshot is shown.

3 comentarios

KSSV
KSSV el 28 de Ag. de 2018
How we can comment/ help with out knowing code?
rrv
rrv el 29 de Ag. de 2018
im = (abs(input_image(:,:,1)-background(:,:,1)) > threshold) | (abs(input_image(:,:,2) - background(:,:,2)) > threshold) ...
| (abs(input_image(:,:,3) - background(:,:,3)) > threshold);
b = bwmorph(im,'close');
im = bwmorph(b,'open');
im = bwmorph(im,'erode',2);
biggest_object = bwlabel(im,8);
object = regionprops(biggest_object);
N = size(object,1);
if N < 1||isempty(object)
return
end
s=find([object.Area]<200);
if ~isempty(s)
object(s)=[ ];
end
N=size(object,1);
if N < 1 || isempty(object)
return
end
for n=1:N
hold on
centroid = object(n).Centroid;
C_X = centroid(1);
C_Y = centroid(2);
end
Walter Roberson
Walter Roberson el 29 de Ag. de 2018
Editada: Walter Roberson el 29 de Ag. de 2018
The above code loops over the number of centroids but does nothing with them, and does not display anything.
It would help if we had the original image to test with. And the value of threshold .

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 28 de Ag. de 2018

1 voto

You have attempted to index your image array as (X, Y) . That is incorrect: images arrays need to be indexed as (Y, X) in MATLAB. The first index in MATLAB, the row index, is considered to be the vertical distance (so the Y) and the second index in MATLAB, the column index, is considered to be the horizontal distance (so the X)
Image Analyst
Image Analyst el 29 de Ag. de 2018
You can get rid of half that program just by using bwareafilt():
biggest_object = bwareafilt(im, 1); % Extract largest blob only.
props = regionprops(biggest_object, 'Centroid');
if length(props) == 0 % If nothing is there, bail out.
return;
end
% Get centroid and plot it.
xCentroid = props.Centroid(1);
yCentroid = props.Centroid(2);
hold on;
plot(xCentroid, yCentroid, 'r+', 'MarkerSize', 30);
No need for the for loop, calls to size(), and other things you have there.

Preguntada:

rrv
el 28 de Ag. de 2018

Respondida:

el 29 de Ag. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by