Ask Your Question

Revision history [back]

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.

  • Perform a segmentation of the object since the background is quite constant. My guess OTSU thresholding will work quite well on a grayscale image.
  • Then do a findContours and get the contour of the object
  • Apply minAreaRect on the found contour to get a rotatedRect associated to this object
  • Retrieve the angle of the rotatedRect and warp it back with warpAffine