www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: raft on January 09, 2014, 09:23:21 am

Title: blitting with rotation and perspective warp
Post by: raft on January 09, 2014, 09:23:21 am
i want to blit an image with rotation and perspective warp, how can I do that?

OpenCv finds my template in camera image and it also gives me a 2d affine transform (3x3 matrix) to transform the borders of the template (it's a rectangle) to camera space. the white lines in the image reflects transformed template borders.

i want to blit an image to fit that distorted rectangle, how can I do that? is it possible to add such a blitting method to FrameBuffer? or what else can I do? going reverse and put a quad and calculate corner points of the quad based on fov and camera distance may also an option but seems complicated. i also want the result perspectively correct, i.e. there should be no discontinuity accross the diagonal line, i'm not sure quad solution will provide that.

any other suggestions?

(http://s2.postimg.org/5jl5masg9/screenshot_taz.png)
Title: Re: blitting with rotation and perspective warp
Post by: EgonOlsen on January 09, 2014, 08:48:11 pm
You will never get a perspective correct result unless you know the depth of the corners in 3D (i.e. their distance from the camera). If you have these, you can simply take the points in 2D, use Interact2D to project them back into 3D and then use a vertex controller to make a quad with these coordinates. But it think that the problem is, that you don't have the depth...i'm not sure how to solve this. Do you have any 3d information or just 2d?
Title: Re: blitting with rotation and perspective warp
Post by: raft on January 09, 2014, 09:34:09 pm
indeed I have. OpenCV takes camera parameters (fov etc), object space 3d point coordinates and projection of that points onto camera as input and calculates 3d transform of object in camera space, both translation and rotation. pretty amazing :) so I know the rotation and translation of the template border in the image. I successfully placed a jPCT object onto that.

i've never tried but docs say, it can also apply the previously mentioned 2d transform to images. so I was hoping openGL can also do that and blitting is an easier solution to place planar things.
Title: Re: blitting with rotation and perspective warp
Post by: Thomas. on January 09, 2014, 09:39:47 pm
You can use overlay...? Are you using any library or can you provide sources?
Title: Re: blitting with rotation and perspective warp
Post by: raft on January 09, 2014, 09:42:51 pm
You can use overlay...? Are you using any library or can you provide sources?
how? overlay does not have a rotation or perspective warp
Title: Re: blitting with rotation and perspective warp
Post by: EgonOlsen on January 09, 2014, 09:43:14 pm
You can use overlay...?
You can rotate an overlay, but you can't tilt it. The only way is to use an actual 3d object. You won't get a perspective correct rendering otherwise.
Title: Re: blitting with rotation and perspective warp
Post by: EgonOlsen on January 09, 2014, 09:44:39 pm
overlay does not have a rotation...
It has: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/Overlay.html#setRotation(float) (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/Overlay.html#setRotation(float))

...but that alone won't help here.
Title: Re: blitting with rotation and perspective warp
Post by: raft on January 09, 2014, 09:48:35 pm
right, saw it after you said it has.

so there is no way to apply an affine transform to a quad with open gl except using 3d?
Title: Re: blitting with rotation and perspective warp
Post by: EgonOlsen on January 09, 2014, 10:15:21 pm
An affine transformation won't give you a perspective correct result. It would turn out like texture mapping on the Playstation 1.
Title: Re: blitting with rotation and perspective warp
Post by: raft on January 09, 2014, 10:17:03 pm
mm, I see, thx