Computing orientation of a square and displaying an object with the same orientation
I wrote an application which detects a square within an image. To give you a good understanding of how such an image containing such a square, in this case a marker, could look like:
What I get, after the detection, are the coordinates of the four corners of my marker. Now I don't know how to display an object on my marker. The object should have the same rotation/angle/direction as the marker.
Are there any papers on how to achieve that, any algorithms that I can use that proofed to be pretty solid/working?
It doesn't need to be a working solution, it could be a simple description on how开发者_如何学运维 to achieve that or something similar. If you point me at a library or something, it should work under linux, windows is not needed but would be great in case I need to port the application at some point. I already looked at the ARToolkit but they you camera parameter files and more complex matrices while I only got the four corner points and a single image instead of a whole video / camera stream.
I believe you can use OpenCV's cvGetPerspectiveTransform
to find the transform that can warp a square to the marker's corners, and then cvWarpPerspective
to warp the image.
It's a square. It's supposed to lye in a plane that has normal and we need to find it because it's the way we should place our object. We can suppose that all y cooridnates are 0 and now we are dealing with aspect problem. Maybe we could start by mapping it into 0-1 range. Most left point gets 0 on x, most right 1, same will be on z - nearest get's 0 and farest 1. we can determine this by checking length of diagonals. shorter one connects front and back point and next the other 2. so we get something like
x z
left: 0 ?
right: 1 ?
front: ? 0
back: ? 1
I think these ? could be computed by aspect of sides. Using square simplifies problem. If 2 lines connecting front-right and front-left are same, z values of left and right are 0.5 . Well and this way you could get all 3 dimensions and using vector cross product compute normal. You could then take your models having y axis as height, compute matrix used to rotate 0,1,0 vector into normal you get, then draw position 2D image and scale it properly. Well I don't know if I helped you maybe it's not the way it even works but I hope I wrote something that can be useful.
精彩评论