mirror of
https://github.com/introlab/rtabmap.git
synced 2026-10-08 02:57:46 +08:00
android: fixed yuv conversion bug on some devices, updated default driver based on which one is available and built with it.
This commit is contained in:
@@ -431,7 +431,6 @@ public class ARCoreSharedCamera {
|
||||
|
||||
/*************************************************** ONDRAWFRAME ARCORE ************************************************************* */
|
||||
|
||||
|
||||
// Draw frame when in AR mode. Called on the GL thread.
|
||||
public void updateGL() throws CameraNotAvailableException {
|
||||
|
||||
@@ -498,11 +497,14 @@ public class ARCoreSharedCamera {
|
||||
float[] fl = intrinsics.getFocalLength();
|
||||
float[] pp = intrinsics.getPrincipalPoint();
|
||||
if(!RTABMapActivity.DISABLE_LOG) Log.d(TAG, String.format("fx=%f fy=%f cx=%f cy=%f", fl[0], fl[1], pp[0], pp[1]));
|
||||
ByteBuffer rgb = image.getPlanes()[0].getBuffer().asReadOnlyBuffer();
|
||||
|
||||
ByteBuffer y = image.getPlanes()[0].getBuffer().asReadOnlyBuffer();
|
||||
ByteBuffer u = image.getPlanes()[1].getBuffer().asReadOnlyBuffer();
|
||||
ByteBuffer v = image.getPlanes()[2].getBuffer().asReadOnlyBuffer();
|
||||
|
||||
double stamp = (double)image.getTimestamp()/10e8;
|
||||
if(!RTABMapActivity.DISABLE_LOG) Log.d(TAG, String.format("RGB %dx%d len=%dbytes format=%d =%f",
|
||||
image.getWidth(), image.getHeight(), rgb.limit(), image.getFormat(), stamp));
|
||||
image.getWidth(), image.getHeight(), y.limit(), image.getFormat(), stamp));
|
||||
|
||||
if(mTOFAvailable)
|
||||
{
|
||||
@@ -513,9 +515,9 @@ public class ARCoreSharedCamera {
|
||||
RTABMapActivity.nativeApplication,
|
||||
pose.tx(), pose.ty(), pose.tz(), pose.qx(), pose.qy(), pose.qz(), pose.qw(),
|
||||
fl[0], fl[1], pp[0], pp[1], stamp,
|
||||
rgb, rgb.limit(), image.getWidth(), image.getHeight(), image.getFormat(),
|
||||
y, u, v, y.limit(), image.getWidth(), image.getHeight(), image.getFormat(),
|
||||
mTOFImageReader.depth16_raw, mTOFImageReader.depth16_raw.limit(), mTOFImageReader.WIDTH, mTOFImageReader.HEIGHT, ImageFormat.DEPTH16,
|
||||
points, points.limit());
|
||||
points, points.limit()/4);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -524,7 +526,7 @@ public class ARCoreSharedCamera {
|
||||
RTABMapActivity.nativeApplication,
|
||||
pose.tx(), pose.ty(), pose.tz(), pose.qx(), pose.qy(), pose.qz(), pose.qw(),
|
||||
fl[0], fl[1], pp[0], pp[1], stamp,
|
||||
rgb, rgb.limit(), image.getWidth(), image.getHeight(), image.getFormat(),
|
||||
y, u, v, y.limit(), image.getWidth(), image.getHeight(), image.getFormat(),
|
||||
bb, 0, 0, 0, ImageFormat.DEPTH16,
|
||||
points, points.limit()/4);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.MemoryInfo;
|
||||
import android.app.AlertDialog;
|
||||
@@ -59,9 +58,7 @@ import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.text.Html;
|
||||
import android.text.InputType;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ContextMenu;
|
||||
@@ -90,7 +87,6 @@ import android.widget.NumberPicker;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
@@ -586,6 +582,10 @@ public class RTABMapActivity extends FragmentActivity implements OnClickListener
|
||||
postCreate();
|
||||
}
|
||||
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String cameraDriverStr = sharedPref.getString(getString(R.string.pref_key_camera_driver), getString(R.string.pref_default_camera_driver));
|
||||
mCameraDriver = Integer.parseInt(cameraDriverStr);
|
||||
|
||||
isArCoreAvailable();
|
||||
isArEngineAvailable();
|
||||
}
|
||||
@@ -607,6 +607,60 @@ public class RTABMapActivity extends FragmentActivity implements OnClickListener
|
||||
mButtonLibrary.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCameraDriverSettings()
|
||||
{
|
||||
Log.i(TAG, String.format("updateCameraDriverSettings() mCameraDriver=%d RTABMapLib.isBuiltWith(%d)=%d", mCameraDriver, mCameraDriver, RTABMapLib.isBuiltWith(nativeApplication, mCameraDriver)?1:0));
|
||||
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
if(mCameraDriver == 0 && (!CheckTangoCoreVersion(MIN_TANGO_CORE_VERSION) || !RTABMapLib.isBuiltWith(nativeApplication, 0)))
|
||||
{
|
||||
if(mIsAREngineAvailable && RTABMapLib.isBuiltWith(nativeApplication, 2))
|
||||
{
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(getString(R.string.pref_key_camera_driver), "2");
|
||||
editor.commit();
|
||||
}
|
||||
else if(mIsARCoreAvailable)
|
||||
{
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(getString(R.string.pref_key_camera_driver), "3");
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
else if(((mCameraDriver == 1 && (!RTABMapLib.isBuiltWith(nativeApplication, 0) || !mIsARCoreAvailable)) ||
|
||||
(mCameraDriver == 3 && !mIsARCoreAvailable)))
|
||||
{
|
||||
if(CheckTangoCoreVersion(MIN_TANGO_CORE_VERSION) && RTABMapLib.isBuiltWith(nativeApplication, 0))
|
||||
{
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(getString(R.string.pref_key_camera_driver), "0");
|
||||
editor.commit();
|
||||
}
|
||||
else if(mIsAREngineAvailable && RTABMapLib.isBuiltWith(nativeApplication, 2))
|
||||
{
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(getString(R.string.pref_key_camera_driver), "2");
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
else if(mCameraDriver == 2 && (!mIsAREngineAvailable || !RTABMapLib.isBuiltWith(nativeApplication, 2)))
|
||||
{
|
||||
if(CheckTangoCoreVersion(MIN_TANGO_CORE_VERSION) && RTABMapLib.isBuiltWith(nativeApplication, 0))
|
||||
{
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(getString(R.string.pref_key_camera_driver), "0");
|
||||
editor.commit();
|
||||
}
|
||||
else if(mIsARCoreAvailable)
|
||||
{
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(getString(R.string.pref_key_camera_driver), "3");
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void isArCoreAvailable() {
|
||||
ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(this);
|
||||
@@ -622,9 +676,11 @@ public class RTABMapActivity extends FragmentActivity implements OnClickListener
|
||||
if (availability.isSupported()) {
|
||||
Log.i(TAG, "ARCore supported");
|
||||
mIsARCoreAvailable = true;
|
||||
updateCameraDriverSettings();
|
||||
} else { // Unsupported or unknown.
|
||||
Log.i(TAG, "ARCore supported");
|
||||
mIsARCoreAvailable = false;
|
||||
updateCameraDriverSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,9 +699,11 @@ public class RTABMapActivity extends FragmentActivity implements OnClickListener
|
||||
if (availability.isSupported()) {
|
||||
Log.i(TAG, "AREngine supported");
|
||||
mIsAREngineAvailable = true;
|
||||
updateCameraDriverSettings();
|
||||
} else { // Unsupported or unknown.
|
||||
Log.i(TAG, "AREngine not supported");
|
||||
mIsAREngineAvailable = false;
|
||||
updateCameraDriverSettings();
|
||||
}
|
||||
}
|
||||
catch(UnsatisfiedLinkError e)
|
||||
@@ -1069,6 +1127,8 @@ public class RTABMapActivity extends FragmentActivity implements OnClickListener
|
||||
case PermissionHelper.CAMERA_CODE: {
|
||||
if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// permission was granted, yay!
|
||||
startCamera(String.format("Hold Tight! Initializing Camera Service...\n"
|
||||
+ "Tip: If the camera is still drifting just after the mapping has started, do \"Reset\"."));
|
||||
} else {
|
||||
Toast.makeText(this, "Camera permission is needed for scanning and motion tracking.", Toast.LENGTH_LONG).show();
|
||||
if (!PermissionHelper.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
|
||||
|
||||
@@ -37,13 +37,8 @@ public class RTABMapLib
|
||||
public static native int openDatabase(long nativeApplication, String databasePath, boolean databaseInMemory, boolean optimize);
|
||||
public static native int openDatabase2(long nativeApplication, String databaseSource, String databasePath, boolean databaseInMemory, boolean optimize);
|
||||
|
||||
/*
|
||||
* Called when the camera service is connected.
|
||||
*
|
||||
* @param binder The native binder object.
|
||||
*/
|
||||
public static native boolean isBuiltWith(long nativeApplication, int cameraDriver);
|
||||
public static native boolean startCamera(long nativeApplication, IBinder binder, Context context, Activity activity, int driver);
|
||||
|
||||
public static native void stopCamera(long nativeApplication);
|
||||
|
||||
// Allocate OpenGL resources for rendering.
|
||||
@@ -143,7 +138,7 @@ public class RTABMapLib
|
||||
float x, float y, float z, float qx, float qy, float qz, float qw,
|
||||
float fx, float fy, float cx, float cy,
|
||||
double stamp,
|
||||
ByteBuffer rgb, int rgbLen, int rgbWidth, int rgbHeight, int rgbFormat,
|
||||
ByteBuffer yPlane, ByteBuffer uPlane, ByteBuffer vPlane, int yPlaneLen, int rgbWidth, int rgbHeight, int rgbFormat,
|
||||
ByteBuffer depth, int depthLen, int depthWidth, int depthHeight, int depthFormat,
|
||||
FloatBuffer points, int pointsLen);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user