0

At http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_geometric_transformations/py_geometric_transformations.html I have seen how to geometric transform an image. Depending on the transformation, the resulting image does not fit into a rectangle. How can I crop the image in such a way that I don't have any black background (or in other words, it fits into a rectangle) in such a way that the cropped image is as large as possible? Is there a function for that in openCV?

My question is similar to Rotate image and crop out black borders. Difference is though that I am not just interested in rotated images, but any arbitrary geometric transformation.

Community
  • 1
  • 1
Make42
  • 12,236
  • 24
  • 79
  • 155
  • what do you mean by "in such a way that I don't have any black background (or in other words, it fits into a rectangle)" ? For most geometric transformations, your image will not be rectangle shaped anymore and no cropping will help that. – Soltius Mar 22 '17 at 09:55
  • @Soltius: See my question update. Losing part of the non-black image is ok. I want to get rid of the black background. – Make42 Mar 22 '17 at 09:56
  • 1
    The problem is equivalent to given a quadrilateral fit a rectangle of max size in it. You can do this by comparing the coordinates of four corners of the resultant transformed image. For ex the top corner of rectangle would be(x, y) where `x = max(topleft.x, bottomLeft.x)`, and `y = max(topLeft.y, topRight.y)`. Same You can extrapolate for other corners. – Optimus 1072 Mar 22 '17 at 09:56

0 Answers0