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 GLRsSurfaceView not showing a single Frame #11740

Closed
electro-logic opened this issue Apr 27, 2023 · 8 comments
Closed

Android GLRsSurfaceView not showing a single Frame #11740

electro-logic opened this issue Apr 27, 2023 · 8 comments
Labels

Comments

@electro-logic
Copy link

Hello,

This code is working

var frames = _pipeline.WaitForFrames().ReleaseWith(fr).As(Extension.Frameset) as FrameSet
_glSurfaceView1.Upload(frames);

But if I want to display only the Depth frame

var depthFrame = frames.First(StreamType.Depth).ReleaseWith(fr).As(Extension.DepthFrame) as DepthFrame
_glSurfaceView1.Upload(depthFrame);

this code is not showing anything. Is this a bug?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Apr 28, 2023

Hi @electro-logic Are you able to achieve the depth stream on its own if you define a custom config stream configuration like in #11670 so that only the depth stream is enabled and the color stream is not? If config instructions are not defined then the SDK will enable both the depth and color streams by default.

@electro-logic
Copy link
Author

Hello, by enabling the Depth stream only, I can see only that frame. But I need to record the Color and the IR stream too (without displaying them).

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Apr 28, 2023

I wonder whether you could configure two separate pipelines, each with their own config instruction sets (such as 'config1' and 'config2'), and put depth on 'pipeline1' and color + IR on 'pipeline2'. #1735 (comment) has an example of this method in Python whose structure should be convertable to Android instructions, since you know how to define a pipeline and a config instruction.

Having set up individual pipelines, you would then have two pipeline start lines for 'pipeline1' and 'pipeline2'.

@electro-logic
Copy link
Author

I need frames to be synchronized and, though may work, this looks like a workaround. Any chance to get this fixed?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Apr 29, 2023

I am not aware of a past example of a RealSense Android case in which the visual rendering of one stream type has successfully been disabled whilst the other is enabled. So I do not have an alternative suggestion, unfortunately.

@electro-logic
Copy link
Author

I can always process the depth data and create a bitmap without the GLRsSurfaceView, I will try this way.

@electro-logic
Copy link
Author

electro-logic commented Apr 29, 2023

Hello, at the end I solved in this way (pseudocode)

byte[] depthData = new byte[IMAGE_WIDTH * IMAGE_HEIGHT * 2];
int[] depthDataARGB = new int[IMAGE_WIDTH * IMAGE_HEIGHT];
depthFrame.GetData(depthData);
Bitmap bmp = Bitmap.CreateBitmap(IMAGE_WIDTH, IMAGE_HEIGHT, Bitmap.Config.Argb8888, false);

// Convert Z16 to ARGB888
for (int indexRgb24 = 0; indexRgb24 < IMAGE_WIDTH * IMAGE_HEIGHT; indexRgb24++)
{
    var offsetDepth = indexRgb24 * 2;                                
    short depth = (short)(depthData[offsetDepth] | (depthData[offsetDepth + 1] << 8));
    byte intensity = (byte)(depth / (double)short.MaxValue * 255.0);
    depthDataARGB[indexRgb24] = intensity | (intensity << 8) | (intensity << 16) | (255 << 24);
}
bmp.SetPixels(depthDataARGB, 0, IMAGE_WIDTH, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
_imageView1.SetImageBitmap(bmp);

where the for loop can be parallelized and some variables (ex. bmp and arrays) can be cached for better performance.
Thanks anyway for the support

@MartyG-RealSense
Copy link
Collaborator

No problem at all, @electro-logic - I'm pleased to hear that you achieved a solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants