@@ -291,38 +291,8 @@ bool CameraSensor::CreateCamera()
291
291
break ;
292
292
}
293
293
294
- // Update the DOM object intrinsics to have consistent
295
- // intrinsics between ogre camera and camera_info msg
296
- if (!cameraSdf->HasLensIntrinsics ())
297
- {
298
- auto intrinsicMatrix =
299
- gz::rendering::projectionToCameraIntrinsic (
300
- this ->dataPtr ->camera ->ProjectionMatrix (),
301
- this ->dataPtr ->camera ->ImageWidth (),
302
- this ->dataPtr ->camera ->ImageHeight ()
303
- );
304
-
305
- cameraSdf->SetLensIntrinsicsFx (intrinsicMatrix (0 , 0 ));
306
- cameraSdf->SetLensIntrinsicsFy (intrinsicMatrix (1 , 1 ));
307
- cameraSdf->SetLensIntrinsicsCx (intrinsicMatrix (0 , 2 ));
308
- cameraSdf->SetLensIntrinsicsCy (intrinsicMatrix (1 , 2 ));
309
- }
310
- // set custom projection matrix based on intrinsics param specified in sdf
311
- else
312
- {
313
- double fx = cameraSdf->LensIntrinsicsFx ();
314
- double fy = cameraSdf->LensIntrinsicsFy ();
315
- double cx = cameraSdf->LensIntrinsicsCx ();
316
- double cy = cameraSdf->LensIntrinsicsCy ();
317
- double s = cameraSdf->LensIntrinsicsSkew ();
318
- auto projectionMatrix = CameraSensorPrivate::BuildProjectionMatrix (
319
- this ->dataPtr ->camera ->ImageWidth (),
320
- this ->dataPtr ->camera ->ImageHeight (),
321
- fx, fy, cx, cy, s,
322
- this ->dataPtr ->camera ->NearClipPlane (),
323
- this ->dataPtr ->camera ->FarClipPlane ());
324
- this ->dataPtr ->camera ->SetProjectionMatrix (projectionMatrix);
325
- }
294
+ this ->UpdateLensIntrinsicsAndProjection (this ->dataPtr ->camera ,
295
+ *cameraSdf);
326
296
327
297
this ->dataPtr ->image = this ->dataPtr ->camera ->CreateImage ();
328
298
@@ -336,48 +306,6 @@ bool CameraSensor::CreateCamera()
336
306
this ->dataPtr ->saveImage = true ;
337
307
}
338
308
339
- // Update the DOM object intrinsics to have consistent
340
- // projection matrix values between ogre camera and camera_info msg
341
- // If these values are not defined in the SDF then we need to update
342
- // these values to something reasonable. The projection matrix is
343
- // the cumulative effect of intrinsic and extrinsic parameters
344
- if (!cameraSdf->HasLensProjection ())
345
- {
346
- // Note that the matrix from Ogre via camera->ProjectionMatrix() has a
347
- // different format than the projection matrix used in SDFormat.
348
- // This is why they are converted using projectionToCameraIntrinsic.
349
- // The resulting matrix is the intrinsic matrix, but since the user has
350
- // not overridden the values, this is also equal to the projection matrix.
351
- auto intrinsicMatrix =
352
- gz::rendering::projectionToCameraIntrinsic (
353
- this ->dataPtr ->camera ->ProjectionMatrix (),
354
- this ->dataPtr ->camera ->ImageWidth (),
355
- this ->dataPtr ->camera ->ImageHeight ()
356
- );
357
- cameraSdf->SetLensProjectionFx (intrinsicMatrix (0 , 0 ));
358
- cameraSdf->SetLensProjectionFy (intrinsicMatrix (1 , 1 ));
359
- cameraSdf->SetLensProjectionCx (intrinsicMatrix (0 , 2 ));
360
- cameraSdf->SetLensProjectionCy (intrinsicMatrix (1 , 2 ));
361
- }
362
- // set custom projection matrix based on projection param specified in sdf
363
- else
364
- {
365
- // tx and ty are not used
366
- double fx = cameraSdf->LensProjectionFx ();
367
- double fy = cameraSdf->LensProjectionFy ();
368
- double cx = cameraSdf->LensProjectionCx ();
369
- double cy = cameraSdf->LensProjectionCy ();
370
- double s = 0 ;
371
-
372
- auto projectionMatrix = CameraSensorPrivate::BuildProjectionMatrix (
373
- this ->dataPtr ->camera ->ImageWidth (),
374
- this ->dataPtr ->camera ->ImageHeight (),
375
- fx, fy, cx, cy, s,
376
- this ->dataPtr ->camera ->NearClipPlane (),
377
- this ->dataPtr ->camera ->FarClipPlane ());
378
- this ->dataPtr ->camera ->SetProjectionMatrix (projectionMatrix);
379
- }
380
-
381
309
// Populate camera info topic
382
310
this ->PopulateInfo (cameraSdf);
383
311
@@ -886,6 +814,86 @@ const std::string& CameraSensor::OpticalFrameId() const
886
814
return this ->dataPtr ->opticalFrameId ;
887
815
}
888
816
817
+ // ////////////////////////////////////////////////
818
+ void CameraSensor::UpdateLensIntrinsicsAndProjection (
819
+ rendering::CameraPtr _camera, sdf::Camera &_cameraSdf)
820
+ {
821
+ // Update the DOM object intrinsics to have consistent
822
+ // intrinsics between ogre camera and camera_info msg
823
+ if (!_cameraSdf.HasLensIntrinsics ())
824
+ {
825
+ auto intrinsicMatrix =
826
+ gz::rendering::projectionToCameraIntrinsic (
827
+ _camera->ProjectionMatrix (),
828
+ _camera->ImageWidth (),
829
+ _camera->ImageHeight ()
830
+ );
831
+
832
+ _cameraSdf.SetLensIntrinsicsFx (intrinsicMatrix (0 , 0 ));
833
+ _cameraSdf.SetLensIntrinsicsFy (intrinsicMatrix (1 , 1 ));
834
+ _cameraSdf.SetLensIntrinsicsCx (intrinsicMatrix (0 , 2 ));
835
+ _cameraSdf.SetLensIntrinsicsCy (intrinsicMatrix (1 , 2 ));
836
+ }
837
+ // set custom projection matrix based on intrinsics param specified in sdf
838
+ else
839
+ {
840
+ double fx = _cameraSdf.LensIntrinsicsFx ();
841
+ double fy = _cameraSdf.LensIntrinsicsFy ();
842
+ double cx = _cameraSdf.LensIntrinsicsCx ();
843
+ double cy = _cameraSdf.LensIntrinsicsCy ();
844
+ double s = _cameraSdf.LensIntrinsicsSkew ();
845
+ auto projectionMatrix = CameraSensorPrivate::BuildProjectionMatrix (
846
+ _camera->ImageWidth (),
847
+ _camera->ImageHeight (),
848
+ fx, fy, cx, cy, s,
849
+ _camera->NearClipPlane (),
850
+ _camera->FarClipPlane ());
851
+ _camera->SetProjectionMatrix (projectionMatrix);
852
+ }
853
+
854
+ // Update the DOM object intrinsics to have consistent
855
+ // projection matrix values between ogre camera and camera_info msg
856
+ // If these values are not defined in the SDF then we need to update
857
+ // these values to something reasonable. The projection matrix is
858
+ // the cumulative effect of intrinsic and extrinsic parameters
859
+ if (!_cameraSdf.HasLensProjection ())
860
+ {
861
+ // Note that the matrix from Ogre via camera->ProjectionMatrix() has a
862
+ // different format than the projection matrix used in SDFormat.
863
+ // This is why they are converted using projectionToCameraIntrinsic.
864
+ // The resulting matrix is the intrinsic matrix, but since the user has
865
+ // not overridden the values, this is also equal to the projection matrix.
866
+ auto intrinsicMatrix =
867
+ gz::rendering::projectionToCameraIntrinsic (
868
+ _camera->ProjectionMatrix (),
869
+ _camera->ImageWidth (),
870
+ _camera->ImageHeight ()
871
+ );
872
+ _cameraSdf.SetLensProjectionFx (intrinsicMatrix (0 , 0 ));
873
+ _cameraSdf.SetLensProjectionFy (intrinsicMatrix (1 , 1 ));
874
+ _cameraSdf.SetLensProjectionCx (intrinsicMatrix (0 , 2 ));
875
+ _cameraSdf.SetLensProjectionCy (intrinsicMatrix (1 , 2 ));
876
+ }
877
+ // set custom projection matrix based on projection param specified in sdf
878
+ else
879
+ {
880
+ // tx and ty are not used
881
+ double fx = _cameraSdf.LensProjectionFx ();
882
+ double fy = _cameraSdf.LensProjectionFy ();
883
+ double cx = _cameraSdf.LensProjectionCx ();
884
+ double cy = _cameraSdf.LensProjectionCy ();
885
+ double s = 0 ;
886
+
887
+ auto projectionMatrix = CameraSensorPrivate::BuildProjectionMatrix (
888
+ _camera->ImageWidth (),
889
+ _camera->ImageHeight (),
890
+ fx, fy, cx, cy, s,
891
+ _camera->NearClipPlane (),
892
+ _camera->FarClipPlane ());
893
+ _camera->SetProjectionMatrix (projectionMatrix);
894
+ }
895
+ }
896
+
889
897
// ////////////////////////////////////////////////
890
898
math::Matrix4d CameraSensorPrivate::BuildProjectionMatrix (
891
899
double _imageWidth, double _imageHeight,
0 commit comments