SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSAndroidARCore Class Reference

#include <SENSAndroidARCore.h>

Inheritance diagram for SENSAndroidARCore:
[legend]

Public Member Functions

 SENSAndroidARCore (JavaVM *jvm, JNIEnv *env, jobject context, jobject activity, std::string appName, std::string writableDir)
 
 ~SENSAndroidARCore ()
 
bool init (unsigned int textureId=0, bool retrieveCpuImg=false, int targetWidth=-1) override
 
bool init (JNIEnv *env, void *context, void *activity)
 
bool isReady () override
 
bool resume () override
 
void reset () override
 
void pause () override
 
bool update (cv::Mat &pose) override
 
void lightComponentIntensity (float *components) override
 
bool checkAvailability (JNIEnv *env, void *context, void *activity)
 
bool isAvailable () override
 
bool checkInstalled (JNIEnv *env, void *context, void *activity)
 
bool isInstalled () override
 
bool askInstall (JNIEnv *env, void *context, void *activity)
 
bool install () override
 
bool installRefused () override
 
void installRefused (bool b) override
 
const SENSCameraConfigstart (std::string deviceId, const SENSCameraStreamConfig &streamConfig, bool provideIntrinsics) override
 This function is needed to correctly use arcore as a camera in SENSCVCamera. More...
 
void stop () override
 Stop a started camera device. More...
 
const SENSCapturePropscaptureProperties () override
 Get SENSCaptureProps which contains necessary information about all available camera devices and their capabilities. More...
 
- Public Member Functions inherited from SENSARBaseCamera
 SENSARBaseCamera ()
 
virtual ~SENSARBaseCamera ()
 
bool isRunning ()
 
void fetchPointCloud (bool s)
 
cv::Mat pointCloud ()
 
cv::Size inputFrameSize ()
 
cv::Size cpuFrameSize ()
 
- Public Member Functions inherited from SENSBaseCamera
SENSFrameBasePtr latestFrame () override
 Get the latest captured frame. If no frame was captured the frame will be empty (null). More...
 
const SENSCameraConfigconfig () const override
 defines how the camera was configured during start More...
 
void registerListener (SENSCameraListener *listener) override
 
void unregisterListener (SENSCameraListener *listener) override
 
bool started () const override
 
bool permissionGranted () const override
 
void setPermissionGranted () override
 
- Public Member Functions inherited from SENSCamera
virtual ~SENSCamera ()
 

Private Member Functions

void doFetchPointCloud ()
 
cv::Mat convertToYuv (ArImage *arImage)
 
void updateCamera (cv::Mat &intrinsics)
 
void retrieveCaptureProperties ()
 

Private Attributes

ArSession * _arSession = nullptr
 
ArFrame * _arFrame = nullptr
 
bool _waitInit = false
 
bool _available = false
 
bool _installed = false
 
bool _installRefused = false
 
GLuint _fbo = 0
 
GLuint _pbo = 0
 
GLuint _cameraTextureId
 
float _envLightI [3]
 
JavaVM * _jvm
 
std::string _appName
 
std::string _writableDir
 
SENSGLTextureReader_texImgReader = nullptr
 
float _fx = 0.f
 
float _fy = 0.f
 
float _cx = 0.f
 
float _cy = 0.f
 

Additional Inherited Members

- Protected Member Functions inherited from SENSBaseCamera
void updateFrame (cv::Mat bgrImg, cv::Mat intrinsics, int width, int height, bool intrinsicsChanged)
 
void processStart ()
 call from start function to do startup preprocessing More...
 
- Protected Attributes inherited from SENSARBaseCamera
bool _running = false
 
bool _pause = true
 
int _inputFrameW = 0
 
int _inputFrameH = 0
 
bool _retrieveCpuImg = false
 
int _cpuImgTargetWidth = -1
 
int _cpuImgTargetHeight = -1
 
bool _fetchPointCloud = false
 
cv::Mat _pointCloud
 
- Protected Attributes inherited from SENSBaseCamera
SENSCaptureProps _captureProperties
 
std::atomic< bool > _started {false}
 flags if camera was started More...
 
