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

Update realsense_device_manager.py #4402

Merged
merged 3 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
###########################################################################################################################
## License: Apache 2.0. See LICENSE file in root directory. ##
## License: Apache 2.0. See LICENSE file in root directory. ##
###########################################################################################################################
## Simple Box Dimensioner with multiple cameras: Main demo file ##
###########################################################################################################################
## Workflow description: ##
## Workflow description: ##
## 1. Place the calibration chessboard object into the field of view of all the realsense cameras. ##
## Update the chessboard parameters in the script in case a different size is chosen. ##
## 2. Start the program. ##
## 3. Allow calibration to occur and place the desired object ON the calibration object when the program asks for it. ##
## Make sure that the object to be measured is not bigger than the calibration object in length and width. ##
## Make sure that the object to be measured is not bigger than the calibration object in length and width. ##
## 4. The length, width and height of the bounding box of the object is then displayed in millimeters. ##
###########################################################################################################################

Expand Down Expand Up @@ -56,12 +56,12 @@ def run_demo():
1: Calibration
Calibrate all the available devices to the world co-ordinates.
For this purpose, a chessboard printout for use with opencv based calibration process is needed.

"""
# Get the intrinsics of the realsense device
intrinsics_devices = device_manager.get_device_intrinsics(frames)

# Set the chessboard parameters for calibration
# Set the chessboard parameters for calibration
chessboard_params = [chessboard_height, chessboard_width, square_size]

# Estimate the pose of the chessboard in the world coordinate using the Kabsch Method
Expand All @@ -88,19 +88,19 @@ def run_demo():
chessboard_points_cumulative_3d = np.column_stack( (chessboard_points_cumulative_3d,points3D) )

# Extract the bounds between which the object's dimensions are needed
# It is necessary for this demo that the object's length and breath is smaller than that of the chessboard
# It is necessary for this demo that the object's length and breath is smaller than that of the chessboard
chessboard_points_cumulative_3d = np.delete(chessboard_points_cumulative_3d, 0, 1)
roi_2D = get_boundary_corners_2D(chessboard_points_cumulative_3d)

print("Calibration completed... \nPlace the box in the field of view of the devices...")


"""
2: Measurement and display
Measure the dimension of the object using depth maps from multiple RealSense devices
The information from Phase 1 will be used here
2: Measurement and display
Measure the dimension of the object using depth maps from multiple RealSense devices
The information from Phase 1 will be used here

"""
"""

