def get_warped_image_from_corners(image, corners):
"""
Returns unwarped image of goal, using corners of goal and the original
source image.
Parameters:
:param: `image` - the original source image with the goal in it
:param: `corners` - a numpy array of the corner pixels of the goal
"""
orig_image = numpy.copy(image)
center = get_center(corners)
corners = sort_corners(corners, center)
height_right = int(math.sqrt((corners[1][0][0] - corners[2][0][0]) ** 2 +
(corners[1][0][1] - corners[2][0][1]) ** 2))
height_left = int(math.sqrt((corners[0][0][0] - corners[3][0][0]) ** 2 +
(corners[0][0][1] - corners[3][0][1]) ** 2))
height = int((height_left + height_right) / 2)
width = int(height * (300 / 210))
quad = numpy.zeros((width, height))
quad_pts = numpy.array([[[0, 0]], [[width, 0]],
[[width, height]], [[0, height]]], numpy.float32)
new_image_to_process = numpy.array(image, numpy.float32)
quad_pts = cv2.getPerspectiveTransform(corners, quad_pts)
warped_image = cv2.warpPerspective(new_image_to_process, quad_pts,
(width, height))
return warped_image
# def get_distance_to_goal(orig_image, warped_image):
# angle_between_sides = (len(warped_image[0]) / len(orig_image[0])) * FOV_OF_CAMERA
# print(math.degrees(angle_between_sides))
# return ((WIDTH_OF_GOAL_IN_METERS / 2) / math.sin(angle_between_sides / 2)) * math.sin((math.pi + angle_between_sides) / 2)
vision_processing.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录