Given an image of my choice, and choose an object in the image, how to move that object to another place in the image? How to stretch and shrink it?
Those problems can be well solved by Affine transformations.Making it more concrete, my job is to rotate an object of my choice 30 degrees counterclockwise, translate by a distance, and scale of 0.5.
Firstly, load an image and show it in a window. Choose a rectangle area as ROI by mouse clicking. Then do transformation for the rectangle area (the object). After transformation, some black areas will appear, flood filling is helpful here for those images that have single background color.
Matrix for affine transformation can be defined as:
scaling 0.5 0 0
0 0.5 0
translation 1 0 distanceX
0 1 distanceY
rotation cos(Pi/6) -sin(Pi/6) 0
sin(Pi/6) cos(Pi/6) 0
Now let me choose the first picture:
Shrink the number "0":
Translation T_x by 245 pixels from original picture:
Now rotation. A little problem for my OpenCV is that I can't set my original point to the bottom left of the image (it's always at the top-left point). But I can deal with this by some transformation .
The relation of two coordinates is: O(x,y) <----> O'(x,H-y)
calculate the new coordinate of A(x',y') in O'(x',y'), we can get the offsets
offsetX=Xo=x', offsetY=Yo=H-y'
Rotate the image in ROI, and then add the offsets, flood-fill blank areas, I can rotate the arrow in the picture by 30 degrees:
------------------------------------------------------------------------------------------------------------------------
The rotation is fine,but floodfill function leaves a black box.
Jiannan Zhang
2.9 in MN
Comment
Comment by Jiannan Zhang on February 10, 2012 at 10:19am Yes! Unity3D will be more powerful in image processing and 3D animation constructing. I will start a project on robotics and vision soon, and AR Drone might be used, I may have chance to try there tools.
Jiannan
Comment by Ben Koo on February 9, 2012 at 10:45pm Dear Jian Nan:
Great to see this interesting post. I wonder if you know of this tool: unity3d. Please go to http://www.unity3D.com You may download the tool, and you could potentially create all these illustrations and matrix manipulation using that interactively.
Ben
Share your knowledge and creativity with the world, protect your work with CC Licenses and discover other creative works and CC activities around the world. For Chinese CC, please go to: (中文版知识共享协议网站请点击) http://cn.creativecommons.org.
Creative Commons licenses provide a flexible range of protections and freedoms for authors, artists, and educators.
Toyhouse.cc is licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License.
© 2012 Created by Toyhouse Administrator.

You need to be a member of Toyhouse to add comments!
Join Toyhouse