Cannot detect D435i on Android always
Hi,
I am using D435i on Android.
If I use the Android example such as the Capture app, the camera can be detected successfully.
I follow this example and copy the following code from the Capture app to my app.
However, sometimes the camera can be detected but sometimes not.
In the app build.gradle I use the same compileSdkVersion, targetSdkVersion as the Capture example.
Any help are really appreciated!
Best,
Yixun
private void init(){
//RsContext.init must be called once in the application lifetime before any interaction with physical RealSense devices.
//For multi activities applications use the application context instead of the activity context
RsContext.init(mAppContext);
//Register to notifications regarding RealSense devices attach/detach events via the DeviceListener.
mRsContext = new RsContext();
mRsContext.setDevicesChangedCallback(mListener);
mPipeline = new Pipeline();
mColorizer = new Colorizer();
try(DeviceList dl = mRsContext.queryDevices()){
if(dl.getDeviceCount() > 0) {
Log.d(TAG, "The connected devices num is; " + dl.getDeviceCount());
showConnectLabel(false);
start();
}
}
}
-
Hi Yixun Liu Assuming that your app can run without the camera permissions checking code that the Capture example has, the next step you could try is to add the camera attach / detach device listener code from Capture into your script (lines 130-141).
-
Thanks for your reply.
I do have the camera attach/detach code and it works. If I detach the camera I will see a warning and if I attach the camera the warning does not show.
I comment out the following code since my device has Android 11.
The difference from the example is except for the Depth camera I also use the tablet's camera. Before detecting the depth camera I start streaming of the tablet's camera. Does this cause the issue?
Thank you so much!
Best,
Yixun
// Android 9 also requires camera permissions
//if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.O &&
// ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
//ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSIONS_REQUEST_CAMERA);
//return;
//} -
If the original Capture example detects the D435i camera consistently but your version that adds streaming from the Android device's own RGB camera causes problems then it is certainly worth focusing on that aspect of the project as a priority.
I note that you seem to have removed the config.enableStream instructions in your version of the script. Stream configuration instructions enable you to specify exactly which streams should be enabled. If custom configuration instructions are absent then the D435i camera will use its default configuration (Depth + RGB).
So if you only want the Depth stream of the RealSense camera to be accessed and you are not using the RealSense camera's RGB then I suggest putting the config instructions back in your script but only including the Depth stream definition and leaving the Color one out so that RGB is ignored.
-
I add config.enableStream and comment out the follow code:
config.enableStream(StreamType.COLOR, 640, 480);
But it still does not work.
I did some tests. I use a checkbox to start
initDepthCamera()
rather than doing it in onResume.
As I check the checkbox I call initDepthCamera and as I uncheck the checkbok I call stop(). The first time I check the checkbox the camera cannot be detected. But it can be detected as I check the box second time.
Hope this information can help you to find the reason.
Thank you so much!
-
Is your initDepthCamera() code based on the init() code in the Capture example, which states in the comment notes: "RsContext.init must be called once in the application lifetime before any interaction with physical RealSense devices. For multi activities applications use the application context instead of the activity context".
Please sign in to leave a comment.
Comments
7 comments