35 #include <media/NdkImage.h> 48 arInstallRequested_(
false)
71 HwArInstallStatus install_status;
81 HwArEnginesApk_requestInstall(
env_,
activity_, user_requested_install, &install_status);
83 switch (install_status)
85 case HWAR_INSTALL_STATUS_INSTALLED:
87 case HWAR_INSTALL_STATUS_INSTALL_REQUESTED:
123 if (HwArSession_resume(
arSession_) != HWAR_SUCCESS)
125 UERROR(
"Cannot resume camera!");
185 LOGE(
"CameraAREngine::captureImage() ArSession_update error");
189 HwArCamera* ar_camera;
192 HwArTrackingState camera_tracking_state;
193 HwArCamera_getTrackingState(
arSession_, ar_camera, &camera_tracking_state);
196 if(camera_tracking_state == HWAR_TRACKING_STATE_TRACKING)
202 pose =
Transform(pose_raw[4], pose_raw[5], pose_raw[6], pose_raw[0], pose_raw[1], pose_raw[2], pose_raw[3]);
206 float fx=492.689667,fy=492.606201, cx=323.594849, cy=234.659744;
207 int32_t camWidth=640, camHeight=480;
212 LOGI(
"%f %f %f %f %d %d", fx, fy, cx, cy, camWidth, camHeight);
214 if(fx > 0 && fy > 0 && camWidth > 0 && camHeight > 0 && cx > 0 && cy > 0)
219 HwArImage * image =
nullptr;
220 HwArImage * depthImage =
nullptr;
222 HwArStatus statusDepth = HwArFrame_acquireDepthImage(
arSession_,
arFrame_, &depthImage);
223 if(statusRgb == HWAR_SUCCESS && statusDepth == HWAR_SUCCESS)
234 const AImage* ndkImageRGB;
235 HwArImage_getNdkImage(image, &ndkImageRGB);
237 AImage_getNumberOfPlanes(ndkImageRGB, &planeCount);
238 AImage_getWidth(ndkImageRGB, &width);
239 AImage_getHeight(ndkImageRGB, &height);
240 AImage_getPlaneRowStride(ndkImageRGB, 0, &stride);
241 AImage_getPlaneData(ndkImageRGB, 0, &imageData, &len);
242 LOGI(
"RGB: width=%d, height=%d, bytes=%d stride=%d planeCount=%d", width, height, len, stride, planeCount);
245 if(imageData !=
nullptr && len>0)
247 cv::cvtColor(cv::Mat(height+height/2, width, CV_8UC1, (
void*)imageData), outputRGB, CV_YUV2BGR_NV21);
251 const AImage* ndkImageDepth;
252 HwArImage_getNdkImage(depthImage, &ndkImageDepth);
253 AImage_getNumberOfPlanes(ndkImageDepth, &planeCount);
254 AImage_getWidth(ndkImageDepth, &width);
255 AImage_getHeight(ndkImageDepth, &height);
256 AImage_getPlaneRowStride(ndkImageDepth, 0, &stride);
257 AImage_getPlaneData(ndkImageDepth, 0, &imageData, &len);
258 LOGI(
"Depth: width=%d, height=%d, bytes=%d stride=%d planeCount=%d", width, height, len, stride, planeCount);
260 cv::Mat outputDepth(height, width, CV_16UC1);
262 for (
int y = 0; y < outputDepth.rows; ++y)
264 for (
int x = 0; x < outputDepth.cols; ++x)
266 uint16_t depthSample = dataShort[y*outputDepth.cols + x];
267 uint16_t depthRange = (depthSample & 0x1FFF);
268 outputDepth.at<
uint16_t>(y,x) = depthRange;
272 if(!outputRGB.empty() && !outputDepth.empty())
274 double stamp = double(timestamp_ns)/10e8;
276 data =
SensorData(outputRGB, outputDepth, model, 0, stamp);
281 LOGE(
"CameraAREngine: failed to get rgb image (status=%d %d)", (
int)statusRgb, (
int)statusDepth);
284 HwArImage_release(image);
285 HwArImage_release(depthImage);
289 LOGE(
"Invalid intrinsics!");
293 HwArCamera_release(ar_camera);
297 LOGE(
"CameraAREngine: Pose is null");
322 LOGE(
"CameraARCore::captureImage() ArSession_update error");
326 HwArCamera* ar_camera;
329 HwArTrackingState camera_tracking_state;
330 HwArCamera_getTrackingState(
arSession_, ar_camera, &camera_tracking_state);
334 if(camera_tracking_state == HWAR_TRACKING_STATE_TRACKING)
340 pose =
Transform(pose_raw[4], pose_raw[5], pose_raw[6], pose_raw[0], pose_raw[1], pose_raw[2], pose_raw[3]);
348 HwArCamera_release(ar_camera);
virtual void capturePoseOnly()
void poseReceived(const Transform &pose)
virtual std::string getSerial() const
#define UASSERT(condition)
HwArCameraIntrinsics * arCameraIntrinsics_
static const rtabmap::Transform opengl_world_T_rtabmap_world(0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f)
Transform deviceTColorCamera_
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")
static const rtabmap::Transform rtabmap_world_T_opengl_world(0.0f, 0.0f,-1.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f)
static const rtabmap::Transform opticalRotation
ULogger class and convenient macros.
virtual SensorData captureImage(CameraInfo *info=0)
CameraAREngine(void *env, void *context, void *activity, bool smoothing=false)
virtual ~CameraAREngine()