# Enable the emitter of the devices
device_manager.enable_emitter(True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##################################################################################################
## License: Apache 2.0. See LICENSE file in root directory. ####
## License: Apache 2.0. See LICENSE file in root directory. ####
##################################################################################################
## Box Dimensioner with multiple cameras: Helper files ####
## Box Dimensioner with multiple cameras: Helper files ####
##################################################################################################


Expand All @@ -14,7 +14,7 @@
| |_| | / _ \| || '_ \ / _ \| '__| | |_ | | | || '_ \ / __|| __|| | / _ \ | '_ \ / __|
| _ || __/| || |_) || __/| | | _| | |_| || | | || (__ | |_ | || (_) || | | |\__ \
|_| |_| \___||_|| .__/ \___||_| |_| \__,_||_| |_| \___| \__||_| \___/ |_| |_||___/
_|
|_|
"""


Expand All @@ -30,13 +30,13 @@ def enumerate_connected_devices(context):

Parameters:
-----------
context : rs.context()
The context created for using the realsense library
context : rs.context()
The context created for using the realsense library

Return:
-----------
connect_device : array
Array of enumerated devices which are connected to the PC
Array of enumerated devices which are connected to the PC

"""
connect_device = []
Expand All @@ -53,26 +53,25 @@ def post_process_depth_frame(depth_frame, decimation_magnitude=1.0, spatial_magn

Parameters:
-----------
depth_frame : rs.frame()
The depth frame to be post-processed
depth_frame : rs.frame()
The depth frame to be post-processed
decimation_magnitude : double
The magnitude of the decimation filter
spatial_magnitude : double
The magnitude of the spatial filter
spatial_smooth_alpha : double
The alpha value for spatial filter based smoothening
spatial_smooth_delta : double
The delta value for spatial filter based smoothening
temporal_smooth_alpha : double
The alpha value for temporal filter based smoothening
temporal_smooth_delta : double
The delta value for temporal filter based smoothening

The magnitude of the decimation filter
spatial_magnitude : double
The magnitude of the spatial filter
spatial_smooth_alpha : double
The alpha value for spatial filter based smoothening
spatial_smooth_delta : double
The delta value for spatial filter based smoothening
temporal_smooth_alpha: double
The alpha value for temporal filter based smoothening
temporal_smooth_delta: double
The delta value for temporal filter based smoothening

Return:
----------
filtered_frame : rs.frame()
The post-processed depth frame
The post-processed depth frame
"""

# Post processing possible only on the depth_frame
Expand Down Expand Up @@ -108,7 +107,7 @@ def post_process_depth_frame(depth_frame, decimation_magnitude=1.0, spatial_magn
| \/ | __ _ (_) _ __ / ___| ___ _ __ | |_ ___ _ __ | |_
| |\/| | / _` || || '_ \ | | / _ \ | '_ \ | __|/ _ \| '_ \ | __|
| | | || (_| || || | | | | |___| (_) || | | || |_| __/| | | || |_
|_| |_| \__,_||_||_| |_| \____|\___/ |_| |_| \__|\___||_| |_| \__|
|_| |_| \__,_||_||_| |_| \____|\___/ |_| |_| \__|\___||_| |_| \__|

"""

Expand All @@ -120,10 +119,10 @@ def __init__(self, context, pipeline_configuration):

Parameters:
-----------
context : rs.context()
The context created for using the realsense library
pipeline_configuration : rs.config()
The realsense library configuration to be used for the application
context : rs.context()
The context created for using the realsense library
pipeline_configuration : rs.config()
The realsense library configuration to be used for the application

"""
assert isinstance(context, type(rs.context()))
Expand All @@ -140,8 +139,8 @@ def enable_device(self, device_serial, enable_ir_emitter):

Parameters:
-----------
device_serial : string
Serial number of the realsense device
device_serial : string
Serial number of the realsense device
enable_ir_emitter : bool
Enable/Disable the IR-Emitter of the device

Expand Down Expand Up @@ -185,9 +184,8 @@ def load_settings_json(self, path_to_settings_file):

"""

file = open(path_to_settings_file, 'r')
json_text = file.read().strip()
file.close()
with open(path_to_settings_file, 'r') as file:
json_text = file.read().strip()

for (device_serial, device) in self._enabled_devices.items():
# Get the active profile and load the json file which contains settings readable by the realsense
Expand Down Expand Up @@ -223,12 +221,12 @@ def poll_frames(self):
return frames

def get_depth_shape(self):
""" Retruns width and height of the depth stream for one arbitrary device
"""
Retruns width and height of the depth stream for one arbitrary device

Returns:
-----------

width: int
width : int
height: int
"""
width = -1
Expand All @@ -247,7 +245,7 @@ def get_device_intrinsics(self, frames):
Parameters:
-----------
frames : rs::frame
The frame grabbed from the imager inside the Intel RealSense for which the intrinsic is needed
The frame grabbed from the imager inside the Intel RealSense for which the intrinsic is needed

Return:
-----------
Expand All @@ -271,7 +269,7 @@ def get_depth_to_color_extrinsics(self, frames):
Parameters:
-----------
frames : rs::frame
The frame grabbed from the imager inside the Intel RealSense for which the intrinsic is needed
The frame grabbed from the imager inside the Intel RealSense for which the intrinsic is needed

Return:
-----------
Expand All @@ -298,7 +296,7 @@ def disable_streams(self):
| | / _ \/ __|| __|| || '_ \ / _` |
| || __/\__ \| |_ | || | | || (_| |
|_| \___||___/ \__||_||_| |_| \__, |
|___/
|___/

"""
if __name__ == "__main__":
Expand Down