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

My branch #53

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/source/device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Device
============

Device is a higher level class that contains functionality to collect data from the camrea.
Device is a higher level class that contains functionality to collect data from the camera.

To set up and intialize device:

Expand Down
6 changes: 0 additions & 6 deletions docs/source/driver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ To see if there are other devices currently connected to your PC:

print(driver.find_devices())

In order to test if your device is connected and color image and depth piplines are configured:

.. code-block:: python

driver.live_stream_test()

Set laser intensity function:

.. code-block:: python
Expand Down
8 changes: 4 additions & 4 deletions docs/source/stream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ These are the different functions that you can run:

.. code-block:: python

record.plt_live_stream()
stream.plt_live_stream()

* To show a live plot of the IMU readings:

.. code-block:: python

record.IMU_live_plotting(dt = 1)
stream.IMU_live_plotting(dt = 1)

* To stream data that is already stored into the buffer as a replay.

.. code-block:: python

recorder.stream_buffer()
stream.stream_buffer()

* To livestream the data as it is coming in from the circular buffers:

.. code-block:: python

recorder.cv2_live_stream_buffer()
stream.cv2_live_stream_buffer()


29 changes: 21 additions & 8 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Usage
=====

The driver class is deisgned to run the intel realsense cameras. It is speciically designed to run L151 and D435i.
The driver class is deisgned to run the intel realsense cameras. It is specifically designed to run L151 and D435i.
it may run with other models but some functionaity may break down.

System design:
Expand Down Expand Up @@ -43,8 +43,20 @@ For the L515 camera:

* Acceleration Output Data Rate 100Hz/200Hz/400Hz
* Gyroscope Output Data Rate 100Hz/200Hz/400Hz

Recording Data

Applications
-------------
There are two different applications:

* Recorder

The recorder is able to collect data while livestreaming it. You can find more information in recorder.rst

* Stream

There are diffent functionalities in this class such as live streaming images using different python modules and live ploting of IMU data. You can find more information in stream.rst.

Recorder
---------------

All the functionality to collect data and store it in a file is already done for you in the record script.
Expand All @@ -53,11 +65,12 @@ In order to run it, you will need a config file and a h5py file to save data int
To collect the data run the following script:

.. code-block:: python

# IT MUST BE IN THIS ORDER
python recorder.py "YOUR CONFIG FILE" "YOUR H5PY FILE"
# my example
python recorder.py "test_files\config_L151_f1320305.yaml" "test_files\test.h5py"

import intel_realsense_devices
# IT MUST BE IN THIS ORDER
python recorder.py "YOUR CONFIG FILE" "YOUR H5PY FILE"
# my example
python recorder.py "test_files\config_L151_f1320305.yaml" "test_files\test.h5py"


The data will be stored into a H5PY file where the dataset names are ['accel', 'color', 'depth', 'frameN', 'gyro', 'infrared'].
Expand Down
7 changes: 2 additions & 5 deletions intel_realsense_devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ class Device():
"""
def __init__(self, config_filename):
"""
part 1 to iniatilie the camera
initialize all the attributes to set up the device

Parameters:
------------
config_filename: string
config file path

h5py_filename: string
h5py file path
"""

# Create a context object. This object owns the handles to all connected realsense devices
Expand Down Expand Up @@ -229,7 +226,7 @@ def io_pull(self, io_dict):
else:
debug('reading default config file')
config_filename = r"C:\Users\Abdel Nasser\Documents\L151 Camera\intel-realsense-devices\intel_realsense_devices\test_files\config_d435i__139522074713.yaml"
config_filename = "test_files\config_L515_f1231322.yaml"
# config_filename = "test_files\config_L515_f1231322.yaml"

info(config_filename)

Expand Down
8 changes: 3 additions & 5 deletions intel_realsense_devices/higher_applications/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ def start(self):
self.device.start()
threads["record"] = new_thread(self.record)

from intel_realsense_devices.higher_applications.stream import Stream

stream = Stream(self.config_filename)
stream.cv2_live_stream_buffer()
from intel_realsense_devices.higher_applications.stream import cv2_live_stream_buffer
cv2_live_stream_buffer(self.device)

def stop(self):
"""
Expand Down Expand Up @@ -107,7 +105,7 @@ def save_h5py_file(self):

def read_h5py_file(self):
"""
reads the hp5y file data sets, For testing
reads the hp5y file data set name, For testing

Parameters:
----------
Expand Down
43 changes: 37 additions & 6 deletions intel_realsense_devices/higher_applications/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
IMAGE = "image"
FRAMEN = "frameN"

def cv2_live_stream_color_buffer(device):
"""
Live stream images from the buffer via the cv2 lib.
Used while collecting data.

Paremeter:
------------
Device Object
"""

buffer_length = device.buffers[FRAMEN].get_all().shape[0] # gets the number of frames

while last_frame < buffer_length:

last_frame = device.buffers[FRAMEN].get_last_value()[0]

c = device.buffers[COLOR].get_last_value()
color = c[0,:,:, :]

if color is not None:
cv2.imshow("Color", color)

key = cv2.waitKey(10)
if key != -1:
cv2.destroyAllWindows()
run = False

cv2.destroyAllWindows()

class Stream():
"Higher level application that can stream live data from the camera"

Expand All @@ -25,7 +54,7 @@ def __init__(self, config_filename):
self.driver = self.device.driver
self.run = True

def plt_live_stream(self):
def plt_live_stream(self,):
"""
live stream of images using matplotlib
"""
Expand Down Expand Up @@ -86,17 +115,19 @@ def stream_buffer(self):
cv2.destroyAllWindows()
self.run = False

def cv2_live_stream_buffer(self):
def cv2_live_stream_buffer(self,):
"""
Live stream images using the cv2 lib.
Used while collecting data.
"""

self.device.start()

while self.run:
last_frame = 0
buffer_length = self.device.buffers[FRAMEN].get_all().shape[0] # gets the number of frames

frames = self.device.buffers[FRAMEN].get_last_value()[0]
while last_frame < buffer_length and self.run:
last_frame = self.device.buffers[FRAMEN].get_last_value()[0]

d = self.device.buffers[DEPTH].get_last_value()
depth = d[0,:,:]
Expand Down Expand Up @@ -124,8 +155,8 @@ def Cv2_live_stream(self):
Stream live images from the camera
"""
self.device.start()

while True:
while self.run:
dict = self.device.driver.get_images()

color = dict[COLOR]
Expand Down