Page 1 of 1

Equivalent to OpenCV's cv2.warpPerspective?

Posted: Mon Mar 06, 2017 10:41 pm
by zlite
I'd like to convert an oblique image to one that looks like it was taken from above, which in OpenCV would be done with the cv2.warpPerspective or cv2.perspectiveTransform functions. I can't find anything quite like that in OpenMV, but is there some combination of transforms that would accomplish the same thing?

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Mon Mar 06, 2017 11:42 pm
by kwagyeman
I don't think we have anything like that. Um, what's the use case?

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Tue Mar 07, 2017 1:17 am
by zlite
Driving autonomous cars like this. https://wroscoe.github.io/compound-eye- ... -autopilot

That function turns distorted ground-level camera views into easy-to-parse top level views.

So this
download.png
download.png (67.64 KiB) Viewed 5129 times
turns into this:
download (1).png
download (1).png (147.05 KiB) Viewed 5129 times

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Tue Mar 07, 2017 9:33 am
by kwagyeman
Okay, so, I could implement a function to do this but it's going to kill the frame rate. Not sure if that makes any sense. Seems like it would be smarter to just deal with the mathematics of the lines found that trying to make them parallel. I can guess roughly that the M7 will only be able to achieve about 10 FPS once you apply a perspective fix like that.

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Tue Mar 07, 2017 10:11 am
by zlite
Actually 10 FPS is fine for cars.

The reason to do this is not to make it easier to find the lines, but rather to do this:

"To calculate the steering angle we'll use a perspective transform to simulate a birds eye view from the tip. This way we can calculate the actual angle of the line relative to the car."

There are probably other good ways to do that without a perspective transform, but it does neatly address the problem of lines being both translated (car is closer or further from them) as well as rotated (car is not running parallel to them), which can make the math tricky otherwise.

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Tue Mar 07, 2017 11:10 am
by kwagyeman
I can probably add a general purpose perspective transform function then. Seen this code twice now for QR Code and AprilTags. Can just copy if from there. You can then just supply a sequence of X/Y/Z rotations.

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Tue Mar 07, 2017 12:54 pm
by deshipu
I think it would be *much* faster to first find the line on the image, and *then* apply the perspective transformation to the ends of that line, instead of applying it to each and every pixel in the image.

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Tue Mar 07, 2017 12:55 pm
by kwagyeman
Much, much, faster.

Re: Equivalent to OpenCV's cv2.warpPerspective?

Posted: Mon Mar 13, 2017 11:50 pm
by skylin008
@ kwagyeman Have some example code to be test,Thanks!