Skip to content

Commit

Permalink
Samples: Automatic updates to public repository
Browse files Browse the repository at this point in the history
Remember to do the following:
    1. Ensure that modified/deleted/new files are correct
    2. Make this commit message relevant for the changes
    3. Force push
    4. Delete branch after PR is merged

If this commit is an update from one SDK version to another,
make sure to create a release tag for previous version.
  • Loading branch information
csu-bot-zivid committed Jun 30, 2023
1 parent 48c5d3a commit 3de3a61
Show file tree
Hide file tree
Showing 28 changed files with 130 additions and 107 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ubuntu-version: ["ubuntu:18.04", "ubuntu:20.04"]
ubuntu-version: ["18.04", "20.04", "22.04"]
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup on ${{matrix.ubuntu-version}}
- name: Setup on Ubuntu ${{matrix.ubuntu-version}}
run: |
docker run \
--volume $PWD:/host \
--workdir /host/continuous-integration \
--env "PYTHONDONTWRITEBYTECODE=1" \
${{matrix.ubuntu-version}} \
ubuntu:${{matrix.ubuntu-version}} \
bash -c "./setup.sh"
ubuntu-setup-and-lint:
name: Ubuntu setup and lint
runs-on: ubuntu-latest
strategy:
matrix:
ubuntu-version: ["ubuntu:18.04"]
ubuntu-version: ["18.04"]
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup and lint on ${{matrix.ubuntu-version}}
- name: Setup and lint on Ubuntu ${{matrix.ubuntu-version}}
run: |
docker run \
--volume $PWD:/host \
--workdir /host/continuous-integration \
--env "PYTHONDONTWRITEBYTECODE=1" \
${{matrix.ubuntu-version}} \
ubuntu:${{matrix.ubuntu-version}} \
bash -c "./setup.sh && ./lint.sh"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python samples

