35 #include <media/NdkImage.h>
48 arInstallRequested_(
false)
73 HwArInstallStatus install_status;
83 HwArEnginesApk_requestInstall(
env_,
activity_, user_requested_install, &install_status);
85 switch (install_status)
87 case HWAR_INSTALL_STATUS_INSTALLED:
89 case HWAR_INSTALL_STATUS_INSTALL_REQUESTED:
122 if (HwArSession_resume(
arSession_) != HWAR_SUCCESS)
124 UERROR(
"Cannot resume camera!");
176 int ret =
static_cast<int>(colorCameraToDisplayRotation) + 1;
181 HwArSession_setDisplayGeometry(
arSession_,
ret, width, height);
200 glBindTexture(GL_TEXTURE_EXTERNAL_OES,
textureId_);
201 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
202 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
203 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
204 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
211 LOGE(
"CameraAREngine::captureImage() ArSession_update error");
220 HwArFrame_transformDisplayUvCoords(
224 UERROR(
"uv: (%f,%f) (%f,%f) (%f,%f) (%f,%f)",
233 HwArCamera* ar_camera;
237 HwArCamera_getProjectionMatrix(
arSession_, ar_camera,
241 HwArTrackingState camera_tracking_state;
242 HwArCamera_getTrackingState(
arSession_, ar_camera, &camera_tracking_state);
244 if(camera_tracking_state == HWAR_TRACKING_STATE_TRACKING)
248 float fx=492.689667,
fy=492.606201,
cx=323.594849,
cy=234.659744;
249 int32_t camWidth=640, camHeight=480;
254 LOGI(
"%f %f %f %f %d %d",
fx,
fy,
cx,
cy, camWidth, camHeight);
256 if(
fx > 0 &&
fy > 0 && camWidth > 0 && camHeight > 0 &&
cx > 0 &&
cy > 0)
261 HwArImage * image =
nullptr;
262 HwArImage * depthImage =
nullptr;
264 HwArStatus statusDepth = HwArFrame_acquireDepthImage(
arSession_,
arFrame_, &depthImage);
265 if(statusRgb == HWAR_SUCCESS && statusDepth == HWAR_SUCCESS)
276 const AImage* ndkImageRGB;
277 HwArImage_getNdkImage(image, &ndkImageRGB);
279 AImage_getNumberOfPlanes(ndkImageRGB, &planeCount);
280 AImage_getWidth(ndkImageRGB, &width);
281 AImage_getHeight(ndkImageRGB, &height);
282 AImage_getPlaneRowStride(ndkImageRGB, 0, &
stride);
283 AImage_getPlaneData(ndkImageRGB, 0, &imageData, &
len);
284 LOGI(
"RGB: width=%d, height=%d, bytes=%d stride=%d planeCount=%d", width, height,
len,
stride, planeCount);
287 if(imageData !=
nullptr &&
len>0)
289 cv::cvtColor(cv::Mat(height+height/2, width, CV_8UC1, (
void*)imageData), outputRGB, cv::COLOR_YUV2BGR_NV21);
293 const AImage* ndkImageDepth;
294 HwArImage_getNdkImage(depthImage, &ndkImageDepth);
295 AImage_getNumberOfPlanes(ndkImageDepth, &planeCount);
296 AImage_getWidth(ndkImageDepth, &width);
297 AImage_getHeight(ndkImageDepth, &height);
298 AImage_getPlaneRowStride(ndkImageDepth, 0, &
stride);
299 AImage_getPlaneData(ndkImageDepth, 0, &imageData, &
len);
300 LOGI(
"Depth: width=%d, height=%d, bytes=%d stride=%d planeCount=%d", width, height,
len,
stride, planeCount);
302 cv::Mat outputDepth(height, width, CV_16UC1);
304 for (
int y = 0;
y < outputDepth.rows; ++
y)
306 for (
int x = 0;
x < outputDepth.cols; ++
x)
308 uint16_t depthSample = dataShort[
y*outputDepth.cols +
x];
309 uint16_t depthRange = (depthSample & 0x1FFF);
314 if(!outputRGB.empty() && !outputDepth.empty())
316 double stamp = double(timestamp_ns)/10e8;
324 pose =
Transform(pose_raw[4], pose_raw[5], pose_raw[6], pose_raw[0], pose_raw[1], pose_raw[2], pose_raw[3]);
327 LOGE(
"CameraAREngine: Pose is null");
338 LOGE(
"CameraAREngine: failed to get rgb image (status=%d %d)", (
int)statusRgb, (
int)statusDepth);
341 HwArImage_release(image);
342 HwArImage_release(depthImage);
346 LOGE(
"Invalid intrinsics!");
350 HwArCamera_release(ar_camera);