Finding centroid of a specific object (running dog) in an image instead of centroids for many objects in the image

2 views (last 30 days)
dog = imread('1.jpg');
Ibw = im2bw(dog);
Ibw = imfill(Ibw,'holes');
Ilabel = bwlabel(Ibw);
stat = regionprops(Ilabel,'centroid');
imshow(dog); hold on;
for x = 1: numel(stat)
plot(stat(x).Centroid(1),stat(x).Centroid(2),'ro');end
As you can see from the above and the title of the question, I am currently working on establishing my ground truth for my tracking model but determing the position (in x and y coordinates) of my dog. To estimate it I would like to use the centroid of my desired object of tracking (i.e dog) and so I would like to find the centroid of the object in image (a frame of the video), but the as you can see I am getting hundreds of centroids and non on the actual dog. How can I specify a specific region of my image (using regionprops function) to find centroid of my desired object. Thanks

Accepted Answer

Image Analyst
Image Analyst on 27 Nov 2022
See my attached demo where I track a green Sharpie marker in a video.

More Answers (1)

Image Analyst
Image Analyst on 25 Nov 2022
That's just because you're doing an intensity threshold. You'd need to do some more sophisticated segmentation. Perhaps you need to subtract old frames from the current frame, as long as your camera is not moving. Or else define something that uniquely describes the dog.
  11 Comments
Nizar Sharkas
Nizar Sharkas on 27 Nov 2022
I am still working on it. I don't have much computer vision or image processing experience so I am still trying to dissect your demo code, and so far I am not able to get a blob for the dog, especially in the early frames where his color intensity is similar in brightness to the grass around him
Walter Roberson
Walter Roberson on 27 Nov 2022
You have a moving camera in a situation where you have no template image. You want to be able to detect an object that will be moving from the very first frame, before it has even moved.
In order to do that, you need a considerable amount of scene intelligence, such as numerous pictures of playing fields marked up according to whether the various objects in view are movable or immovable, so that when you later present the first image of the video the program can analyze the blobs to figure out which are stationary objects, marking the ones that are not stationary.
But even if you do that, you should expect the algorithm to fail. For example, much of the time, an orange pylon at the edge of the field would be immobile, just marking the boundaries, but it is possible for the pylon to be blown by the wind or to be mounted on something that is moving. Suppose it were a pylon that was moving in the video, which would be something obvious if you compared a few frames... but you expect your code to be able to pick it out on the first frame before you even know whether it is going to be stationary or not.
By expecting it to be able to pick out the dog on the first frame before it has a chance to move, you are effectively asking for a program with the intelligence to detect things that "don't belong" on the field.
Realistic video tracking programs without template images or gigabytes of scene data to analyze from, do not work that way. Instead, they use the first image as a template and look at the second frame relative to the first frame. 3 frames are usually enough to determine moving objects. The program might then go backwards and be able to mark where the moving object was in previous frames -- but the program does not already know from just the first frame which portion will be the moving object.

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!