Webcam colored object tracking, how to leave a lasting path from centroid of an object

4 ビュー (過去 30 日間)
Ted
Ted 2022 年 12 月 6 日
回答済み: Image Analyst 2023 年 2 月 23 日
So I have already have a code that tracks two object's centroids/borders/distances, and I would like to further add to this to track the position of the objects and leave a lasting path of the trail of the object's centroids.
Most examples I have examined only use this for an imported video, so if anyone knows any resources that use a live webcam video for this task would be very helpful.
Here is the section of my code for annotate the image with aforementioned plots, just wondering how I need to go about creating this trail that will stay on the output figure
imshow(RGB);
imshow(redYellowOverlay);
hold on;
plot(rjMean,riMean, 'g-x', 'LineWidth',5)
plot(yjMean,yiMean, 'g-x', 'LineWidth',5)
plot([rjMean,yjMean],[riMean,yiMean],'b','LineWidth',2);
RGB is the snapshot taken from the webcam, redYellowOverlay is the border code, ri/rj/yi/yj means are the centroid coordinates and all plot() lines are plotting of centroids/distances onto the figure

回答 (2 件)

Sourabh
Sourabh 2023 年 2 月 23 日
One workaround which I can think of for your problem is storing the previous centroid positions for each object and then plotting a line connecting them to the current centroid position on each frame.
To use a live webcam video, you can read frames from the webcam using the snapshot function from the Image Acquisition Toolbox.
Alternatively, you can use the snapshot method of a webcam object from the Support Package for USB Webcams.
You might find this example relevant for your use case:
Hope this helps!

Image Analyst
Image Analyst 2023 年 2 月 23 日
You need to plot the whole vector, from time=0, rather than just the last point.
My attached code doesn't do that but it might be useful for people learning how to track a moving colored object in a video.

カテゴリ

Help Center および File ExchangeMATLAB Support Package for IP Cameras についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by