Auto detecting multiple points and tracking their locations

조회 수: 20 (최근 30일)
Pieter Boersma
Pieter Boersma 2021년 8월 5일
답변: Alan 2024년 5월 31일
I have a binary video with a few hundred moving white dots that I would like to track and get their respective x and y location individually. I tried following this example: https://www.mathworks.com/help/vision/ug/motion-based-multiple-object-tracking.html to auto track the points but it seems like the the white dots are too small or too dense to be picked up. Anyone have any advice?

답변 (1개)

Alan
Alan 2024년 5월 31일
Hi Pieter,
The example you mentioned in the given link can be fine-tuned to better suit your video. There are 2 distinct phases of object tracking:
  1. Object detection and track creation (a track is a detected object and its position)
  2. Track creation (involves updating the position of the tracked object and deleting the track if the object disappears for a certain threshold of frames)
I could help you out with the object detection part as I don’t have your video it would be difficult for me to create one. However, I could create a single frame containing dots:
I = zeros(100,150, 'uint8');
I2 = imnoise(I, "salt & pepper", 0.01);
I3 = imdilate(I2, strel("square", 3));
imshow(I3);
There is a function named detectObjects in the example link you have shared, which does a poor job of preprocessing this image with morphological operations. Here is just the pre-processing part:
% Function performing the morphological operations in the example
function mask = morph_ops1(mask)
mask = imopen(mask, strel('rectangle', [3,3]));
mask = imclose(mask, strel('rectangle', [15, 15]));
mask = imfill(mask, 'holes');
end
I4 = morph_ops1(I3);
imshow(I4);
title('Original Morphological Operations')
The following is a template function for blob analysis you can use:
function plotBlobs(img, originalImage, border)
img = imbinarize(img);
% Step 3: Create the Blob Analysis Object
blobAnalyzer = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, ...
'CentroidOutputPort', true, ...
'MinimumBlobArea', 1, ...
'MaximumCount', 1000); % maximum number of dots to be tracked
% Step 4: Analyze the Blobs
[centroids, boxes] = step(blobAnalyzer, img);
% Step 5: Display the Results
imshow(originalImage); % Display the original image
hold on;
for i = 1:length(boxes)
if border
rectangle('Position', boxes(i, :), 'EdgeColor', 'r'); % Draw bounding boxes
else
plot(centroids(i,1), centroids(i,2), 'b.'); % Mark centroids
end
end
hold off;
end
Let’s run blob analysis on the obtained image from the examples preprocessing:
plotBlobs(I4, I4, true);
As you can see most of the nearby dots have been merged, and hence the blob analysis did a bad job. To tackle this, you can modify the code to apply a series of 2 gentle erode operation as follows:
I5 = I3;
I5 = imerode(I5, strel("square", 2));
I5 = imerode(I5, strel("square", 2));
imshow(I5)
Let us know find blobs:
plotBlobs(I5, I5, true);
We can also plot the blob centroids on top of the original image to see if it aligns with the dots:
plotBlobs(I5, I3, false);
The centroids seem to roughly match the dots. If you wish to use the x-y coordinates, you can access them in the centroids variable in the plotBlobs function. To know more about the blob analysis, you can check out: https://www.mathworks.com/help/releases/R2021a/vision/ref/vision.blobanalysis-system-object.html
Here is a complete set of morphological operations using MATLAB to customize your preprocessing stage: https://www.mathworks.com/help/releases/R2021a/images/morphological-dilation-and-erosion.html
After solving the object detection part, you can configure the Kalman filter of each dot by specifying different arguments:
  1. You could set the MotionModel argument based on the whether the dots move with a constant velocity or constant acceleration.
  2. The InitialLocation argument can be set to the centroid of the blob.
  3. Since the centroid locations doesn’t exactly match the dots’ location the InitialEstimateError argument can also be specified for the tracker to accommodate the error.
Details on other arguments of configureKalmanFilter can be seen here:
Based on how often dots eclipse or go out of the frame, you can also adjust the invisibleForTooLong and ageThreshold variables given in the example.
Regards.

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by