### Author Topic: blitting with rotation and perspective warp  (Read 1946 times)

#### raft

• Posts: 1974
##### blitting with rotation and perspective warp
« 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?

#### EgonOlsen

• Posts: 11777
##### Re: blitting with rotation and perspective warp
« Reply #1 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?

#### raft

• Posts: 1974
##### Re: blitting with rotation and perspective warp
« Reply #2 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.

#### Thomas.

• double
• Posts: 833
##### Re: blitting with rotation and perspective warp
« Reply #3 on: January 09, 2014, 09:39:47 pm »
You can use overlay...? Are you using any library or can you provide sources?

#### raft

• Posts: 1974
##### Re: blitting with rotation and perspective warp
« Reply #4 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

#### EgonOlsen

• Posts: 11777
##### Re: blitting with rotation and perspective warp
« Reply #5 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.

#### EgonOlsen

• Posts: 11777
##### Re: blitting with rotation and perspective warp
« Reply #6 on: January 09, 2014, 09:44:39 pm »

#### raft

• Posts: 1974
##### Re: blitting with rotation and perspective warp
« Reply #7 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?

#### EgonOlsen

• Posts: 11777
##### Re: blitting with rotation and perspective warp
« Reply #8 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.