Equivalent to OpenCV's cv2.warpPerspective?

Discussion related to "under the hood" OpenMV topics.
zlite
Posts: 73
Joined: Sun Feb 05, 2017 9:26 pm

Equivalent to OpenCV's cv2.warpPerspective?

Postby zlite » Mon Mar 06, 2017 10:41 pm

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?
User avatar
kwagyeman
Posts: 4658
Joined: Sun May 24, 2015 2:10 pm

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby kwagyeman » Mon Mar 06, 2017 11:42 pm

I don't think we have anything like that. Um, what's the use case?
Nyamekye,
zlite
Posts: 73
Joined: Sun Feb 05, 2017 9:26 pm

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby zlite » Tue Mar 07, 2017 1:17 am

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 5105 times
turns into this:
download (1).png
download (1).png (147.05 KiB) Viewed 5105 times
User avatar
kwagyeman
Posts: 4658
Joined: Sun May 24, 2015 2:10 pm

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby kwagyeman » Tue Mar 07, 2017 9:33 am

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.
Nyamekye,
zlite
Posts: 73
Joined: Sun Feb 05, 2017 9:26 pm

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby zlite » Tue Mar 07, 2017 10:11 am

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.
User avatar
kwagyeman
Posts: 4658
Joined: Sun May 24, 2015 2:10 pm

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby kwagyeman » Tue Mar 07, 2017 11:10 am

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.
Nyamekye,
User avatar
deshipu
Posts: 74
Joined: Sat Jan 09, 2016 5:36 am
Location: Zürich
Contact:

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby deshipu » Tue Mar 07, 2017 12:54 pm

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.
User avatar
kwagyeman
Posts: 4658
Joined: Sun May 24, 2015 2:10 pm

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby kwagyeman » Tue Mar 07, 2017 12:55 pm

Much, much, faster.
Nyamekye,
skylin008
Posts: 65
Joined: Mon Mar 13, 2017 10:18 pm

Re: Equivalent to OpenCV's cv2.warpPerspective?

Postby skylin008 » Mon Mar 13, 2017 11:50 pm

@ kwagyeman Have some example code to be test,Thanks!

Return to “Technical Discussion”

Who is online

Users browsing this forum: gerokatseros and 3 guests