SENSCameraConfig _config
 indicates what is currently running More...
 
std::atomic< bool > _permissionGranted {false}
 
std::vector< SENSCameraListener * > _listeners
 
std::mutex _listenerMutex
 
SENSFrameBasePtr _frame
 current frame More...
 
std::mutex _frameMutex
 

Detailed Description

Definition at line 23 of file SENSAndroidARCore.h.

Constructor & Destructor Documentation

◆ SENSAndroidARCore()

SENSAndroidARCore::SENSAndroidARCore ( JavaVM *  jvm,
JNIEnv *  env,
jobject  context,
jobject  activity,
std::string  appName,
std::string  writableDir 
)

Definition at line 19 of file SENSAndroidARCore.cpp.

25 {
26  checkAvailability(env, context, activity);
27  _arSession = nullptr;
28  _jvm = jvm;
29 
30  _appName = appName;
31  _writableDir = writableDir;
32 }
ArSession * _arSession
std::string _writableDir
bool checkAvailability(JNIEnv *env, void *context, void *activity)

◆ ~SENSAndroidARCore()

SENSAndroidARCore::~SENSAndroidARCore ( )

Definition at line 117 of file SENSAndroidARCore.cpp.

118 {
119  reset();
120 }
void reset() override

Member Function Documentation

◆ askInstall()

bool SENSAndroidARCore::askInstall ( JNIEnv *  env,
void context,
void activity 
)

Definition at line 92 of file SENSAndroidARCore.cpp.

93 {
94  ArInstallStatus install_status;
95  ArCoreApk_requestInstall(env, activity, true, &install_status);
96  if (install_status == AR_AVAILABILITY_SUPPORTED_INSTALLED)
97  {
98  _installed = true;
99  return true;
100  }
101 
102  _installed = false;
103  return false;
104 }

◆ captureProperties()

const SENSCaptureProps & SENSAndroidARCore::captureProperties ( )
overridevirtual

Get SENSCaptureProps which contains necessary information about all available camera devices and their capabilities.

Implements SENSCamera.

Definition at line 487 of file SENSAndroidARCore.cpp.

488 {
489  if (_captureProperties.size() == 0)
491 
492  return _captureProperties;
493 }
SENSCaptureProps _captureProperties
Definition: SENSCamera.h:216

◆ checkAvailability()

bool SENSAndroidARCore::checkAvailability ( JNIEnv *  env,
void context,
void activity 
)

Definition at line 34 of file SENSAndroidARCore.cpp.

37 {
38  ArAvailability availability;
39  ArCoreApk_checkAvailability(env, context, &availability);
40 
41  if (availability == AR_AVAILABILITY_UNKNOWN_CHECKING)
42  {
43  // TODO(dgj1): this could theoretically go on forever (or until the stack-memory is all used up).
44  // add a limit to recursion?
45  std::this_thread::sleep_for(std::chrono::microseconds((int)(200000)));
46  checkAvailability(env, context, activity);
47  }
48  else if (availability == AR_AVAILABILITY_SUPPORTED_NOT_INSTALLED ||
49  availability == AR_AVAILABILITY_SUPPORTED_APK_TOO_OLD ||
50  availability == AR_AVAILABILITY_SUPPORTED_INSTALLED)
51  {
52  return true;
53  }
54  return false;
55 }

◆ checkInstalled()

bool SENSAndroidARCore::checkInstalled ( JNIEnv *  env,
void context,
void activity 
)

Definition at line 69 of file SENSAndroidARCore.cpp.

72 {
73  ArAvailability availability;
74  ArCoreApk_checkAvailability(env, context, &availability);
75  if (availability == AR_AVAILABILITY_SUPPORTED_INSTALLED)
76  return true;
77  return false;
78 }

◆ convertToYuv()

cv::Mat SENSAndroidARCore::convertToYuv ( ArImage *  arImage)
private

Definition at line 385 of file SENSAndroidARCore.cpp.

