IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.55k stars 4.81k forks source link

How to implement PostProcessing like Spatial/Temporal/DecimationFilter in Unity #1898

Closed Jerice closed 6 years ago

Jerice commented 6 years ago

https://github.com/IntelRealSense/librealsense/issues/1572


Required Info
Camera Model D415
Firmware Version 05.09.09.02
Operating System & Version Win 10
Kernel Version (Linux Only)
Platform PC
SDK Version lastest
Language unity(c#)

Issue Description

Hi, I want to implement the filter of the SDK in Unity. Is that possible? I have tried to add this filters with no success. Thanks!

RealSense-Customer-Engineering commented 6 years ago

[Realsense Customer Engineering Team Comment] @Jerice Attached my way to implement new post processing block for Unity.

carypai commented 6 years ago

Unity_PostProcessing_sample.zip

Akthree commented 6 years ago

Hey Guys, I also was looking forward to implement the post-processing filters inside my Unity Project. But i cant quite follow your instructions given.

First to implement the customized post processing inside C# by leveraging the class of "CustomProcessingBlock", and then compile this class as one of the Intel.RealSense.dll.

What do I need to put inside where? Can you please provide a little more details for this particular step? The second Question is: Do i just attach the CustomProcessorDemo.cs as Component on my GameObjects or is it a more global approach? I am very thankful for the support but i would also like to understand what i need to do :D

RealSense-Customer-Engineering commented 6 years ago

[Realsense Customer Engineering Team Comment] @Akthree After unzip the package, follow the instruction below :

  1. Copy the "CustomProcessor.cs" to /wrappers/csharp/Intel.RealSense (optional, you can add the existing item from anywhere in your system in step 2)
  2. In visual stuido, add existing item (CustomProcessor.cs) from Intel.RealSense project, then build it. Two main dll files will be generated, realsense2.dll, Intel.RealSense.dll
  3. Create "Plugin.Managed" folder under /wrappers/unity/Assets, then copy the "Intel.RealSense.dll" generated in step 2 to this folder.
  4. Create "Plugins" folder under /wrappers/unity/Assets/RealSenseSKD2.0, then copy the "realsense2.dll" generated in step 2 to this folder.

For how to use in Unity, since I am not very familiar with it, I just modify the "Color" object inside StreamsTexture (in Asset/RealSenseSDK2.0/Scenes/RealSenseTextures) for testing. The way should be the first way you mentioned, to add the GameObject then attach the CustomerProcessorDemo as its component.

Akthree commented 6 years ago

@RealSense-Customer-Engineering
Thanks for the help! So i got it all working properly but i still aint getting anywhere. I attached the CustomerProcessorDemo-Script on the Color StreamsTexture just like you mentioned and its all working just fine but when i attach it to the Depth StreamsTexture it is somehow breaking the pipeline and there is no useful output.

I also digged a little deeper inside the c# wrapper examples and got a little bit of an insight on how to implement postprocessing. But just to be clear the CustomerProcessorDemo.cs file currently is not doing a lot exept breaking the depth channel. Can someone provide a little more information on how to expose the filters inside the CustomProcessor and how to manipulate the values compared to the C++ postProcessing example or the Realsense-Viewer? So if someone can tell me how to expose and apply the filters inside given Demo i would be glad to work on a better implementation for Unity.

RealSense-Customer-Engineering commented 6 years ago

[Realsense Customer Engineering Team Comment] @Akthree The example I show you intended to let the script inside Unity do as simple work as possible and left the manipulation of frame inside the C#.

In the C# CustomProcessor.cs, the processingFrame is the callback function send to the CustomProcessingBlock instance, which will be invoked once you call the "block.ProcessingFrames(frames)". So what you want to do for your own filter should be implemented inside this processingFrame callback function, after you have done the manipulation for the frames, you can allocate new frames using the "FrameSource" instance then move the newly allocated frames to queue by calling the "source.FrameReady(frame)"

For more detailed information, please refer to the "cs-tutorial-3-processing" project inside the latest LibRS csharp wrapper.

RealSense-Customer-Engineering commented 6 years ago

[Realsense Customer Engineering Team Comment] @Akthree Does the response help?