Answer the question
In order to leave comments, you need to log in
How to get the aspect ratio of a distorted rectangle?
Hello!
I have a photo of a rectangular object taken at a certain angle, i.e. it is distorted. I need to crop the photo so that the photo contains only a rectangle, and already aligned. I did it with a matrix, everything works fine, but I myself set the final coordinates where it will "squeeze". How can I get the actual proportions of a rectangle?
I write for Android. corners are the coordinates of the corners of the distorted rectangle in the photo. w & h - the dimensions to which I adjust the rectangle, it is them that I need to calculate:
float[] dest = new float[]{0, 0, w, 0, w, h, 0, h};
float[] source = new float[]{corners.get(0).getX(), corners.get(0).getY(), corners.get(1).getX(), corners.get(1).getY(), corners.get(2).getX(), corners.get(2).getY(), corners.get(3).getX(), corners.get(3).getY()};
matrix.setPolyToPoly(source, 0, dest, 0, 4);
Answer the question
In order to leave comments, you need to log in
I won't say the formula - I don't know.
With OpenCV try getPerspectiveTransform
stackoverflow.com/questions/8235288/perspective-co...
Automatic perspective correction for quadrilateral...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question