Camera matching script, need some details

General questions and troubleshooting SOFTIMAGE©
Post Reply
pgeissler
Posts: 7
Joined: 05 Jul 2013, 14:45

Camera matching script, need some details

Post by pgeissler » 05 Jul 2013, 17:09

Hi,

i'm working on a camera matching JS script, to get the correct camera FOV from a photography and place some 3D on top of it. I'm using some mathematics, trigonometry and all, people will just have to place some curves along the vanishing lines of the pictures and the script will give the correct FOV. but to achieve my goal i think need to get the ratio of the photography used as a reference. However i can't tell how to get the width (xres) and the height (yres) of the loaded image clip. It's displayed in the image source property editor but as people will use their own pictures, i need to get these informations dynamically.

Here is a part of my code:

Code: Select all

var ClipImage;
var oFileBrowser = oUIToolkit.FileBrowser ;
oFileBrowser.DialogTitle = "Select a file" ;
oFileBrowser.InitialDirectory = "c:" ;
oFileBrowser.Filter = "All Files (*.*)|*.*||" ;
oFileBrowser.ShowOpen() ; 
if ( oFileBrowser.FilePathName != "" )
{
SetValue("preferences.Interaction.autoinspect", false, null);
ClipImage=CreateImageClip2(oFileBrowser.FilePathName, null, null);
SetValue("preferences.Interaction.autoinspect", true, null);
}
SetValue(CurrentCamera+".rotoscope.imagename", ""+ClipImage, null);
i can dynamically load the picture and use it as a rotoscopy picture but i haven't found how to get the ratio of the source file.

I'm not very skilled with softimage 2014. And sorry for the poor english, i'm having a hard time trying to explain my problem as clearly as possible.

Thanks a lot for your help.

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Camera matching script, need some details

Post by rray » 05 Jul 2013, 17:16

ClipImage.Source.Parameters("XRes").Value

should work

(according to this)
softimage resources section updated Jan 5th 2024

pgeissler
Posts: 7
Joined: 05 Jul 2013, 14:45

Re: Camera matching script, need some details

Post by pgeissler » 05 Jul 2013, 17:40

Thanks for your answer. It's strange because

LogMessage (ClipImage.Source.Parameters("XRes").Value);

return an error ("'ClipImage.Source' is null") even if ClipImage is global, but i've manage to get the value by using the following:

var Sourcename=GetValue( ClipImage+ ".Source.Name" );
LogMessage(GetValue("Sources." +Sourcename + ".XRes"));

Based on your solution.

This script is quite complicated. I hope the picture ratio will be usefull to get the camera FOV, according to how the rotoscopy work in softimage 2014..

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Camera matching script, need some details

Post by rray » 05 Jul 2013, 18:17

Quite a math challenge. I know that if the lines become more parallel, the object is further away, but how this relates to the FOV, I wouldn't know where to begin calculating.
softimage resources section updated Jan 5th 2024

pgeissler
Posts: 7
Joined: 05 Jul 2013, 14:45

Re: Camera matching script, need some details

Post by pgeissler » 08 Jul 2013, 11:58

It's something about triangle, orthocenter and a bit of trigonometry... The algorithm is already done even if i'm not able to understand it anymore, the problem is the integration with xsi now. As i'm not a 3D artist at all, i don't know the soft very well.

User avatar
Draise
Posts: 891
Joined: 09 Oct 2012, 20:48
Skype: ondraise
Location: Colombia

Re: Camera matching script, need some details

Post by Draise » 10 Jul 2013, 19:59

I'm still getting my hands wet with SI, but if you need someone to test your concepts out in the software in practice, I'm more than glad to help you out if I can! :D

pgeissler
Posts: 7
Joined: 05 Jul 2013, 14:45

Re: Camera matching script, need some details

Post by pgeissler » 12 Jul 2013, 15:58

That would be great! i hope i will soon getting this script working. However, it seem quite hard. I continue to get some weird issues with the field of view.