386 {
387  int32_t height, width, rowStrideY;
388  ArImage_getHeight(_arSession, arImage, &height);
389  ArImage_getWidth(_arSession, arImage, &width);
390  ArImage_getPlaneRowStride(_arSession, arImage, 0, &rowStrideY);
391 
392  // pointers to yuv data planes and length of yuv data planes in byte
393  const uint8_t *yPixel, *vPixel;
394  int32_t yLen, vLen;
395  ArImage_getPlaneData(_arSession, arImage, (int32_t)0, &yPixel, &yLen);
396  ArImage_getPlaneData(_arSession, arImage, (int32_t)2, &vPixel, &vLen);
397 
398  cv::Mat yuv(height + (height / 2), rowStrideY, CV_8UC1);
399  memcpy(yuv.data, yPixel, yLen);
400  memcpy(yuv.data + yLen + (rowStrideY - width), vPixel, vLen + 1);
401 
402  if (rowStrideY > width)
403  {
404  cv::Rect roi(0, 0, width, yuv.rows);
405  cv::Mat roiYuv = yuv(roi);
406  return roiYuv;
407  }
408  else
409  return yuv;
410 }

◆ doFetchPointCloud()

void SENSAndroidARCore::doFetchPointCloud ( )
private

Definition at line 536 of file SENSAndroidARCore.cpp.

537 {
538  ArPointCloud* arPointCloud = nullptr;
539 
540  if (ArFrame_acquirePointCloud(_arSession,
541  _arFrame,
542  &arPointCloud) == AR_SUCCESS)
543  {
544  int n;
545  float* mp;
546 
547  ArPointCloud_getNumberOfPoints(_arSession, arPointCloud, &n);
548  if (n > 0)
549  {
550  ArPointCloud_getData(_arSession, arPointCloud, &mp);
551 
552  _pointCloud = cv::Mat(n, 4, CV_32F);
553  std::memcpy(_pointCloud.data, mp, n * 4 * sizeof(float));
554  /*
555  int nbPoints = 0;
556  for (int i = 0; i < n; i++)
557  {
558  int idx = i * 4;
559  if (mp[idx + 3] >= confidanceValue)
560  {
561  *mapPoints[nbPoints] = mp[idx];
562  *mapPoints[nbPoints + 1] = mp[idx + 1];
563  *mapPoints[nbPoints + 2] = mp[idx + 2];
564  nbPoints++;
565  }
566  }
567  */
568  }
569  ArPointCloud_release(arPointCloud);
570  }
571 }

◆ init() [1/2]

bool SENSAndroidARCore::init ( JNIEnv *  env,
void context,
void activity 
)

Definition at line 164 of file SENSAndroidARCore.cpp.

