我从项目的NDK端从ARCore那里得到了NDK_Image。 我的AI法师因为相机方向而旋转。
如何在 NDK 中获取相机方向的值?
在相机 NDK 文档中,我发现了这个ACAMERA_JPEG_ORIENTATION
它甚至给出了一个代码示例:
private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) {
if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0;
int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Round device orientation to a multiple of 90
deviceOrientation = (deviceOrientation + 45) / 90 * 90;
// Reverse device orientation for front-facing cameras
boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT;
if (facingFront) deviceOrientation = -deviceOrientation;
// Calculate desired JPEG orientation relative to camera orientation to make
// the image upright relative to the device orientation
int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360;
return jpegOrientation;
}
但它没有解释如何使用,我找不到CameraCharascteristics
的图书馆.
将是一个很好的示例,介绍如何在 NDK 中获取相机方向。谢谢!
这个 Java 中的示例代码是错误的。
从 C++ 中,您可以使用标签 ACAMERA_SENSOR_ORIENTATION 调用ACameraManager_getCameraCharacteristics()并标记ACAMERA_LENS_FACING。
OrientationEventListener.ORIENTATION_UNKNOWN
是一个常数 -1。CameraCharacteristics.LENS_FACING_FRONT
或ACAMERA_LENS_FACING_FRONT0
.