Image processing of moving marble

조회 수: 5 (최근 30일)
ZENONAS ZENIOU
ZENONAS ZENIOU 2016년 7월 6일
답변: Image Analyst 2016년 7월 7일
Hello. I need to write a code for a project which is about a ball that is passing through a circular shape. Why i need basically is to track the balls and showing the path that they followed and also finding the location where the balls exiting the circular shape. Thanks a lot. Any help will be highly appreciated.

답변 (1개)

Image Analyst
Image Analyst 2016년 7월 7일
For each snapshot, find the binary image of the ball, by thresholding or color segmentation or optical flow or whatever method you want. Then use bwboundaries() to get the outline of the ball.
binaryImage = bwareafilt(binaryImage, 1); % Take only one blob
boundaries = bwboundaries(binaryImage);
thisBoundary = boundaries{1};
boundaryX = thisBoundary (:,2);
boundaryY = thisBoundary (:,1);
% Put "hold on" and plot the boundaries over the image.
hold on;
plot(boundaryX, boundaryY, 'r-');
Now you should know the center and radius of your large circle. First of all plot it. Then see if any of the boundary points is farther from the center than your radius.
distances = sqrt((boundaryX - centerX).^2 + (boundaryY - centerY) .^ 2);
if max(distances) > bigCircleRadius
% Ball has left the circle
else
% Ball is still completely contained in the big circle.
end
If any distance is greater than the radius, then at least some part of the ball has left the circle. If you need to see how to get the boundary coordinates, see my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Community Treasure Hunt

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

Start Hunting!

Translated by