Coder Social home page Coder Social logo

Comments (31)

stavBodik avatar stavBodik commented on September 23, 2024 29

@Vedhus I don't know, its should work maybe the syntax is different but you should find way to get the same using python.

Any way I figure out that in digital camera matrix (computer graphics like openGL/UnrealEngine) the pixel ratio equals to 1 because there is no physical distortion like in real life camera, this means that getting the intrinsic matrix is simple,no calibration operation needed :

Intrinsic Matrix:
K = [[f, 0, Cu],
[0, f, Cv],
[0, 0, 1 ]]

fx=fy=f=imageWidth /(2 * tan(CameraFOV * Ο€ / 360))

Cu=image horizontal center = imageWidth/2
Cv=image vertical center = imageHight/2

Enjoy .

from unrealcv.

yilinliu77 avatar yilinliu77 commented on September 23, 2024 7

@Vedhus I don't know, its should work maybe the syntax is different but you should find way to get the same using python.

Any way I figure out that in digital camera matrix (computer graphics like openGL/UnrealEngine) the pixel ratio equals to 1 because there is no physical distortion like in real life camera, this means that getting the intrinsic matrix is simple,no calibration operation needed :

Intrinsic Matrix:
K = [[f, 0, Cu],
[0, f, Cv],
[0, 0, 1 ]]

fx=fy=f=imageWidth /(2 * tan(CameraFOV * Ο€ / 360))

Cu=image horizontal center = imageWidth/2
Cv=image vertical center = imageHight/2

Enjoy .

The focal length you calculate here is measured in pixel, but how can I get the focal length measured in real-world units(mm)? I can't find the sensor size of the default camera in the unreal engine.

Without the real focal length, how can I reproject the point into 3D world coordinates?

from unrealcv.

dineshreddy91 avatar dineshreddy91 commented on September 23, 2024 5

Hi @edz-o thanks for the reply
According to your formula the k matrix comes out to be

K = [320 0 320
0 320 240
0 0 1]
The depth to point cloud conversion using this intrinsic matrix is very distorted. Previously for opengl to camera matrix conversion i have used this https://strawlab.org/2011/11/05/augmented-reality-with-OpenGL. i wanted to access the OpenGL projection matrix to convert to the Hz intrinsic matrix.

from unrealcv.

DonnEssime avatar DonnEssime commented on September 23, 2024 3

I have a quick note: the posted distance-to-image plane function does not seem to be correct; it actually computes the distance to the camera along the viewing direction (i.e. distance to image plane + focal depth).
The correct equation on line 8 should, imo, read

PlaneDepth = (PointDepth-1) / (1 + (DistanceFromCenter / f)**2)**(0.5)

However, for single-image reconstruction purposes it seems to work as it should πŸ‘ I guess this is more of a semantic note, in that it does not compute the distance to the image plane, but rather to the Z plane in the camera's reference system.

from unrealcv.

edz-o avatar edz-o commented on September 23, 2024 2

Hi,

@debadeepta
We guess the cause is that the depth image obtained by vget /camera/0/depth is the distance from the scene to the camera center, you may convert it to the distance to image plane using this function.

from unrealcv.

DonnEssime avatar DonnEssime commented on September 23, 2024 2

For future reference, I got confused with the calculation/application of the location and rotation, because they do not follow the axes lay-out I was expecting. The translation axes for a non-rotated camera are given with the x axis into the scene, the y axis to the right and the z axis to the top (left-handed, for some reason?). I was expecting it to be z axis into the scene, x axis to the right and y axis to the bottom, as you do when projecting points onto an image plane.
By setting location = [location[1],-location[2],location[0]], the rest of my code ran as expected.

from unrealcv.

edgarriba avatar edgarriba commented on September 23, 2024 1

anyone faced: LogUnrealCV:Warning: error Argument Invalid
when calling vget /camera/0/proj_matrix ?

from unrealcv.

qiuwch avatar qiuwch commented on September 23, 2024

Hi, @dineshreddy91

This is an unfinished feature and I am working on it.
The camera matrix for FOV 90 is fixed, I need to ask my co-author for the exact value.

from unrealcv.

dineshreddy91 avatar dineshreddy91 commented on September 23, 2024

@qiuwch thanks for the reply. can you provide the projection matrix for FOV 90. i wanted to test the odometry and am stuck without the intrinsic matrix of the camera.

from unrealcv.

edz-o avatar edz-o commented on September 23, 2024

Hi, @dineshreddy91

The focal length f = W / 2 / tan(FOV/2) = W/2, where W is the width of the image which is 640 px here. And the pixels are square.

from unrealcv.

qiuwch avatar qiuwch commented on September 23, 2024

@dineshreddy91 If this is not what you are looking for, then I need to spend one or two days to read Unreal Engine's code to find what is the correct answer.

from unrealcv.

bhack avatar bhack commented on September 23, 2024

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/ULocalPlayer/GetProjectionData/index.html

from unrealcv.

debadeepta avatar debadeepta commented on September 23, 2024

screenshot from 2017-06-07 17-09-52
Using the K matrix above I am getting a really distorted point cloud as well. See attached image. It is a view into the room in RealisticRendering binary example. The depth image converted to point cloud using K above makes the scene 'cave-in' towards the center. I think we need the camera distortion model and coefficients to properly project. Is anyone else having the same experience?
figure_1