165 {
166  if (!checkAvailability(env, context, activity)) return false;
167  if (_arSession != nullptr) return false;
168 
169  ArInstallStatus install_status;
170  ArCoreApk_requestInstall(env, activity, false, &install_status);
171 
172  if (install_status == AR_AVAILABILITY_SUPPORTED_NOT_INSTALLED) return false;
173  if (ArSession_create(env, activity, &_arSession) != AR_SUCCESS) return false;
174  if (!_arSession) return false;
175 
176  // todo: what do we have to set here? the display size? is it needed at all for our case?
177  // ArSession_setDisplayGeometry(_arSession, 0, _config.targetWidth, _config.targetHeight);
178 
179  // ----- config -----
180  ArConfig* arConfig = nullptr;
181  ArConfig_create(_arSession, &arConfig);
182 
183  if (!arConfig)
184  {
185  ArSession_destroy(_arSession);
186  _arSession = nullptr;
187  return false;
188  }
189 
190  // Depth texture has values between 0 millimeters to 8191 millimeters. 8m is not enough in our case
191  // https://developers.google.com/ar/reference/c/group/ar-frame#arframe_acquiredepthimage
192  ArConfig_setDepthMode(_arSession, arConfig, AR_DEPTH_MODE_DISABLED);
193  ArConfig_setLightEstimationMode(_arSession, arConfig, AR_LIGHT_ESTIMATION_MODE_ENVIRONMENTAL_HDR);
194  ArConfig_setInstantPlacementMode(_arSession, arConfig, AR_INSTANT_PLACEMENT_MODE_DISABLED);
195 
196  ArSession_setCameraTextureName(_arSession, _cameraTextureId);
197 
198  if (ArSession_configure(_arSession, arConfig) != AR_SUCCESS)
199  {
200  ArConfig_destroy(arConfig);
201  ArSession_destroy(_arSession);
202  _arSession = nullptr;
203  return false;
204  }
205  _envLightI[0] = 1.0f;
206  _envLightI[1] = 1.0f;
207  _envLightI[2] = 1.0f;
208 
209  ArConfig_destroy(arConfig);
210 
211  // -- arFrame The world state resulting from an update
212  // Create with: ArFrame_create
213  // Allocate with: ArSession_update
214  // Release with: ArFrame_destroy
215 
216  ArFrame_create(_arSession, &_arFrame);
217  if (!_arFrame)
218  {
219  ArSession_destroy(_arSession);
220  _arSession = nullptr;
221  return false;
222  }
223 
224  // retrieve intrinsics and frame size
225  ArCamera* arCamera;
226  ArFrame_acquireCamera(_arSession, _arFrame, &arCamera);
227 
228  ArCameraIntrinsics* arIntrinsics = nullptr;
229  ArCameraIntrinsics_create(_arSession, &arIntrinsics);
230  ArCamera_getTextureIntrinsics(_arSession, arCamera, arIntrinsics);
231 
232  ArCameraIntrinsics_getFocalLength(_arSession, arIntrinsics, &_fx, &_fy);
233  ArCameraIntrinsics_getPrincipalPoint(_arSession, arIntrinsics, &_cx, &_cy);
234  ArCameraIntrinsics_getImageDimensions(_arSession,
235  arIntrinsics,
236  &_inputFrameW,
237  &_inputFrameH);
238 
239  ArCameraIntrinsics_destroy(arIntrinsics);
240  ArCamera_release(arCamera);
241 
242  if (_cpuImgTargetWidth > 0)
243  {
244  float aspect = (float)_inputFrameH / (float)_inputFrameW;
246  }
247 
248  pause();
249  return true;
250 }
void pause() override

◆ init() [2/2]

bool SENSAndroidARCore::init ( unsigned int  textureId = 0,
bool  retrieveCpuImg = false,
int  targetWidth = -1 
)
overridevirtual

Implements SENSARBaseCamera.

Definition at line 139 of file SENSAndroidARCore.cpp.

142 {
143  if (textureId > 0)
144  _cameraTextureId = textureId;
145 
146  if (_texImgReader)
147  {
148  delete _texImgReader;
149  _texImgReader = nullptr;
150  }
151 
152  _retrieveCpuImg = retrieveCpuImg;
153  _cpuImgTargetWidth = targetWidth;
154 
155  JNIEnv* env;
156  _jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
157  std::string className = "ch/cpvr/" + _appName + "/GLES3Lib";
158  jclass clazz = env->FindClass(className.c_str());
159  jmethodID methodid = env->GetStaticMethodID(clazz, "initAR", "()Z");
160 
161  return env->CallStaticBooleanMethod(clazz, methodid);
162 }
SENSGLTextureReader * _texImgReader

◆ install()

bool SENSAndroidARCore::install ( )
overridevirtual

Reimplemented from SENSARBaseCamera.

Definition at line 106 of file SENSAndroidARCore.cpp.

107 {
108  JNIEnv* env;
109  _jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
110  std::string className = "ch/cpvr/" + _appName + "/GLES3Lib";
111  jclass clazz = env->FindClass(className.c_str());
112  jmethodID methodid = env->GetStaticMethodID(clazz, "askARInstall", "()Z");
113 
114  return env->CallStaticBooleanMethod(clazz, methodid);
115 }

◆ installRefused() [1/2]

bool SENSAndroidARCore::installRefused ( )
inlineoverridevirtual

Reimplemented from SENSARBaseCamera.

Definition at line 50 of file SENSAndroidARCore.h.

50 { return _installRefused; };

◆ installRefused() [2/2]

void SENSAndroidARCore::installRefused ( bool  b)
inlineoverridevirtual

Reimplemented from SENSARBaseCamera.

Definition at line 51 of file SENSAndroidARCore.h.

