Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focal Length #275

Open
Bilel12 opened this issue Aug 7, 2019 · 7 comments
Open

Focal Length #275

Bilel12 opened this issue Aug 7, 2019 · 7 comments

Comments

@Bilel12
Copy link

Bilel12 commented Aug 7, 2019

Hi,

Please, how can I change the focal length of the camera and the field of view?

Thanks in advance.

@roozbehm
Copy link
Contributor

roozbehm commented Aug 7, 2019

You can specify the fieldOfView:
controller.step(dict(action='Initialize', gridSize=0.25, fieldOfView=90))

@winthos
Copy link
Collaborator

winthos commented Aug 7, 2019

The focal length is not exposed to the python controller, and it is also not hooked up by default in the Unity side of the framework. The focal length value of the camera can be used to calculate frustrum and field of view, but that would require editing camera settings in the Unity Editor. You would need to edit the camera of the agent in the Unity Editor by toggling the usePhysicalProperties bool on the camera component. More information on that can be found here: https://docs.unity3d.com/ScriptReference/Camera-usePhysicalProperties.html

You can adjust field of view using the action listed above by @roozbehm

@Bilel12
Copy link
Author

Bilel12 commented Aug 7, 2019

thank you @roozbehm @winthos for the helping, so I need to modify the camera parameters using Unity to change the focal length.

So now we can change FOV, but please what do you think if I change the field of view to get the desired focal length without modification with Unity using one of the following field of view formula? is that work? :

  1. FOV = 2 * arctan(y1 / f) ......... here I need the y1: is the half-size of your sensor.
    
  2.   FOV = 2*arctan(pixelNumber/(2*focalLength))........ here I need the pixelNumber: image Resolution (width or hight).
    

@Bilel12
Copy link
Author

Bilel12 commented Aug 18, 2019

Hi,

Please which file I need to edit the camera settings to change the focal length?
PS: I don't have any experience with Unity, please need your help.

thanks in advance.

@winthos
Copy link
Collaborator

winthos commented Aug 20, 2019

First make sure you download the correct version of the Unity editor (2018.3.6) from the Unity archive: https://unity3d.com/get-unity/download/archive

Once you have that, open up the unity folder in your local copy of the repository.

From here, navigate to the Project tab and you will need to find a prefab called FPSController which is located in Assets/StandardAssets/Characters/FirstPersonCharacter/Prefabs/FPSController. Prefabs are instances of objects that if you edit, will affect all other instances of that prefab in the entire project. The FPSController is the agent placed in each scene, so in order to change the camera settings of all agents in all scenes, you will need to open up this prefab and edit it accordingly.

From here, double click the FPSController prefab and it will open up it up in Prefab Mode. This will allow you to save any changes to the prefab by either hitting the save button in the top right of the Scene View tab, or it will auto-save if the auto save check box is checked.

Screen Shot 2019-08-20 at 9 47 04 AM

Now that you have the prefab open, find the object called FirstPersonCharacter which is in the hierarchy of objects that make up the FPSController. Go to the Heirarchy tab to find this.

Screen Shot 2019-08-20 at 9 49 16 AM

Once you find that, selecting the FirstPersonCharacter will allow you to see its components in the Inspector tab. In the Inspector tab, find the Camera Component which will allow you to edit field of view. Additionally you will find the toggle for Physical Camera Properties I mentioned above, toggling this will allow you to enter focal length, sensor type, and lens size information to simulate a real camera.

Screen Shot 2019-08-20 at 9 51 18 AM

Note that the default settings of the Physical Camera mode will not be the same as the default settings of the camera, so scenes will look different when this mode is toggled on sense the camera is not the same. I would watch for near plane clipping issues if messing with the camera, as the positions of objects in the scene and where the agent can see them from are made assuming the camera has not been changed.

Once you are done with your changes, make sure to save them with the Save button in the Scene View Tab so that they are applied to all instances of the FPSController.

Additionally, if you would like to change focal length or other camera values at runtime, you can access them via the Camera Component: https://docs.unity3d.com/ScriptReference/Camera.html
You will need to write some custom c# code to facilitate this.

@phongnhhn92
Copy link

Hello @winthos,
Would it be possible to add this Physical Camera mode into the new version of Ai2Thor ? I think it would be extremely helpful for 3D vision task (reconstruction, view synthesis ) if we can know the intrinsic and extrinsic information as the agents move around the scene.

@winthos
Copy link
Collaborator

winthos commented Jul 6, 2020

We will look into adding this as an exposed setting in a future release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants