Azzera filtri
Azzera filtri

Tracking based on difference in brightness | Use im2bw for tracking

5 visualizzazioni (ultimi 30 giorni)
I try to track an object in this Video. What is the best method to track the moving object in the lower left half?
I tried Tracking based on interesting points but following this example the object get lost when it makes some turns, in the middle of the video. I think converting the image with im2bw looks good so far, but still at some point of the video it losses the track.
I also tried the Histogram-based Tracking Example. There they use rgb2hsv to convert the image. In my case, I want to use im2bw to track the object which is brighter than the background. My image/video is already without colors.
I use the code from the site for setup and to draw the tracking rectangle around my object. The method initializeObject does not work for the params (tracker, objectBW, objectRegion). The problem is the second parameter objectBW, because im2bw has a different type than rgb2hsv.
videoReader = VideoReader('images.avi');
videoPlayer = vision.VideoPlayer();
shapeInserter = vision.ShapeInserter('BordeColor','Custom','CustomBorderColor',[1 0 0]);
% Create tracker Object
tracker = vision.HistogramBasedTracker;
% Initialize tracker
objectFrame = im2single(readFrame(videoReader));
objectBW = im2bw(objectFrame, 0.6);
%objectHSV = rgb2hsv(objectFrame); --- OLD
% When displaying objectBW you can see the white bright cell in the lower left half of the image.
% I want to track this object
imshow(objectBW)
% Get rectangle around tracking object
figure
imshow(objectFrame)
objectRegion = round(getPosition(imrect));
objectImage = insertShape(objectFrame,'rectangle',objectRegion,'Color','red');
% Show rectangle
figure
imshow(objectImage)
title('Red box shows object region')
% initializeObject(tracker,objectHSV(:,:,1),objectRegion); --- OLD
% initializeObject(tracker,objectBW,objectRegion); --- NEW TRY
% Track Object -- old code from example!
while hasFrame(videoReader)
frame = im2single(readFrame(videoReader));
hsv = rgb2hsv(frame);
bbox = tracker(hsv(:,:,1));
out = shapeInserter(frame,bbox);
videoPlayer(out);
end
% Display line/graph of tracked object in picture
% ...

Risposte (1)

Image Analyst
Image Analyst il 22 Dic 2022
Make sure your objectFrame is gray scale, not RGB.
size(objectFrame)
Other than that I can't tell because I don't have the full code, or the video file.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
  1 Commento
Henning
Henning il 28 Dic 2022
Modificato: Henning il 29 Dic 2022
@Image Analyst I changed my question and added some stuff, to hopefully make it more clear.
Sry for the late reply, you now Christmas :)

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by