Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from ifm/lm_script_edits
Browse files Browse the repository at this point in the history
Merged two scripts in one
  • Loading branch information
lola-masson authored Jul 15, 2021
2 parents 8745ddc + 8aa8c62 commit 53a7517
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 187 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/settings.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:warning: **The ifm3D Tiny will be deprecated soon and replaced by [ifm3d](https://github.com/ifm/ifm3d)**: Be very careful here!

# ifm3DTiny-examples
Examples for the O3R ifm3DTiny python client (see installation instructions on (www.ifm3d.com)[www.ifm3d.com])
Examples for the O3R ifm3DTiny python client (see installation instructions on [ifm3d.com](https://ifm3d.com))

Disclaimer:
ifm's support team provides code examples and helper scripts with the idea of accelerating the development process for customers.
Expand Down
28 changes: 0 additions & 28 deletions save_algo_debug/README_start_algodebug.md

This file was deleted.

65 changes: 0 additions & 65 deletions save_algo_debug/start_algodebug.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
Disclaimer: ifm's support team provides code examples and helper scripts with the idea of accelerating the development process for customers.
We do not guarantee that these scripts will be updated to reflect the lifecycle of ifm's various software packages.

# How to save a data stream with the helper script `start_save_datastream.py`
# How to save a data stream with the helper script `save_data_stream.py`

## requirements
Required python packages:
+ `ifmO3r`
+ (all dependent packages of the `ifmO3r` package)
+ Python `version >= 3.8`

## run start_save_datastream
The `start_save_datastream.py` python script is used as a helper tool when recording continous data sets with a predefined format, length, and VPU - Head combination.
For further flexibility see the function and it's arguments `save_data_stream()` as part of the `ImageLogger` class.
## run save_data_stream
The `save_data_stream.py` python script is used as a helper tool when recording data for a predifined number of seconds. This script can be used to record algo debug data or normal data streams.
For further flexibility see the functions `save_data_stream()` and `save_algo_debug_data()` as part of the `ImageLogger` class, along with the tutorial on [ifm3d.com](https://ifm3d.com).

**Typical use:**
Start the script via:
```
python start_save_datastream.py
python save_data_stream.py
```

To see all available argument parsing parameters:
```
python start_save_datastream.py --help
python save_data_stream.py --help
usage: start_save_datastream.py [-h] [--ip IP] [--timeout TIMEOUT] [--numSeconds NUMSECONDS]
[--loglevel {DEBUG,INFO,WARNING,ERROR}] [--filename FILENAME]
[--portIndices [PORTINDICES [PORTINDICES ...]]] [--conf CONF]
usage: save_data_stream.py [-h] [--type {normal,debug}] [--ip IP]
[--timeout TIMEOUT] [--numSeconds NUMSECONDS]
[--loglevel {DEBUG,INFO,WARNING,ERROR}]
[--filename FILENAME]
[--portIndices [PORTINDICES [PORTINDICES ...]]]
[--conf CONF]
optional arguments:
-h, --help show this help message and exit
--type {normal,debug}
The type of data to save (normal data stream or
algo-debug data)
--ip IP ip address of VPU
--timeout TIMEOUT timeout to be used in the get function
--numSeconds NUMSECONDS
number of seconds to be recorded
--loglevel {DEBUG,INFO,WARNING,ERROR}
--filename FILENAME target filename. If not given, a file will be created in the current directory.
--filename FILENAME target filename. If not given, a file will be
created in the current directory.
--portIndices [PORTINDICES [PORTINDICES ...]]
VPU ports to be recorded.
--conf CONF head configuration via json file, default is config.json in the cwd
```
VPU ports to be recorded
--conf CONF head configuration via json file, default is
config.json in the cwd
## required python setup to run this script
## Cheatsheet: required python setup to run this script
1. activate your python environment
cmd: `o3r-venv\Scripts\activate`
powershell: `.\o3r-venv\Scripts\activate`
Expand Down
99 changes: 99 additions & 0 deletions save_data_stream/save_data_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2021 ifm electronic gmbh, CSR
#
# ifm's support team provides code examples and helper scripts with the idea of accelerating the development process for customers.
# We do not guarantee that these scripts will be updated to reflect the lifecycle of ifm's various software packages.

from ifmO3r.ifm3dTiny import ImageLogger, FrameGrabber, ImageBuffer, Device
from ifmO3r.ifm3dTiny.utils.recorder import record as ad_record
import argparse
import logging

status_logger = logging.getLogger(__name__)


def configure_heads_from_json(conf, devs):
# configure heads with config from json config files
if conf is not None:
for d in devs:
if configure_head(d, conf):
status_logger.info("imager successfully configured at port: {port} with json-config: {conf_file}".format(
port=d.id, conf_file=conf))
else:
status_logger.info("imager configuration at port: {port} with json-config: {conf_file} failed".format(
port=d.id, conf_file=conf))

def configure_head(dev, conf):
try:
dev.config_from_json_file(conf)
except Exception as e:
status_logger.error(e)
return True

def create_port_list_from_indices(portIndices):
# create port lists from pid
port3d = []
port2d = []
for p in portIndices:
if 0 <= int(p) <= 1:
port2d.append(int(50020 + int(p)))
if 2 <= int(p) <= 5:
port3d.append(int(50010 + int(p)))
status_logger.debug("ports of 3D imagers: {}".format(port3d))
status_logger.debug("ports of 2D imagers: {}".format(port2d))
return port2d, port3d

def log_image_data(args, dev, fg, im):
if args.type == "normal":
# TODO: implement a ImageLogger based on more than one Buffer and Device
# only use the first set of grabber, buffer and logger
image_logger = ImageLogger(device=dev, frameGrabber=fg, imageBuffer=im)
status_logger.info("start saving data stream to file")
num_frames = image_logger.save_data_stream(streams=['o3r',], num_sensors=1, write_index=True, numSeconds=args.numSeconds, desc="example data set")
status_logger.info("stop saving data stream to file")
status_logger.info("{} frames saved".format(num_frames))
elif args.type == "debug":
#TODO
try:
ad_record(ip=args.ip, timeout=args.timeout, numberOfSeconds=args.numSeconds, filename=args.filename, cameras=[int(cid) for cid in args.portIndices], )
except Exception as e:
status_logger.error(e)
else:
status_logger.warning("Type of data unknown")


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--type", help="The type of data to save (normal data stream or algo-debug data)", choices=["normal", "debug"], default="normal", type=str)
parser.add_argument("--ip", help="ip address of VPU", default="192.168.0.69")
parser.add_argument("--timeout", help="timeout to be used in the get function", default=3.0, type=float)
parser.add_argument("--numSeconds", help="number of seconds to be recorded ", default=5, type=int)
parser.add_argument("--loglevel", default="INFO", choices=["DEBUG", "INFO", "WARNING", "ERROR"])
parser.add_argument("--filename",
help="target filename. If not given, a file will be created in the current directory.",
default=None)
parser.add_argument("--portIndices", help="VPU ports to be recorded", default=[2], nargs="*")
parser.add_argument("--conf", help="head configuration via json file, default is config.json in the cwd",
default=None, type=str)
args = parser.parse_args()

logging.basicConfig(level=args.loglevel)
# log all argparse arguments
status_logger.info(args)
status_logger.debug("WARNING: this implementation only saves 3D data at the moment")

port2d, port3d = create_port_list_from_indices(args.portIndices)

# Build Devices, FrameGrabbers and ImageBuffers for supplied ports
devs = [Device(ip=args.ip, port=port) for port in port3d]
fgs = [FrameGrabber(dev) for dev in devs]
ims = [ImageBuffer() for _ in enumerate(devs)]

configure_heads_from_json(args.conf, devs)
# Logging data for the first device. Add loop for multiple ports.
log_image_data(args, devs[0], fgs[0], ims[0])



if __name__ == "__main__":
main()
79 changes: 0 additions & 79 deletions save_data_stream/start_save_datastream.py

This file was deleted.

0 comments on commit 53a7517

Please sign in to comment.