Untitled
unknown
python
a year ago
902 B
10
Indexable
def warp_image(image, src_points, dst_size):
dst_points = np.array([[0, 0], [dst_size[0] - 1, 0], [dst_size[0] - 1, dst_size[1] - 1], [0, dst_size[1] - 1]], dtype=np.float32)
M = cv2.getPerspectiveTransform(src_points, dst_points)
warped_image = cv2.warpPerspective(image, M, dst_size, flags=cv2.INTER_CUBIC)
return warped_image
def find_corners(points):
# Sort points based on their x-coordinates
points.sort(key=lambda p: p[0])
# Split the sorted points into two groups: leftmost and rightmost
leftmost = points[:2]
rightmost = points[2:]
# Sort the leftmost and rightmost points based on their y-coordinates
leftmost.sort(key=lambda p: p[1])
rightmost.sort(key=lambda p: p[1])
# Return the corners in the order: top-left, top-right, bottom-right, bottom-left
return [leftmost[0], rightmost[0], rightmost[1], leftmost[1]]Editor is loading...
Leave a Comment