1 | initial version |
The already proposed solution will only work when having objects with circles. If not this will fail dramatically. What I suggest is, given these very simple conditions.
OTSU thresholding
will work quite well on a grayscale image.findContours
and get the contour of the objectminAreaRect
on the found contour to get a rotatedRect
associated to this objectrotatedRect
and warp it back with warpAffine