the algorithm i used is already implemented on another program (made with Flash and Stage3D) i made for a company some month ago. The purpose of this program was to help the user to determinate the 3D camera field of view based on a background picture/photography with the same method (vanishing lines & trigonometry) and allow him to place a 3D object anywhere on the screen, with a matching perspective (it's exactly what i try to do in softimage with my script). This program is always giving me good results, for every picture/screenshots i gave to him, the 3D object can be put anywhere with correct deformation, like it was a part of the background photography.

The only difference is that the FOV range of this program is from 0° (orthographic) to 90°, where the FOV range of softimage is from 0° to 180°. But when i export screenshots/renders from softimage to this program, the results aren't even proportionals.

When i set the FOV to 20° in softimage, take a screenshot of the active area of the viewport and put it on the program, it return a FOV of 18° (on a range of 0~90).
For 40° in SI the program return 36°
When the FOV is 70° in SI the program return 54°
When the FOV is 90° in SI the program return 63°
When the FOV is 120° in SI the program return 73°

And for every values the program calculate, the perspective deformation and the FOV of the camera is correct. And when i use the script to calculate the perspective of the screenshots from SI, i have the same problem, the corresponding values aren't linear at all, i can't just multiply the result by a constant to get a correct value every time.

So i'm completely lost. The camera system of SI seem far more complicated than i though. I can't understand why the values of FOV between SI and my own program aren't proportional. I need to get deeper into this to understand how it work. And as i will be in vacancies for a month, i may have some difficulties to work on this..

Thanks for all your help. I hope you've understand something in all what i said.


tl;dr nothing work because the camera system of SI is a complete wizardry



Edit: i made a curve based on these values between a FOV from softimage and a FOV calculated by the stage3D program:
Image

As you can see, it's not linear. it look like a sine curve, or a square root curve. Is there a rule in optic or in photography science that can explain this evolution?

grahamef
Posts: 281
Joined: 23 Jun 2009, 21:01

Re: Camera matching script, need some details

Post by grahamef » 12 Jul 2013, 18:04

I just made a quick test and a FOV of 90 degrees seems correct in Softimage.

Are you sure you are rendering square pixels?
Attachments
fov90.png
fov90.png (4.92 KiB) Viewed 1762 times

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Camera matching script, need some details

Post by rray » 12 Jul 2013, 18:57

Tested with a circle with 36 subdivisions (each at 10°). Did put the camera at (0,0,0).
At FOV=20°, the 10° and -10° points were exactly at the top and bottom of the screen... At 40° the 20°/-20° points and so on.. so like from how Grahame tested, the FOV setting seems exact.

Softimage default FOV is vertical, maybe this is an issue?
softimage resources section updated Jan 5th 2024

pgeissler
Posts: 7
Joined: 05 Jul 2013, 14:45

Re: Camera matching script, need some details

Post by pgeissler » 13 Aug 2013, 10:34

Hi,

i just gotten back off vacation, without PC most of the days nor XSI..

Thanks for your tests, as you said, the FOV setting seem exact. So i really, really don't know why it give non-linear results when i use the stage3D application to re-calculate the FOV.

I may check the code of this application but the algorithm is supposed to be generic, it's just pure FOV determination from some 2D points (3D points on the same axis-aligned plane on the XSI version) on top of a photography, it's API-independant..

Have a nice day!

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Camera matching script, need some details

Post by myara » 14 Aug 2013, 11:37

Be sure your FOVs are both vertical or both horizontal because FOV vertical isn't linearly proportional to FOV horizontal.
Softimage default FOV is Horizontal.

I had to convert all my cameras to FOV vertical in a previous project because the game engine didn't supported FOV horizontal, and they just forgot to tell me and all the animators had already played with the cameras.

I wrote this function and applied to all the camera FOV horizontal plotted keys.

Code: Select all

//JScript
// fovX = fov horizontal angle
// aspect = camera aspect ratio
function fov_XtoY(fovX, aspect){
	rfovX = XSIMath.DegreesToRadians ( fovX )
	rfovY = 2 * Math.atan(Math.tan(rfovX / 2) / aspect)
	return XSIMath.RadiansToDegrees(rfovY)
}
M.Yara
Character Modeler | Softimage Generalist (sort of)

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests