-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Setting persistency index in temporal filter with pyrealsense2 has no effect #10078
Comments
Hi @amirf147 May I first ask if you have defined a value for persistency_index so that the script knows which of the persistency modes (0-8) to apply, please? The effect that is applied with modes 1-8 is described in the official pyrealsense2 documentation link below. Intel's post-processing guide in the link below defines '0' as "Disabled - The Persistency filter is not activated and no hole filling occurs". If a float variable persistency_index was defined but a value not stored in it then I would speculate that the value of the variable would default to '0' - where the Persistency filter is not activated. |
Yes i defined a value for persistency_index and i tried all the values from 0 to 8. I was also able to confirm that the value was loaded to the option with the print statement that i showed. Still, no effect was observed. |
And you have placed your filter instructions after the pipe start instruction like in #1672 (comment) ? Would it be possible to post your full Python script into a comment, please? |
camera_setup.py class RealSenseCamera:
opencv_stream.py ros_bag = "C:\Users\35840\Documents\20211217_204044.bag" camera = RealSenseCamera(ros_bag) try:
finally: |
hopefully you can understand that. for some reason not everything stayed in the code block. the program works without errors and displays the frames. just the filter is not applied, or atleast, setting and changing the persistency_index variable is not resulting in any changes in the final frame. When playing the ros bag file with realsense-viewer, changing the persistency mode values does show significant changes to the stream. It seems that changing it in the python code and viewing the frames through opencv does not show any effect though. |
applying the other filters in the python code does work though, or at least they have some noticeable effects which would cause me to conclude that they are working. the only one not seeming to work is the temporal filter. also, the double back slashes are present in the ros_bag path but just seem to get cut out after pasting here. |
The first observation I would make about your script is that it is recommended that align is applied after post-processing filters are applied. If alignment is done before post-processing then it can result in issues such as 'aliasing' distortion (jagged lines). Also, Intel recommend that when using multiple post-processing filters, they are applied in a specific order described in the link below. In your script, the filters are listed in this sequential order: Decimation > Spatial > Temporal > Hole-Filling This is the same order that Intel recommend. Although the application of the filters is dependent on an If condition being true, since the program would process the lines of the script sequentially from top to bottom then I would assume that even if some filters were not applied and skipped over because they were not set to True, the ones that were enabled should be applied in the correct order. So that code is likely okay. If the temporal filter is being used for the purpose of hole-filling and the Hole-Filling filter is being applied afterwards then I wonder if it might become more obvious if the temporal filter is having the intended hole-filling effect if the Hole-Filling filter was set to false so that it was not duplicating the hole-filling work. Perhaps the temporal filter would not even be needed if Hole-Filling can fill the holes on its own. |
The RealSense Viewer applies a range of post-processing and depth colorization settings by default when launched. When creating your own application such as a Python script, these defaults for filters are not included and you must manually program them into your script yourself to more closely replicate the images produced by the Viewer. I did experimentation with the Viewer settings to try to replicate your results. Your image with the numerous horizontal lines seemed to be replicable if applying a Spatial filter and setting its Hole Filling function to a high value such as Unlimited. |
Could you please provide a basic python script about how to align post filtered depth frame as the |
|
#2356 (comment) provides a simple Python example of applying align after a post-processing filter. |
Hi @amirf147 Do you require further assistance with this case, please? Thanks! |
While the issue that I originally raised still stands. I've tried many different combinations of the filters with the options that I mentioned above but the temporal filter still shows no effect or difference when on or off or with any combination of the other filters and their options. When using the realsense viewer it is obvious that changing the temporal filter values makes huge changes to the depth stream but when setting the same options with my python code, I see no changes. So I'm wondering is there some other filter or option that needs to be explicitly set with the python code for the temporal filter to do anything or is the temporal filter just not working in python? |
Ok I think I see my problem now, the filter has to be applied to a set of frames, not just one at a time... Edit: though i thought I was doing that in my code.. I'm now wondering if the previous frame is not remembered in my code now? I guess I will try a simpler 1 page script and see if it works. |
Thanks very much @amirf147 for the update - I look forward to your next report. Good luck! |
@MartyG-RealSense OK it looks like the temporal filter is working when I just do it in a simple one page script. So it looks like the reason it's not working for me has something to do with the fact that my code tried to separate out the frame creation or filtering in a separate class. I do appreciate all your input and I learned several things along the way which have been helpful in adding more features to my program. I can conclude that the temporal filter is working correctly and the issue was with my code. Thanks again. |
You are very welcome. Thanks for your detailed feedback about your success :) |
Hi @amirf147 Do you require further assistance with this case, please? Thanks! |
@MartyG-RealSense no, I figured out it was my code that was the problem. Thank you! |
Okay, thanks very much for the confirmation. I will therefore close this case as a solution has been achieved. Thanks again! |
Hi @amirf147, I'm stuck in the same situation you described: I have a sequence of filters that I want to apply to a depth frame, including a temporal filter. I was setting and applying the temporal filter as: rs2::temporal_filter temp_filter; I read from your preview answers that I should apply it to a set of frames, do you intend like: auto allFrames = pipe.wait_for_frames(); Because I tried to do it and it seems not working, could you please help me? Thanks :) |
Hi @Co-stoletta It looks as though you are using C++ language. Another RealSense C++ user recently had problems with applying temporal and spatial filters as it seemed as though the filters were being destroyed. A solution that worked in their particular case was to place the filters inside a 'for' loop, as shown in #10201 (comment) Intel also make use of applying a filter inside a for-loop in their official C++ post processing example program. |
Hi @MartyG-RealSense, firstly thanks for your fast answer. Regarding the first part of your comment: at the moment every single frame (pipe.wait_for_frames()) is inside a while cycle where the control state is if the STOP button is pressed or not (see the next line) while(!isInterruptionRequested()) So I think that is as I should do. In fact, my C++ code works well, the only problem is the application of the temporal filter. Regarding the second part of your answer, I have to try it, after lunch I will try and I will give you a response. Thanks! :) |
Hi @MartyG-RealSense, I wasn't able to create the vector of filters and to apply it so I'm stuck again, wish I will solve it rapidly. Thanks. |
Does the example C++ script shared by a RealSense team member in #1658 (comment) correctly apply the temporal filter if you run the script? |
Hi @MartyG-RealSense, I tried the script (with little adjustments to let it work with my code):
As you can see the first part is exactly what is written in #1658, plus a way to convert it into "raw" data and emit it. I think there is some bug that I can't see. Thanks! EDIT: I adjusted the size of the window where I print the frames, now I can see a better image but I'm working to understand which image format I should use EDIT2: Ok now it works but I'm not sure that the filter is really working, let me indagate EDIT3: Ok now it seems to work, I will try to apply the same code to my original code and not to the #1658 code. I will post updates EDIT4: Ok I understand where the problem is: it is the application of filters, I need to apply color filter, threshold filter and temporal filter but: So the problem is the application, in combination with the temporal filter, of the color filter, that I implemented like: rs2::colorizer color_filter; @MartyG-RealSense do you have some advice to solve it? Thanks! |
@MartyG-RealSense I SOLVED IT!! To all the guys that are stacked in the same problem, you should use the code from the #1658 comment but you should change the align with: rs2::frameset aligned_frames; Now with this modification and this filter sequence application: frame = temp_filter.process(frame); // Temporal filter I get: Thanks! |
Thanks so much @Co-stoletta for sharing your workings and your C++ solution with the RealSense community :) |
@amirf147
|
In regards to pyrealsense2, I followed the above solution but it has no effect.
From the realsense viewer I can see a huge difference when changing this value but in the python script, changing the values has no effect on the stream. I can also verify that the option was set with:
print(rs.options.get_option(temporal, rs.option.holes_fill))
for some reason the option is not being applied or at least I'm not seeing the result when using python. This does return the value of persistency_index which I set but I am not seeing any difference in the stream. Setting the same option in the realsense viewer has an obvious result. The recording when played with python looks the same as when played with realsense viewer but with the persistency index disabled.
The text was updated successfully, but these errors were encountered: