2
$\begingroup$

I want to generate the "projection" image described as bellow. The left picture is the original picture and the right image is what I want. But, I have no idea about how to generate the right image. I know that OpenCV can only generate affine effect, so I know that only OpenGL or Matlab can generate this effect. However, I have no experience about OpenGL combined with Visual C++, so I don't know how to generate the right picture by OpenGL. Besides, according to other webside, I know that function "affine3d" in Matlab can achieve this effect, but my Matlab doesn't provide this function. Is anyone who can help me? Please. Thank you.

enter image description here

$\endgroup$
0
$\begingroup$

If you want to start learning OpenGL, see Part 1 of the answer. If you just want to get an image like the one you presented (and image editor transformation will work for you) and don't want unnecessary complications, see Part 2.

You indeed can generate such a picture with OpenGL, but it's a bit too big for the answer here. Here's the link to some (quite old) OpenGL tutorials and the second pack, all with the source code, and there you can learn and understand how to create such a program, or if needed, just take the sources and modify them slightly for your needs.

In the first pack linked above you can learn how to set up a window and render basic primitives, also how to apply transformations etc. The second pack will teach you how to apply textures (lessons 06-07, others are on advanced topics).

Keep in mind though that those lessons are outdated, and they use the deprecated FFP (fixed functionality pipeline) interface of the OpenGL, but this interface is better suited for the beginners in my opinion. Modern OpenGL applications use the programmable pipeline, where all transformation/projection matrices are filled up manually and transferred to the shaders, immediate primitive mode is unavailable (you can only send primitive data in batches), etc; this may be confusing initially.

But if you just need a picture like that, and do not want to learn how to use OpenGL, then you might want to get some image editor and use something similar to this perspective adjustment. Seems like this freeware editor also has similar adjustments available.

$\endgroup$
  • $\begingroup$ Pfff. The StackExchange framework won't allow me to post more than 2 links, LOL. So hence here are the links that are missing in the second part: "this perspective adjustment" and "this freeware editor" $\endgroup$ – DSPguy Jan 14 '15 at 23:32
  • $\begingroup$ OK, so StackExchange also won't allow me to comment the other answers apparently. That is NOT ok, since how do I ever get to the moment when I can, if I cannot do anything. $\endgroup$ – DSPguy Jan 14 '15 at 23:35
  • $\begingroup$ So to comment on the @tbirdal answer, he didn't provide the most important data in his comment - how to construct this pseudo-camera matrix (which is usually called the projection matrix). Here is a good article about OpenGL-like perspective matrix setup. $\endgroup$ – DSPguy Jan 14 '15 at 23:37
  • $\begingroup$ It is very exciting for me when seeing your reply, I will spend some time looking the detail about part one. If I have any question, I will post it on the following comment. Thank you very much. $\endgroup$ – Kuo Jan 15 '15 at 12:54
0
$\begingroup$

You would not need OpenGL for such perspective transforms.

First create a 3D cylinder with Coca-Cola texture on it. (This is found even in 3D warehouse).

Then, start by creating a pseudo-camera matrix $\mathbf{K}$ and then generate arbitrary rotation angles with desired range for each axis. Then compose the final rotation by $\mathbf{R}=\mathbf{R}_x\mathbf{R}_y\mathbf{R}_z$. Also synthesize a translation $\mathbf{t}$. Your projection matrix then reads $\mathbf{P}=\mathbf{K}[\mathbf{R} | \mathbf{t}]$. Project your 3D points with this matrix and you will get the warping effect.

$\endgroup$
0
$\begingroup$

If you have a recent version of MATLAB with the Image Processing Toolbox, then you can use the imwarp function with the affine2d or projective2d transformation object.

If you have an older version, which does not have imwarp, then you can use imtransform, and you can create the transformation object using maketform.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.