This repository contains python code samples for Zivid SDK v2.9.0. For
This repository contains python code samples for Zivid SDK v2.10.0. For
tested compatibility with earlier SDK versions, please check out
[accompanying
releases](https://github.com/zivid/zivid-python-samples/tree/master/../../releases).
Expand Down Expand Up @@ -157,8 +157,8 @@ The recommended Python version for these samples is 3.6 - 3.9.
4. Add the directory source to PYTHONPATH. Navigate to the root of the
repository and run:

- PowerShell: `$env:PYTHONPATH=$env:PYTHONPATH + ";$PWD\source"`
- cmd: `set PYTHONPATH="$PYTHONPATH;$PWD\source"`
- PowerShell: `$env:PYTHONPATH=$env:PYTHONPATH + ";$PWD\\source"`
- cmd: `set PYTHONPATH="$PYTHONPATH;$PWD\\source"`
- bash: `export PYTHONPATH="$PYTHONPATH:$PWD/source"`

5. Open and run one of the samples.
Expand Down
28 changes: 13 additions & 15 deletions continuous-integration/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,12 @@
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR=$(realpath "$SCRIPT_DIR/..")

ZIVID_SDK_EXACT_VERSION=2.9.0+4dbba385-1
ZIVID_TELICAM_EXACT_VERSION=3.0.1.1-3

export DEBIAN_FRONTEND=noninteractive
source /etc/os-release || exit $?

function apt-yes {
apt-get --assume-yes "$@"
}

function install_www_deb {
TMP_DIR=$(mktemp --tmpdir --directory zivid-python-install-www-deb-XXXX) || exit $?
pushd $TMP_DIR || exit $?
wget -nv "$@" || exit $?
apt-yes install --fix-broken ./*deb || exit $?
popd || exit $?
rm -r $TMP_DIR || exit $?
}

apt-yes update || exit
apt-yes dist-upgrade || exit

Expand All @@ -30,8 +17,19 @@ apt-yes install \
wget ||
exit $?

install_www_deb "https://downloads.zivid.com/sdk/releases/${ZIVID_SDK_EXACT_VERSION}/u${VERSION_ID:0:2}/zivid-telicam-driver_${ZIVID_TELICAM_EXACT_VERSION}_amd64.deb" || exit $?
install_www_deb "https://downloads.zivid.com/sdk/releases/${ZIVID_SDK_EXACT_VERSION}/u${VERSION_ID:0:2}/zivid_${ZIVID_SDK_EXACT_VERSION}_amd64.deb" || exit $?
source /etc/os-release || exit

function install_www_deb {
TMP_DIR=$(mktemp --tmpdir --directory zivid-sdk-install-www-deb-XXXX) || exit
pushd $TMP_DIR || exit
wget -nv "$@" || exit
apt-yes install --fix-broken ./*deb || exit
popd || exit
rm -r $TMP_DIR || exit
}

install_www_deb "https://downloads.zivid.com/sdk/releases/2.10.0-preview-4+4476b90a-1/u${VERSION_ID:0:2}/zivid-telicam-driver_3.0.1.1-3_amd64.deb" || exit
install_www_deb "https://downloads.zivid.com/sdk/releases/2.10.0-preview-4+4476b90a-1/u${VERSION_ID:0:2}/zivid_2.10.0-preview-4+4476b90a-1_amd64.deb" || exit

python3 -m pip install --upgrade pip || exit
python3 -m pip install --requirement "$ROOT_DIR/requirements.txt" || exit
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
numpy
matplotlib
opencv-python
numpy
open3d
opencv-python
pyyaml
scipy
robodk
zivid
scipy
zivid
60 changes: 55 additions & 5 deletions source/applications/advanced/auto_2d_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def _find_lowest_acceptable_fnum(camera: zivid.Camera, image_distance_near: floa
if camera.info.model == zivid.CameraInfo.Model.zividOnePlusSmall:
focus_distance = 500
focal_length = 16
circle_of_confusion = 0.015
fnum_min = 1.4
if image_distance_near < 300 or image_distance_far > 1000:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
Expand All @@ -184,6 +186,8 @@ def _find_lowest_acceptable_fnum(camera: zivid.Camera, image_distance_near: floa
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusMedium:
focus_distance = 1000
focal_length = 16
circle_of_confusion = 0.015
fnum_min = 1.4
if image_distance_near < 500 or image_distance_far > 2000:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
Expand All @@ -192,6 +196,8 @@ def _find_lowest_acceptable_fnum(camera: zivid.Camera, image_distance_near: floa
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusLarge:
focus_distance = 1800
focal_length = 16
circle_of_confusion = 0.015
fnum_min = 1.4
if image_distance_near < 1200 or image_distance_far > 3000:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
Expand All @@ -200,6 +206,8 @@ def _find_lowest_acceptable_fnum(camera: zivid.Camera, image_distance_near: floa
elif camera.info.model == zivid.CameraInfo.Model.zividTwo:
focus_distance = 700
focal_length = 8
circle_of_confusion = 0.015
fnum_min = 1.8
if image_distance_near < 300 or image_distance_far > 1300:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
Expand All @@ -208,16 +216,26 @@ def _find_lowest_acceptable_fnum(camera: zivid.Camera, image_distance_near: floa
elif camera.info.model == zivid.CameraInfo.Model.zividTwoL100:
focus_distance = 1000
focal_length = 8
circle_of_confusion = 0.015
fnum_min = 1.8
if image_distance_near < 600 or image_distance_far > 1600:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
f"({image_distance_far:.2f}) is outside recommended working distance for camera [600, 1600]"
)
elif camera.info.model == zivid.CameraInfo.Model.zividTwoPlusM130:
focus_distance = 1300
focal_length = 11
circle_of_confusion = 0.008
fnum_min = 2.1
if image_distance_near < 800 or image_distance_far > 2000:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
f"({image_distance_far:.2f}) is outside recommended working distance for camera [800, 2000]"
)
else:
raise RuntimeError("Unsupported camera model in this sample.")

circle_of_confusion = 0.015

fnum_near = (
np.abs(image_distance_near - focus_distance)
/ image_distance_near
Expand All @@ -232,7 +250,7 @@ def _find_lowest_acceptable_fnum(camera: zivid.Camera, image_distance_near: floa
fnum_near = min(max(fnum_near, 1), 32)
fnum_far = min(max(fnum_far, 1), 32)

return max(fnum_near, fnum_far, 1.8)
return max(fnum_near, fnum_far, fnum_min)


def _find_lowest_exposure_time(camera: zivid.Camera) -> float:
Expand All @@ -258,12 +276,45 @@ def _find_lowest_exposure_time(camera: zivid.Camera) -> float:
exposure_time = 1677
elif camera.info.model == zivid.CameraInfo.Model.zividTwoL100:
exposure_time = 1677
elif camera.info.model == zivid.CameraInfo.Model.zividTwoPlusM130:
exposure_time = 1677
else:
raise RuntimeError("Unsupported camera model in this sample.")

return exposure_time


def _find_max_brightness(camera: zivid.Camera) -> float:
"""Find the max projector brightness that a given camera can provide.
Args:
camera: Zivid camera
Raises:
RuntimeError: If camera model is not supported
Returns:
Highest projector brightness value for given camera
"""
if camera.info.model == zivid.CameraInfo.Model.zividOnePlusSmall:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusMedium:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusLarge:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividTwo:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividTwoL100:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividTwoPlusM130:
brightness = 2.5
else:
raise RuntimeError("Unsupported camera model in this sample.")

return brightness


def _initialize_settings_2d(aperture: float, exposure_time: float, brightness: float, gain: float) -> zivid.Settings2D:
"""Initialize 2D capture settings.
Expand Down Expand Up @@ -421,7 +472,7 @@ def _find_2d_settings_from_mask(
"""
min_exposure_time = _find_lowest_exposure_time(camera)
brightness = 1.8 if use_projector else 0
brightness = _find_max_brightness(camera) if use_projector else 0
settings_2d = _initialize_settings_2d(aperture=8, exposure_time=min_exposure_time, brightness=brightness, gain=1)

lower_white_range = 210
Expand Down Expand Up @@ -523,7 +574,6 @@ def _plot_image_with_histogram(rgb: np.ndarray, settings_2d: zivid.Settings2D) -


def _main() -> None:

app = zivid.Application()

user_options = _options()
Expand Down
1 change: 0 additions & 1 deletion source/applications/advanced/color_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def _options() -> argparse.Namespace:


def _main() -> None:

app = zivid.Application()

user_options = _options()
Expand Down
2 changes: 0 additions & 2 deletions source/applications/advanced/create_depth_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def _visualize_and_save_image(image: np.ndarray, image_file: str, title: str) ->


def _main() -> None:

with zivid.Application():

data_file = get_sample_data_path() / "Zivid3D.zdf"
print(f"Reading ZDF frame from file: {data_file}")
frame = zivid.Frame(data_file)
Expand Down
2 changes: 0 additions & 2 deletions source/applications/advanced/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def _options() -> argparse.Namespace:


def _main() -> None:

with zivid.Application():

user_options = _options()
data_file = user_options.zdf_path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def _visualize_checkerboard_point_cloud_with_coordinate_system(


def _main() -> None:

with zivid.Application():

data_file = get_sample_data_path() / "CalibrationBoardInCameraOrigin.zdf"
print(f"Reading ZDF frame from file: {data_file}")
frame = zivid.Frame(data_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ def print_header(txt: str) -> None:


def _main() -> None:

with zivid.Application():

np.set_printoptions(precision=4, suppress=True)
print_header("This example shows conversions to/from Transformation Matrix")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ def options() -> argparse.Namespace:


def _main() -> None:

app = zivid.Application()

user_options = options()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def _generate_dataset(app: zivid.Application, con: rtde.RTDE, input_data: rtde.s
"""
with app.connect_camera() as camera:

settings = _camera_settings(camera)
save_dir = _generate_folder()

Expand Down Expand Up @@ -390,7 +389,6 @@ def perform_hand_eye_calibration(
pose_file_path = data_dir / f"pos{idata:02d}.yaml"

if frame_file_path.is_file() and pose_file_path.is_file():

print(f"Detect feature points from img{idata:02d}.zdf")
point_cloud = zivid.Frame(frame_file_path).point_cloud()
detection_result = zivid.calibration.detect_feature_points(point_cloud)
Expand Down Expand Up @@ -433,7 +431,6 @@ def perform_hand_eye_calibration(


def _main() -> None:

app = zivid.Application()
user_options = _options()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@


def _main() -> None:

with zivid.Application():

np.set_printoptions(precision=2)

while True:
Expand All @@ -45,7 +43,6 @@ def _main() -> None:
).strip()

if robot_camera_configuration.lower() == "eth":

file_name = "ZividGemEyeToHand.zdf"

# The (picking) point is defined as image coordinates in camera frame. It is hard-coded for the
Expand All @@ -61,7 +58,6 @@ def _main() -> None:
break

if robot_camera_configuration.lower() == "eih":

file_name = "ZividGemEyeInHand.zdf"

# The (picking) point is defined as image coordinates in camera frame. It is hard-coded for the
Expand Down Expand Up @@ -94,7 +90,6 @@ def _main() -> None:
command = input("Enter command, s (to transform single point) or p (to transform point cloud): ").strip()

if command.lower() == "s":

print("Transforming single point")

xyz = point_cloud.copy_data("xyz")
Expand All @@ -117,7 +112,6 @@ def _main() -> None:
break

if command.lower() == "p":

print("Transforming point cloud")

point_cloud.transform(transform_base_to_camera)
Expand Down
Loading

0 comments on commit 3de3a61

Please sign in to comment.