Ask Your Question
0

Apply getPerspectiveTransform and warpPerspective for bird-eye view (Python).

asked 2020-07-27 06:58:11 -0600

o.k gravatar image

updated 2020-07-27 07:21:02 -0600

Hi, I'm following some tutorials to change an image of a golf green with balls to bird-eye view to measure distances in a later step.

Now when I apply the transformation to an image with some text on paper it seems to work, but when applied to the outdoor image the results are not as expected.

Here an example with the outdoor image coords and dimensions:

# targeted rectangle on original image which needs to be transformed
tl = [689, 892]
tr = [2518, 892]
br = [2518, 2071]
bl = [689, 2071]

corner_points_array = np.float32([tl,tr,br,bl])

# original image dimensions
width = 4128
height = 2322

# Create an array with the parameters (the dimensions) required to build the matrix
imgTl = [0,0]
imgTr = [width,0]
imgBr = [width,height]
imgBl = [0,height]
img_params = np.float32([imgTl,imgTr,imgBr,imgBl])

# Compute and return the transformation matrix
matrix = cv2.getPerspectiveTransform(corner_points_array,img_params)
img_transformed = cv2.warpPerspective(image,matrix,(width,height))

And here are my results for the golf image:

 input

image description

output

image description

As you can see I don't get a nice bird-eye view.


This is the result I get with text and paper using the same script just with different coords and dimensions:

 Input

image description

output

image description

So what am I doing wrong with the first golf example? Any help would be greatly appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-07-27 08:14:33 -0600

kbarni gravatar image

WarpPerpective will transform a rectangle seen in perspective (like a trapeziod) into a real rectangle.

image description

For it to work, you have to define correctly the corners.

However in the golf image you map a rectangle onto a rectangle, so it won't deform it.

Take care: WarpPerspective works correctly only on planar rectangles. However the golf balls are not planar. You might get elongated golf balls, and determining correctly the real position won't be easy.

edit flag offensive delete link more

Comments

Hey, thx for your answer, I think I understand. But how do I know where to put my trapezoid corner points in the golf example in order to get a correct top down view?

o.k gravatar imageo.k ( 2020-07-27 09:18:35 -0600 )edit
1

You'll need some markers for calibration. Either add some colored points to the field that you can use for calibration of every image, or use a fixed camera, do the calibration once, then remove the points and use the same calibration data.

If there would be some specific features on the ground, you could use a SIFT-based matching with an aerial image, but on a uniform background like the lawn it's impossible to get manually the correct perspective points.

kbarni gravatar imagekbarni ( 2020-07-27 09:27:11 -0600 )edit

With colored points you mean for example 4 physical red balls forming a rectangle lying on the lawn for each image (perfect rectangle?)? Then in each image I take those 4 balls as my corner coords? Sorry for all the questions but I started with computer vision just a week ago. I'm trying to build an application, which should transform each "golf" image taken to bird-eye view. Images will just be taken by the users mobile phone and won't be fixed. Isn't there any solution without any extra calibration points (Just the image as is)? Your help is much appreciated.

o.k gravatar imageo.k ( 2020-07-27 09:41:28 -0600 )edit
1

Yes, the best solution would be to use 4 visible and fixed red balls or points. I also like to use ARUCO markers for calibration (in other kind of applications) - they are very robust.

The other solution would be to use automatically detected keypoints (see this tutorial), but on that lawn it would be difficult to get any kind of robust keypoint.

kbarni gravatar imagekbarni ( 2020-07-27 09:59:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-07-27 06:57:04 -0600

Seen: 9,294 times

Last updated: Jul 27 '20