Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def draw_MAR(path, flipped=False):
- img = io.imread(path, as_grey=True)
- _, img = cv2.threshold(img, 127, 255, 0)
- im2, contours, hierarchy = cv2.findContours(img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
- cont_len = [len(x) for x in contours]
- index = cont_len.index(max(cont_len))
- cnt = contours[index]
- rect = cv2.minAreaRect(cnt)
- box = cv2.boxPoints(rect)
- box = np.int0(box)
- width = int(rect[1][0])
- height = int(rect[1][1])
- src_pts = box.astype("float32")
- dst_pts = np.array([[0, height - 1],
- [0, 0],
- [width - 1, 0],
- [width - 1, height - 1]], dtype="float32")
- M = cv2.getPerspectiveTransform(src_pts, dst_pts)
- warped = cv2.warpPerspective(img, M, (width, height))
- img = warped
- # io.imsave("rotated_" + path, img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement