Items with no label
Announcements
Intel Customer Support will be observing the Martin Luther King holiday on Monday, Jan. 17, and will return on Tues. Jan. 18.
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646
3322 Discussions

Enable Auto-Exposure Using Python Code

NeuroGalaxy
Beginner
4,142 Views

I am able to enable auto exposure on the Intel Realsense Viewer and able to adjust other properties. Is there a function or code which enable me to add auto-exposure to my program. I am using Intel realsense d435 with pyrealsense2 library for python.

0 Kudos
1 Solution
Eliza_D_Intel
Employee
2,765 Views

Hello NeuroGalaxy,

 

Great news! I am attaching a code that can help you set the exposure.

import pyrealsense2 as rs   pipeline = rs.pipeline()   config = rs.config()   profile = pipeline.start(config) # Start streaming   sensor_dep = profile.get_device().first_depth_sensor()   print "Trying to set Exposure"   exp = sensor_dep.get_option(rs.option.exposure)   print "exposure = %d" % exp   print "Setting exposure to new value"   exp = sensor_dep.set_option(rs.option.exposure, 25000)   exp = sensor_dep.get_option(rs.option.exposure)   print "New exposure = %d" % exp   profile = pipeline.stop

Thank you and best regards,

Eliza

View solution in original post

13 Replies
Eliza_D_Intel
Employee
2,765 Views
Hello NeuroGalaxy, Thank you for your interest in the Intel RealSense D435 camera, You can check out the example pybackend_example_1_general.py (Lines 51-58) which enables the auto exposure - https://github.com/IntelRealSense/librealsense/blob/aa65fdd877985dec93e4b61b6ce4806697cbcbd6/wrapper... Thank you and best regards, Eliza
NeuroGalaxy
Beginner
2,765 Views
NeuroGalaxy
Beginner
2,765 Views

I tried it, but there is no module 'pybackend2'. Does this support D435 ?

Eliza_D_Intel
Employee
2,765 Views
Hello NeuroGalaxy, In order to generate the pybackend2.pyd file you will need build librealsense from source: Please follow the instructions from https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python#windows and note that on step 5 and 6, you will need to copy pybackend2.pyd too to the locations mentioned there. Please let me know the output! Thank you and best regards, Eliza
NeuroGalaxy
Beginner
2,765 Views

Thank you. I will build it in Cmake. Is there any pre-build files for pyrealsense2.pyd and realsense.dll available? I am using python 3.6.6 with pyrealsense2.17.1.457.

Eliza_D_Intel
Employee
2,765 Views
Hello NeuroGalaxy, I just run some test and found that if you install the latest executable for RealSense SDK 2.0, all of them are available. Here is what I did: 1. Uninstall the RealSense SDK 2.0 2. Download the latest release Intel.RealSense.SDK-2.18.1.exe from https://github.com/IntelRealSense/librealsense/releases 3. Check "Python 2.7 / 3.6 Developer packages" 4. After the installation is done, go to C:\Programs Files(x86)\Intel RealSense SDK 2.0\bin\ x86 or x64 and here you can find: pybackend2.pyd, pyrealsense2.pyd and realsense2.dll 5. Copy and paste them to: C:\Python27\Lib\site-packages 6. Copy and paste them next to your script Please let me know if you find them! Thank you and best regards, Eliza
NeuroGalaxy
Beginner
2,765 Views

Now, i am getting an Import Error. 'ImportError: generic_type: type "USB_TYPE" is already registered!'

Eliza_D_Intel
Employee
2,765 Views
Hello NeuroGalaxy, Let me look into that. I did not receive this error. You are testing the python-tutorial-1-depth.py, right? Thank you!
NeuroGalaxy
Beginner
2,765 Views

yes thats correct

I am using Anaconda to run all the packages from.

Eliza_D_Intel
Employee
2,765 Views
Hello NeuroGalaxy, Thank you for the clarification. Unfortunately, when using Anaconda you will need to build from source the files (as the path to Anaconda will need to be specified). You can follow these step-by-step instructions that can help you set up the environment: https://github.com/IntelRealSense/librealsense/issues/1657 You can find the latest release for Librealsense (by the name: Source code(zip)) here: https://github.com/IntelRealSense/librealsense/releases Thank you and best regards, Eliza
NeuroGalaxy
Beginner
2,765 Views

thank you. I will try this method.

 

Alternatively, I was able to display the values using just pyrealsense2. See code below.

import pyrealsense2 as rs   pipeline = rs.pipeline() config = rs.config() profile = pipeline.start(config)   dev = profile.get_device()   for i in range(len(dev.sensors)): if dev.sensors[i].is_depth_sensor() == False : sens=dev.sensors[i] break print (sens.get_option(rs.option.brightness)) print (sens.get_option(rs.option.contrast)) print (sens.get_option(rs.option.exposure)) print (sens.get_option(rs.option.gain)) print (sens.get_option(rs.option.gamma)) print (sens.get_option(rs.option.hue)) print (sens.get_option(rs.option.saturation)) print (sens.get_option(rs.option.sharpness)) print (sens.get_option(rs.option.white_balance)) print (sens.get_option(rs.option.enable_auto_exposure))   pipeline.stop()

Do you know how I could set the values for these parameters?

 

The example I was trying to do was: https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/pybackend_exampl...

 

pybackend_example_1_general.py

 

Purpose is to enable/disable auto exposure from code and not from intel viewer.

 

python-tutorial-1-depth.py program is working

Eliza_D_Intel
Employee
2,766 Views

Hello NeuroGalaxy,

 

Great news! I am attaching a code that can help you set the exposure.

import pyrealsense2 as rs   pipeline = rs.pipeline()   config = rs.config()   profile = pipeline.start(config) # Start streaming   sensor_dep = profile.get_device().first_depth_sensor()   print "Trying to set Exposure"   exp = sensor_dep.get_option(rs.option.exposure)   print "exposure = %d" % exp   print "Setting exposure to new value"   exp = sensor_dep.set_option(rs.option.exposure, 25000)   exp = sensor_dep.get_option(rs.option.exposure)   print "New exposure = %d" % exp   profile = pipeline.stop

Thank you and best regards,

Eliza

View solution in original post

NeuroGalaxy
Beginner
2,765 Views

The example I was trying to do was: https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/pybackend_exampl...

 

pybackend_example_1_general.py

 

Purpose is to enable/disable auto exposure from code and not from intel viewer.

Reply