51 { _installRefused = b; };

◆ isAvailable()

bool SENSAndroidARCore::isAvailable ( )
overridevirtual

Reimplemented from SENSARBaseCamera.

Definition at line 57 of file SENSAndroidARCore.cpp.

58 {
59  JNIEnv* env;
60  _jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
61  std::string className = "ch/cpvr/" + _appName + "/GLES3Lib";
62  jclass clazz = env->FindClass(className.c_str());
63  jmethodID methodid = env->GetStaticMethodID(clazz, "checkARAvailability", "()Z");
64 
65  _available = env->CallStaticBooleanMethod(clazz, methodid);
66  return _available;
67 }

◆ isInstalled()

bool SENSAndroidARCore::isInstalled ( )
overridevirtual

Reimplemented from SENSARBaseCamera.

Definition at line 80 of file SENSAndroidARCore.cpp.

81 {
82  JNIEnv* env;
83  _jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
84  std::string className = "ch/cpvr/" + _appName + "/GLES3Lib";
85  jclass clazz = env->FindClass(className.c_str());
86  jmethodID methodid = env->GetStaticMethodID(clazz, "checkARInstalled", "()Z");
87 
88  _installed = env->CallStaticBooleanMethod(clazz, methodid);
89  return _installed;
90 }

◆ isReady()

bool SENSAndroidARCore::isReady ( )
inlineoverridevirtual

Implements SENSARBaseCamera.

Definition at line 38 of file SENSAndroidARCore.h.

38 { return _arSession != nullptr; }

◆ lightComponentIntensity()

void SENSAndroidARCore::lightComponentIntensity ( float *  components)
overridevirtual

Reimplemented from SENSARBaseCamera.

Definition at line 378 of file SENSAndroidARCore.cpp.

379 {
380  component[0] = _envLightI[0];
381  component[1] = _envLightI[1];
382  component[2] = _envLightI[2];
383 }

◆ pause()

void SENSAndroidARCore::pause ( )
overridevirtual

Implements SENSARBaseCamera.

Definition at line 428 of file SENSAndroidARCore.cpp.

429 {
430  _started = false; // for SENSBaseCamera
431  if (!_arSession) return;
432 
433  if (AR_SUCCESS == ArSession_pause(_arSession))
434  _pause = true;
435  else
436  Utils::log("ErlebAR", "SENSAndroidARCore pause failed!!!");
437 }
std::atomic< bool > _started
flags if camera was started
Definition: SENSCamera.h:217
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1100

◆ reset()

void SENSAndroidARCore::reset ( )
overridevirtual

Implements SENSARBaseCamera.

Definition at line 122 of file SENSAndroidARCore.cpp.

123 {
124  if (_arSession != nullptr)
125  {
126  pause();
127  ArSession_destroy(_arSession);
128  ArFrame_destroy(_arFrame);
129  _arSession = nullptr;
130  if (_texImgReader)
131  {
132  delete _texImgReader;
133  _texImgReader = nullptr;
134  }
135  }
136 }

◆ resume()

bool SENSAndroidARCore::resume ( )
overridevirtual

Implements SENSARBaseCamera.

Definition at line 412 of file SENSAndroidARCore.cpp.

413 {
414  if (_pause && _arSession != nullptr)
415  {
416  const ArStatus status = ArSession_resume(_arSession);
417  if (status == AR_SUCCESS)
418  {
419  _pause = false;
420  _started = true; // for SENSBaseCamera
421  }
422  else
423  Utils::log("ErlebAR", "SENSAndroidARCore resume failed!!!");
424  }
425  return !_pause;
426 }

◆ retrieveCaptureProperties()

void SENSAndroidARCore::retrieveCaptureProperties ( )
private

Definition at line 439 of file SENSAndroidARCore.cpp.

