Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# get rotated rect of contour and split into components
center, size, angle = cv2.minAreaRect(prkgViolationContour.contour)
# not sure why this is needed, see
if angle < -45.0:
angle += 90.0
width, height = size[0], size[1]
size = (height, width)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
# rotate the entire image around the center of the parking cell by the
# angle of the rotated rect
# codereview: not sure why it was necessary to swap width and height here,
# probably related to the fact that we did angle += 90 earlier
imgWidth, imgHeight = (img.shape[0], img.shape[1])
rotated = cv2.warpAffine(img, M, (imgHeight, imgWidth), flags=cv2.INTER_CUBIC)
# extract the rect after rotation has been done
sizeInt = (np.int0(size[0]), np.int0(size[1]))
uprightRect = cv2.getRectSubPix(rotated, sizeInt, center)
return uprightRect
You can’t perform that action at this time.