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

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
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?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
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?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting with rotation and perspective warp
« Reply #6 on: January 09, 2014, 09:44:39 pm »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting with rotation and perspective warp
« Reply #9 on: January 09, 2014, 10:17:03 pm »
mm, I see, thx