440 {
441  // the SENSBaseCamera needs to have a valid frame, otherwise we cannot estimate the fov correctly
442  /*
443  if(!_frame)
444  {
445  resume();
446  HighResTimer t;
447  cv::Mat pose;
448  do {
449  update(pose);
450  std::this_thread::sleep_for(200ms);
451  }
452  while(!_frame && t.elapsedTimeInSec() < 10.f);
453 
454  Utils::log("SENSAndroidARCore", "retrieveCaptureProperties update for %fs", t.elapsedTimeInSec());
455  pause();
456  }
457 
458  if(_frame)
459  {
460  std::string deviceId = "ARKit";
461  SENSCameraFacing facing = SENSCameraFacing::BACK;
462 
463  float focalLengthPix = -1.f;
464  if(!_frame->intrinsics.empty())
465  {
466  focalLengthPix = 0.5 * (_frame->intrinsics.at<double>(0, 0) + _frame->intrinsics.at<double>(1, 1));
467  }
468  SENSCameraDeviceProps devProp(deviceId, facing);
469  //here we have to use the cpu image size (which is not the same as the gpu image size)
470  devProp.add(_inputFrameW, _inputFrameH, focalLengthPix);
471  _captureProperties.push_back(devProp);
472  }
473  else
474  Utils::warnMsg("SENSAndroidARCore", "retrieveCaptureProperties: Could not retrieve a valid frame!", __LINE__, __FILE__);
475  */
476  std::string deviceId = "ARKit";
478 
479  float focalLengthPix = 0.5 * (_fx + _fy);
480  SENSCameraDeviceProps devProp(deviceId, facing);
481 
482  // here we have to use the cpu image size (which is not the same as the gpu image size)
483  devProp.add(_inputFrameW, _inputFrameH, focalLengthPix);
484  _captureProperties.push_back(devProp);
485 }
SENSCameraFacing
Definition of camera facing.
Definition: SENSCamera.h:28

◆ start()

const SENSCameraConfig & SENSAndroidARCore::start ( std::string  deviceId,
const SENSCameraStreamConfig streamConfig,
bool  provideIntrinsics 
)
overridevirtual

This function is needed to correctly use arcore as a camera in SENSCVCamera.

This function does not really start the camera as for the arcore implementation, the frame gets only updated with a call to arcore::update.

Implements SENSCamera.

Definition at line 499 of file SENSAndroidARCore.cpp.

502 {
503  // define capture properties
504  if (_captureProperties.size() == 0)
506 
507  if (_captureProperties.size() == 0)
509  "Could not retrieve camera properties!",
510  __LINE__,
511  __FILE__);
512 
513  if (!_captureProperties.containsDeviceId(deviceId))
515  "DeviceId does not exist!",
516  __LINE__,
517  __FILE__);
518 
521  if (props)
522  facing = props->facing();
523 
524  // init config here before processStart
525  _config = SENSCameraConfig(deviceId,
526  streamConfig,
527  facing,
529  // inform camera listeners
530  processStart();
531 
532  _started = true;
533  return _config;
534 }
SENSCameraConfig _config
indicates what is currently running
Definition: SENSCamera.h:218
void processStart()
call from start function to do startup preprocessing
Definition: SENSCamera.cpp:294
const SENSCameraFacing & facing() const
Definition: SENSCamera.h:86
bool containsDeviceId(const std::string &deviceId) const
Definition: SENSCamera.cpp:61
const SENSCameraDeviceProps * camPropsForDeviceId(const std::string &deviceId) const
Definition: SENSCamera.cpp:73

◆ stop()

void SENSAndroidARCore::stop ( )
inlineoverridevirtual

Stop a started camera device.

Implements SENSCamera.

Definition at line 58 of file SENSAndroidARCore.h.

58 { _started = false; };

◆ update()

bool SENSAndroidARCore::update ( cv::Mat &  view)
overridevirtual

Returns true if in tracking state. If correctly initialized, it will update the camera frame that may be retrieved with latestFrame()

Reimplemented from SENSARBaseCamera.

Definition at line 252 of file SENSAndroidARCore.cpp.

