Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android intrisics extrinsics added to wrapper #6594

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions src/android/jni/stream_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,129 @@ Java_com_intel_realsense_librealsense_StreamProfile_nIsProfileExtendableTo(JNIEn
handle_error(env, e);
return rv;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_StreamProfile_nGetExtrinsicsTo(JNIEnv *env, jclass type,
jlong handle, jlong otherHandle, jobject extrinsics) {
rs2_error* e = nullptr;
rs2_extrinsics extr;
rs2_get_extrinsics(reinterpret_cast<const rs2_stream_profile *>(handle),
reinterpret_cast<const rs2_stream_profile *>(otherHandle),&extr, &e);
handle_error(env, e);

if (e != nullptr)
{
return;
}

jclass clazz = env->GetObjectClass(extrinsics);

//retrieving the array members
//mRotation
jfieldID rotation_field = env->GetFieldID(clazz, "mRotation", "[F");
jfloatArray rotationArray = env->NewFloatArray(9);
if (rotationArray != NULL)
{
env->SetFloatArrayRegion(rotationArray, 0, 9, reinterpret_cast<jfloat*>(&extr.rotation));
}
env->SetObjectField(extrinsics, rotation_field, rotationArray);

//mTranslation
jfieldID translation_field = env->GetFieldID(clazz, "mTranslation", "[F");
jfloatArray translationArray = env->NewFloatArray(3);
if (translationArray != NULL)
{
env->SetFloatArrayRegion(translationArray, 0, 3, reinterpret_cast<jfloat*>(&extr.translation));
}
env->SetObjectField(extrinsics, translation_field, translationArray);
}

extern "C"
JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_VideoStreamProfile_nGetIntrinsics(JNIEnv *env, jclass type,
jlong handle, jobject intrinsics) {
rs2_error* e = nullptr;
rs2_intrinsics intr;
rs2_get_video_stream_intrinsics(reinterpret_cast<const rs2_stream_profile *>(handle), &intr, &e);
handle_error(env, e);

if (e != nullptr)
{
return;
}

jclass clazz = env->GetObjectClass(intrinsics);

//retrieving all the built-in types members
jfieldID width_field = env->GetFieldID(clazz, "mWidth", "I");
jfieldID height_field = env->GetFieldID(clazz, "mHeight", "I");
jfieldID ppx_field = env->GetFieldID(clazz, "mPpx", "F");
jfieldID ppy_field = env->GetFieldID(clazz, "mPpy", "F");
jfieldID fx_field = env->GetFieldID(clazz, "mFx", "F");
jfieldID fy_field = env->GetFieldID(clazz, "mFy", "F");
jfieldID model_field = env->GetFieldID(clazz, "mModelValue", "I");


env->SetIntField(intrinsics, width_field, intr.width);
env->SetIntField(intrinsics, height_field, intr.height);
env->SetFloatField(intrinsics, ppx_field, intr.ppx);
env->SetFloatField(intrinsics, ppy_field, intr.ppy);
env->SetFloatField(intrinsics, fx_field, intr.fx);
env->SetFloatField(intrinsics, fy_field, intr.fy);
env->SetIntField(intrinsics, model_field, intr.model);

//retrieving the array member
jfieldID coeff_field = env->GetFieldID(clazz, "mCoeffs", "[F");
jfloatArray coeffsArray = env->NewFloatArray(5);
if (coeffsArray != NULL)
{
env->SetFloatArrayRegion(coeffsArray, 0, 5, reinterpret_cast<jfloat*>(&intr.coeffs));
}
env->SetObjectField(intrinsics, coeff_field, coeffsArray);
}

extern "C"
JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_MotionStreamProfile_nGetIntrinsics(JNIEnv *env, jclass type,
jlong handle, jobject intrinsics) {
rs2_error* e = nullptr;
rs2_motion_device_intrinsic intr;
rs2_get_motion_intrinsics(reinterpret_cast<const rs2_stream_profile *>(handle), &intr, &e);
handle_error(env, e);

if (e != nullptr)
{
return;
}

jclass clazz = env->GetObjectClass(intrinsics);

//retrieving the array members
//mData
jfieldID data_field = env->GetFieldID(clazz, "mData", "[F");
jfloatArray dataArray = env->NewFloatArray(12);
if (dataArray != NULL)
{
env->SetFloatArrayRegion(dataArray, 0, 12, reinterpret_cast<jfloat*>(&intr.data));
}
env->SetObjectField(intrinsics, data_field, dataArray);

//mNoiseVariances
jfieldID noise_field = env->GetFieldID(clazz, "mNoiseVariances", "[F");
jfloatArray noiseArray = env->NewFloatArray(3);
if (noiseArray != NULL)
{
env->SetFloatArrayRegion(noiseArray, 0, 3, reinterpret_cast<jfloat*>(&intr.noise_variances));
}
env->SetObjectField(intrinsics, noise_field, noiseArray);

//mBiasVariances
jfieldID bias_field = env->GetFieldID(clazz, "mBiasVariances", "[F");
jfloatArray biasArray = env->NewFloatArray(3);
if (biasArray != NULL)
{
env->SetFloatArrayRegion(biasArray, 0, 3, reinterpret_cast<jfloat*>(&intr.bias_variances));
}
env->SetObjectField(intrinsics, bias_field, biasArray);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.intel.realsense.librealsense;

public enum DistortionType {
NONE(0),
MODIFIED_BROWN_CONRADY(1),
INVERSE_BROWN_CONRADY(2),
FTHETA(3),
BROWN_CONRADY(4),
KANNALA_BRANDT4(5),
COUNT(6);

private final int mValue;

DistortionType(int value) { mValue = value; }
public int value() { return mValue; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.intel.realsense.librealsense;

public class Extrinsics {
remibettan marked this conversation as resolved.
Show resolved Hide resolved

private float[] mRotation; // Column-major 3x3 rotation matrix
private float[] mTranslation; // Three-element translation vector, in meters

public Extrinsics(){
mRotation = new float[9];
mTranslation = new float[3];
}

public Extrinsics(float[] rotation, float[] translation){
this.mRotation = rotation;
this.mTranslation = translation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.intel.realsense.librealsense;

public class Intrinsics {
remibettan marked this conversation as resolved.
Show resolved Hide resolved
private int mWidth;
private int mHeight;
private float mPpx;
private float mPpy;
private float mFx;
private float mFy;
private DistortionType mModel;
private int mModelValue;
private float[] mCoeffs;


public Intrinsics(){
mCoeffs = new float[5];
}

public Intrinsics(int width,int height,
float ppx, float ppy,
float fx, float fy,
int model,
float[] coeffs){
this.mWidth = width;
this.mHeight = height;
this.mPpx = ppx;
this.mPpy = ppy;
this.mFx = fx;
this.mFy = fy;
this.mModel = DistortionType.values()[model];
this.mModelValue = model;
this.mCoeffs = coeffs;
}

public void SetModel(){
this.mModel = DistortionType.values()[mModelValue];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.intel.realsense.librealsense;

public class MotionIntrinsics {

/* mData matrix description:
* Scale X cross axis cross axis Bias X \n
* cross axis Scale Y cross axis Bias Y \n
* cross axis cross axis Scale Z Bias Z */
private float[][] mData;
private float[] mNoiseVariances; // Variance of noise for X, Y, and Z axis
private float[] mBiasVariances; // Variance of bias for X, Y, and Z axis


public MotionIntrinsics(){
mData = new float[3][4];
mNoiseVariances = new float[3];
mBiasVariances = new float[3];
}

public MotionIntrinsics(float[][] data, float[] noiseVariances, float[] biasVariances){
this.mData = data;
this.mNoiseVariances = noiseVariances;
this.mBiasVariances = biasVariances;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package com.intel.realsense.librealsense;

public class MotionStreamProfile extends StreamProfile {

private MotionIntrinsics mIntrinsics;

MotionStreamProfile(long handle) {
super(handle);
mOwner = false;
mIntrinsics = null;
}

public MotionIntrinsics getIntrinsics() throws Exception {
if(mIntrinsics == null){
mIntrinsics = new MotionIntrinsics();
nGetIntrinsics(mHandle, mIntrinsics);
}
return mIntrinsics;
}

private static native void nGetIntrinsics(long handle, MotionIntrinsics intrinsics);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public int getFrameRate() {
return mPp.frameRate;
}

public Extrinsics getExtrinsicsTo(StreamProfile other) throws Exception {
Extrinsics extrinsics = new Extrinsics();
nGetExtrinsicsTo(mHandle, other.mHandle, extrinsics);
return extrinsics;
}

public boolean is(Extension extension) {
return nIsProfileExtendableTo(mHandle, extension.value());
}
Expand All @@ -64,4 +70,5 @@ public void close() {
private static native boolean nIsProfileExtendableTo(long handle, int extension);
private static native void nGetProfile(long handle, ProfileParams params);
private static native void nDelete(long handle);
private static native void nGetExtrinsicsTo(long handle, long otherHandle, Extrinsics extrinsics);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class VideoStreamProfile extends StreamProfile {
ResolutionParams mResolutionParams;
private Intrinsics mIntrinsics;

private class ResolutionParams {
public int width;
Expand All @@ -13,6 +14,16 @@ private class ResolutionParams {
mOwner = false;
mResolutionParams = new ResolutionParams();
nGetResolution(mHandle, mResolutionParams);
mIntrinsics = null;
}

public Intrinsics getIntrinsics() throws Exception {
if(mIntrinsics == null){
mIntrinsics = new Intrinsics();
nGetIntrinsics(mHandle, mIntrinsics);
mIntrinsics.SetModel();
}
return mIntrinsics;
}

public int getWidth() {
Expand All @@ -24,4 +35,5 @@ public int getHeight() {
}

private static native void nGetResolution(long handle, ResolutionParams params);
private static native void nGetIntrinsics(long handle, Intrinsics intrinsics);
remibettan marked this conversation as resolved.
Show resolved Hide resolved
}