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:
120 if (HwArSession_resume(
arSession_) != HWAR_SUCCESS)
122 UERROR(
"Cannot resume camera!");
174 int ret =
static_cast<int>(colorCameraToDisplayRotation) + 1;
179 HwArSession_setDisplayGeometry(
arSession_,
ret, width, height);
198 glBindTexture(GL_TEXTURE_EXTERNAL_OES,
textureId_);
199 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
200 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
201 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
202 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
209 LOGE(
"CameraAREngine::captureImage() ArSession_update error");
218 HwArFrame_transformDisplayUvCoords(
222 UERROR(
"uv: (%f,%f) (%f,%f) (%f,%f) (%f,%f)",
231 HwArCamera* ar_camera;
235 HwArCamera_getProjectionMatrix(
arSession_, ar_camera,
245 HwArTrackingState camera_tracking_state;
246 HwArCamera_getTrackingState(
arSession_, ar_camera, &camera_tracking_state);
248 if(camera_tracking_state == HWAR_TRACKING_STATE_TRACKING)
252 float fx=492.689667,
fy=492.606201,
cx=323.594849,
cy=234.659744;
253 int32_t camWidth=640, camHeight=480;
258 LOGI(
"%f %f %f %f %d %d",
fx,
fy,
cx,
cy, camWidth, camHeight);
260 if(
fx > 0 &&
fy > 0 && camWidth > 0 && camHeight > 0 &&
cx > 0 &&
cy > 0)
265 HwArImage * image =
nullptr;
266 HwArImage * depthImage =
nullptr;
268 HwArStatus statusDepth = HwArFrame_acquireDepthImage(
arSession_,
arFrame_, &depthImage);
269 if(statusRgb == HWAR_SUCCESS && statusDepth == HWAR_SUCCESS)
280 const AImage* ndkImageRGB;
281 HwArImage_getNdkImage(image, &ndkImageRGB);
283 AImage_getNumberOfPlanes(ndkImageRGB, &planeCount);
284 AImage_getWidth(ndkImageRGB, &width);
285 AImage_getHeight(ndkImageRGB, &height);
286 AImage_getPlaneRowStride(ndkImageRGB, 0, &
stride);
287 AImage_getPlaneData(ndkImageRGB, 0, &imageData, &
len);
288 LOGI(
"RGB: width=%d, height=%d, bytes=%d stride=%d planeCount=%d", width, height,
len,
stride, planeCount);
291 if(imageData !=
nullptr &&
len>0)
293 cv::cvtColor(cv::Mat(height+height/2, width, CV_8UC1, (
void*)imageData), outputRGB, cv::COLOR_YUV2BGR_NV21);
297 const AImage* ndkImageDepth;
298 HwArImage_getNdkImage(depthImage, &ndkImageDepth);
299 AImage_getNumberOfPlanes(ndkImageDepth, &planeCount);
300 AImage_getWidth(ndkImageDepth, &width);
301 AImage_getHeight(ndkImageDepth, &height);
302 AImage_getPlaneRowStride(ndkImageDepth, 0, &
stride);
303 AImage_getPlaneData(ndkImageDepth, 0, &imageData, &
len);
304 LOGI(
"Depth: width=%d, height=%d, bytes=%d stride=%d planeCount=%d", width, height,
len,
stride, planeCount);
306 cv::Mat outputDepth(height, width, CV_16UC1);
308 for (
int y = 0;
y < outputDepth.rows; ++
y)
310 for (
int x = 0;
x < outputDepth.cols; ++
x)
312 uint16_t depthSample = dataShort[
y*outputDepth.cols +
x];
313 uint16_t depthRange = (depthSample & 0x1FFF);
318 if(!outputRGB.empty() && !outputDepth.empty())
320 double stamp = double(timestamp_ns)/10e8;
328 pose =
Transform(pose_raw[4], pose_raw[5], pose_raw[6], pose_raw[0], pose_raw[1], pose_raw[2], pose_raw[3]);
331 LOGE(
"CameraAREngine: Pose is null");
347 LOGE(
"CameraAREngine: failed to get rgb image (status=%d %d)", (
int)statusRgb, (
int)statusDepth);
350 HwArImage_release(image);
351 HwArImage_release(depthImage);
355 LOGE(
"Invalid intrinsics!");
359 HwArCamera_release(ar_camera);