0

I would like to use cv::RotatedRect in Python. However I am unable to find its namespace. Help would be greatly appreciated!

EDIT:

I need this to implement essentially this.

packoman
  • 1,230
  • 1
  • 16
  • 36
  • 1
    This might be useful https://stackoverflow.com/questions/18207181/opencv-python-draw-minarearect-rotatedrect-not-implemented – Aidenhjj Apr 24 '19 at 08:03

1 Answers1

0

compute rotated img's size by yourself

def rotate(img, degree):
    h, w = img.shape[:2]
    center = (w // 2, h // 2)

    dst_h = int(w * math.fabs(math.sin(math.radians(degree))) + h * math.fabs(math.cos(math.radians(degree))))
    dst_w = int(h * math.fabs(math.sin(math.radians(degree))) + w * math.fabs(math.cos(math.radians(degree))))

    matrix = cv2.getRotationMatrix2D(center, degree, 1)
    matrix[0, 2] += dst_w // 2 - center[0]
    matrix[1, 2] += dst_h // 2 - center[1]
    dst_img = cv2.warpAffine(img, matrix, (dst_w, dst_h), borderValue=(255, 255, 255))
    return dst_img

zhujian
  • 31
  • 2
  • I guess OP wants to use the function from the package? Or maybe you can explain why this would be better. Code followed with a good explanation are more useful to the community :) – StupidWolf Aug 05 '20 at 12:44
  • emmmm, I misunderstood the title. by the way, there' s no python's implement for cv::RotatedRect in OpenCV – zhujian Aug 06 '20 at 14:03