from unrealcv.

debadeepta avatar debadeepta commented on September 23, 2024

Thank you! I didn't realize the depth image was in ray-distance form. Your function works great. Just a small nitpick: 'f' is undefined in your function. Ideally should be an argument to it.

Many thanks!

from unrealcv.

bhack avatar bhack commented on September 23, 2024

Could we add this to the plugin?

from unrealcv.

qiuwch avatar qiuwch commented on September 23, 2024

@bhack I am willing to finish the uncompleted vget /camera/[id]/proj_matrix. I am working on #60 and it is almost finished. This will be my next step. If anyone has already done this and can make a pull request, that would be best.

@debadeepta I think the distance to the image plane is a much natural definition for depth. The ray-distance should at least be clearly documented, this is our fault. I am thinking to provide both these two types of depth, but not sure how to call them, depth and ray_distance?

from unrealcv.

qiuwch avatar qiuwch commented on September 23, 2024

Hi, @DonnEssime

@edz-o is travelling these days, I will ask him to follow up this issue when he is back.

from unrealcv.

edz-o avatar edz-o commented on September 23, 2024

Hi, @DonnEssime

You are right, this function computes the distance to the camera plane, i.e. the Z plane.

from unrealcv.

jeffreykxiao avatar jeffreykxiao commented on September 23, 2024

@edgarriba as of the current version 0.3.10, the function vget /camera/0/proj_matrix is incomplete. It just contains a couple lines of commented out code and returns FExecStatus::InvalidArgument.

from unrealcv.

stavBodik avatar stavBodik commented on September 23, 2024

@dineshreddy91

CameraMatrix = IntrinsicMatrix * ExtrinsicMatrix

Where ExtrinsicMatrix = RotationMatrix|TranslationMatrix(aKa position)

For C++ users :

ProjectionMatrix projMatrix = client.simGetCameraInfo("0").proj_mat;

VectorMath::Matrix3x3f rotationMatrix = client.simGetCameraInfo("0").pose.orientation.toRotationMatrix();

VectorMath::Vector3f cameraPosition = client.simGetCameraInfo("0").pose.position;

from unrealcv.

Vedhus avatar Vedhus commented on September 23, 2024

@stavBodik is the projMatrix the IntrinsicMatrix?

from unrealcv.

stavBodik avatar stavBodik commented on September 23, 2024

@Vedhus No, The projection matrix is the camera matrix.

from unrealcv.

Vedhus avatar Vedhus commented on September 23, 2024

@stavBodik thanks, do you know if I can use the camera matrix directly with the cv2.reprojectImageTo3D?

from unrealcv.

stavBodik avatar stavBodik commented on September 23, 2024

@Vedhus "In computer vision a camera matrix or projection matrix is a matrix which describes the mapping of a pinhole camera from 3D points in the world to 2D points in an image.Β " I never tried but this matrix should help you to do the reverse operation if you know the depth/distance from the camera to each pixel.

from unrealcv.

Vedhus avatar Vedhus commented on September 23, 2024

@stavBodik Thanks, last question. Does this work with the python client as well?
proj = client.simGetCameraInfo("0").proj_mat

from unrealcv.

Vedhus avatar Vedhus commented on September 23, 2024

@stavBodik Thanks! Do you know why the projection matrix is 4x4 and not 3x4? Because the Intrisic matrix is 3x3 and extrinsic matrix is 3x4.

from unrealcv.

stavBodik avatar stavBodik commented on September 23, 2024

@Vedhus

Some calibration software provides a 4x4 matrix, which adds an extra row to preserve the z-coordinate. In this case, just drop the last row to get a 3x4 matrix.

http://ksimek.github.io/2012/08/14/decompose/

from unrealcv.

cloudlakecho avatar cloudlakecho commented on September 23, 2024

@whatseven, Are you able to get information from specific camera in Python wrapper? It looks like we are not able to attain information in Python environment.,..Here are others' experience.

from unrealcv.

itwpub avatar itwpub commented on September 23, 2024

thanks

from unrealcv.

Shromm-Gaind avatar Shromm-Gaind commented on September 23, 2024

Is anyone else also getting this format of Projection Matrix? It seems wrong, I have no idea why I am getting this. I expected to get a matrix in this format:
image
ProjectionMatrix { 'matrix': [ [ 0.0,
1.0,
0.0,
0.0],
[ 0.0,
0.0,
-1.7777777910232544,
0.0],
[ 0.0,
0.0,
0.0,
10.0],
[ -1.0,
0.0,
0.0,
0.0]]}

from unrealcv.

Nasr1359 avatar Nasr1359 commented on September 23, 2024

Is anyone else also getting this format of Projection Matrix? It seems wrong, I have no idea why I am getting this. I expected to get a matrix in this format: image ProjectionMatrix { 'matrix': [ [ 0.0, 1.0, 0.0, 0.0], [ 0.0, 0.0, -1.7777777910232544, 0.0], [ 0.0, 0.0, 0.0, 10.0], [ -1.0, 0.0, 0.0, 0.0]]}

Hi I got the same Projection matrix when I tried to get the camera information of the AIRSIM simulator by using client.simGetCameraInfo("0") in python.

from unrealcv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.