253 {
254  if (!_arSession) return false;
255  ArStatus status = ArSession_update(_arSession, _arFrame);
256  if (status != AR_SUCCESS) return false;
257 
258  ArCamera* arCamera;
259  ArFrame_acquireCamera(_arSession, _arFrame, &arCamera);
260 
261  cv::Mat view = cv::Mat::eye(4, 4, CV_32F);
262  ArCamera_getViewMatrix(_arSession, arCamera, view.ptr<float>(0));
263 
264  // conversions to sl camera pose:
265  // from row- to column-major
266  view = view.t();
267  // inversion
268  cv::Mat wRc = (view.rowRange(0, 3).colRange(0, 3)).t();
269  cv::Mat wtc = -wRc * view.rowRange(0, 3).col(3);
270  cv::Mat wTc = cv::Mat::eye(4, 4, CV_32F);
271  wRc.copyTo(wTc.colRange(0, 3).rowRange(0, 3));
272  wtc.copyTo(wTc.rowRange(0, 3).col(3));
273  // axis direction adaption (x = -y, y = x, z = z, t = t)
274  pose = cv::Mat::eye(4, 4, CV_32F);
275  wTc.col(1) *= -1;
276  wTc.col(1).copyTo(pose.col(0));
277  wTc.col(0).copyTo(pose.col(1));
278  wTc.col(2).copyTo(pose.col(2));
279  wTc.col(3).copyTo(pose.col(3));
280 
281  cv::Mat intrinsics = cv::Mat::eye(3, 3, CV_64F);
282  {
283  ArCameraIntrinsics* arIntrinsics = nullptr;
284  ArCameraIntrinsics_create(_arSession, &arIntrinsics);
285  ArCamera_getTextureIntrinsics(_arSession, arCamera, arIntrinsics);
286 
287  float fx, fy, cx, cy;
288  ArCameraIntrinsics_getFocalLength(_arSession, arIntrinsics, &fx, &fy);
289  ArCameraIntrinsics_getPrincipalPoint(_arSession, arIntrinsics, &cx, &cy);
290 
291  ArCameraIntrinsics_getImageDimensions(_arSession,
292  arIntrinsics,
293  &_inputFrameW,
294  &_inputFrameH);
295 
296  ArCameraIntrinsics_destroy(arIntrinsics);
297 
298  intrinsics.at<double>(0, 0) = fx;
299  intrinsics.at<double>(1, 1) = fy;
300  intrinsics.at<double>(0, 2) = cx;
301  intrinsics.at<double>(1, 2) = cy;
302  /*
303  std::stringstream ss;
304  ss << intrinsics;
305  Utils::log("SENSAndroidARCore", "intrinsics %s", ss.str().c_str());
306  */
307  }
308 
309  updateCamera(intrinsics);
310 
311  //---- LIGHT ESTIMATE ----//
312  // Get light estimation value.
313  /*
314  ArLightEstimate* arLightEstimate;
315  ArLightEstimateState arLightEstimateState;
316  ArLightEstimate_create(_arSession, &arLightEstimate);
317 
318  ArFrame_getLightEstimate(_arSession, _arFrame, arLightEstimate);
319  ArLightEstimate_getState(_arSession, arLightEstimate, &arLightEstimateState);
320 
321  // Set light intensity to default. Intensity value ranges from 0.0f to 1.0f.
322  // The first three components are color scaling factors.
323  // The last one is the average pixel intensity in gamma space.
324  if (arLightEstimateState == AR_LIGHT_ESTIMATE_STATE_VALID)
325  {
326  //ArLightEstimate_getColorCorrection(_arSession, arLightEstimate, _lightColor);
327  ArLightEstimate_getEnvironmentalHdrMainLightIntensity(_arSession, arLightEstimate, _envLightI);
328  }
329 
330  ArLightEstimate_destroy(arLightEstimate);
331  arLightEstimate = nullptr;
332  */
333  //---------------------
334 
335  ArTrackingState camera_tracking_state;
336  ArCamera_getTrackingState(_arSession, arCamera, &camera_tracking_state);
337 
338  if (_fetchPointCloud)
340 
341  ArCamera_release(arCamera);
342  // If the camera isn't tracking don't bother rendering other objects.
343  if (camera_tracking_state != AR_TRACKING_STATE_TRACKING)
344  return false;
345 
346  return true;
347 }
void updateCamera(cv::Mat &intrinsics)

◆ updateCamera()

void SENSAndroidARCore::updateCamera ( cv::Mat &  intrinsics)
private

