Borrar filtros
Borrar filtros

How to detect right triangles from an image and find the three side lengths of each triangle?

4 visualizaciones (últimos 30 días)
  2 comentarios
DGM
DGM el 15 de Jun. de 2024
With noticeable perspective distortion and no spatial calibration information, you'll have a hard time knowing anything. We can't trust that the apparent angles are correct, and we don't know how large anything in the scene is.
We might be able to compensate for the perspective, but we don't have any information to do that either. We might be able to guess that the objects are relatively small based on the background texture, but that's not likely a meaningful estimation.
How large is a distant object which can be occluded by holding up your thumb?
John D'Errico
John D'Errico el 16 de Jun. de 2024
Given only a picture, with no other evidence, technically you can't make any inferences about size or angles.
That is, depending on the point of view, any one of those corners could actually be a right angle. As far as size goes and lengths of the sides, again, that could be a picture of huge triangles the size of of Mt Rushmore, or it could have been taken with a microscope.
Again, this all applies only if the triangles were on a completely flat field. Personally, if I had a choice, I would include a known object in the image. For example, put a coin of known size in the image too, in the same plane as the triangles. Now, since the coin is known to be a circle, you could infer the orientation of the plane the coin lies in, and you should now be able to transform the objects in the image as if they were now in a plane perpendicular to the field of the camera. Having done that, you are now able to do anything. The other virtue of having an object of known size in the image is now you can infer the lengths of the triangle sides.
Lacking that, again, if the background were a perfectly flat field, you would be kind of stuck. But it is not perfectly flat. We can see what are essentially brush strokes in that background, and varous irregularities, cracks, etc. You might be able to make some inferences based on the irregularities in the background, although that would be far more error prone than what you could achieve if you had a known object in the field.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 16 de Jun. de 2024
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
You can use bwboundaries on the segmented/binary image to get the (x,y) coordinates of the triangle perimeters. From there it's trivial to use the max function to find the two points in a boundary that are farthest from each other - in other words the hypoteneuse. Once you have the two endpoints of the hypoteneuse, it's again trivial to use the function for computing point to line distance (attached) to find the corner opposite the hypoteneuse. Once you have all 3 points, you can simple use sqrt to find the lengths of the sides.
%=========================================================================================================================================
% Get the distance from a point (x0, y0) to
% a line defined by two points (x1, y1) and (x2, y2);
% Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
function distance = GetPointLineDistance(x0,y0,x1,y1,x2,y2)
try
% Find the numerator for our point-to-line distance formula.
numerator = abs((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1));
% Find the denominator for our point-to-line distance formula.
denominator = sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2);
% Compute the distance.
distance = numerator ./ denominator;
catch ME
callStackString = GetCallStack(ME);
errorMessage = sprintf('Error in program %s.\nTraceback (most recent at top):\n%s\nError Message:\n%s',...
mfilename, callStackString, ME.message);
WarnUser(errorMessage)
end
return; % from GetPointLineDistance()

Community Treasure Hunt

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

Start Hunting!

Translated by