Definition at line 349 of file SENSAndroidARCore.cpp.

350 {
351  cv::Mat image;
352 
353  if (_retrieveCpuImg)
354  {
355  if (!_texImgReader)
356  {
357  // ATTENTION: for the current implementation the gpu texture (preview image) has to have the same aspect ratio as the cpu image
358  // check aspect ratio
360  }
361 
362  HighResTimer t;
363  image = _texImgReader->readImageFromGpu();
364 
365  Utils::log("SENSAndroidARCore", "readImageFromGPU: %fms", t.elapsedTimeInMilliSec());
366  /*
367  Utils::log("imagesize", "orig w:%d h:%d", image.size().width, image.size().height);
368  Utils::log("imagesize", "orig imageSize w:%d h:%d", _inputFrameW, _inputFrameH);
369  Utils::log("imagesize", "orig calib cx:%f cy:%f", intrinsics.at<double>(0, 2),
370  intrinsics.at<double>(1, 2));
371  */
372  // adapt intrinsics to cpu image size
373  }
374 
375  updateFrame(image, intrinsics, _inputFrameW, _inputFrameH, true);
376 }
High Resolution Timer class using C++11.
Definition: HighResTimer.h:31
float elapsedTimeInMilliSec()
Definition: HighResTimer.h:38
void updateFrame(cv::Mat bgrImg, cv::Mat intrinsics, int width, int height, bool intrinsicsChanged)
Definition: SENSCamera.cpp:220

Member Data Documentation

◆ _appName

std::string SENSAndroidARCore::_appName
private

Definition at line 81 of file SENSAndroidARCore.h.

◆ _arFrame

ArFrame* SENSAndroidARCore::_arFrame = nullptr
private

Definition at line 66 of file SENSAndroidARCore.h.

◆ _arSession

ArSession* SENSAndroidARCore::_arSession = nullptr
private

Definition at line 65 of file SENSAndroidARCore.h.

◆ _available

bool SENSAndroidARCore::_available = false
private

Definition at line 68 of file SENSAndroidARCore.h.

◆ _cameraTextureId

GLuint SENSAndroidARCore::_cameraTextureId
private

Definition at line 75 of file SENSAndroidARCore.h.

◆ _cx

float SENSAndroidARCore::_cx = 0.f
private

Definition at line 91 of file SENSAndroidARCore.h.

◆ _cy

float SENSAndroidARCore::_cy = 0.f
private

Definition at line 91 of file SENSAndroidARCore.h.

◆ _envLightI

float SENSAndroidARCore::_envLightI[3]
private

Definition at line 77 of file SENSAndroidARCore.h.

◆ _fbo

GLuint SENSAndroidARCore::_fbo = 0
private

Definition at line 72 of file SENSAndroidARCore.h.

◆ _fx

float SENSAndroidARCore::_fx = 0.f
private

Definition at line 91 of file SENSAndroidARCore.h.

◆ _fy

float SENSAndroidARCore::_fy = 0.f
private

Definition at line 91 of file SENSAndroidARCore.h.

◆ _installed

bool SENSAndroidARCore::_installed = false
private

Definition at line 69 of file SENSAndroidARCore.h.

◆ _installRefused

bool SENSAndroidARCore::_installRefused = false
private

Definition at line 70 of file SENSAndroidARCore.h.

◆ _jvm

JavaVM* SENSAndroidARCore::_jvm
private

Definition at line 78 of file SENSAndroidARCore.h.

◆ _pbo

GLuint SENSAndroidARCore::_pbo = 0
private

Definition at line 73 of file SENSAndroidARCore.h.

◆ _texImgReader

SENSGLTextureReader* SENSAndroidARCore::_texImgReader = nullptr
private

Definition at line 84 of file SENSAndroidARCore.h.

◆ _waitInit

bool SENSAndroidARCore::_waitInit = false
private

Definition at line 67 of file SENSAndroidARCore.h.

◆ _writableDir

std::string SENSAndroidARCore::_writableDir
private

Definition at line 82 of file SENSAndroidARCore.h.


The documentation for this class was generated from the following files: