-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Samples: Automatic updates to public repository
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
1 parent
bd91ba3
commit 2e8b0bd
Showing
15 changed files
with
321 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated file, do not edit @ 2023-10-30 22:22:03 | ||
# | ||
# Command: | ||
# python infrastructure/tools/dependency_updater/dependency_updater.py --remote-update --remote-name origin --base-branch master --access-token <ACCESS_TOKEN> | ||
# | ||
# To update all Python requirements and constraints manually, you should run: | ||
# | ||
# python infrastructure/tools/dependency_updater/dependency_updater.py | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.11 | ||
# by the following command: | ||
# | ||
# pip-compile --all-extras --extra-index-url=http://se-ci-elastic-server-1.localdomain:8081/artifactory/api/pypi/zivid-pypi/simple --output-file=sdk/samples/public/python/pyproject.constraints --strip-extras --trusted-host=se-ci-elastic-server-1.localdomain sdk/samples/public/python/pyproject.toml | ||
# | ||
--extra-index-url http://se-ci-elastic-server-1.localdomain:8081/artifactory/api/pypi/zivid-pypi/simple | ||
--trusted-host se-ci-elastic-server-1.localdomain | ||
|
68 changes: 68 additions & 0 deletions
68
source/applications/basic/visualization/project_image_start_and_stop.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
Start the Image Projection and Stop it. | ||
How to stop the image projection is demonstrated in three different ways: | ||
- calling stop() function on the projected image handle | ||
- projected image handle going out of scope | ||
- triggering a 3D capture | ||
""" | ||
|
||
from typing import Tuple | ||
|
||
import numpy as np | ||
import zivid | ||
import zivid.experimental.calibration | ||
import zivid.experimental.projection | ||
|
||
|
||
def create_projector_image(resolution: Tuple, color: Tuple) -> np.ndarray: | ||
"""Create projector image (numpy array) of given color. | ||
Args: | ||
resolution: projector resolution | ||
color: bgra | ||
Returns: | ||
An image (numpy array) of color given by the bgra value | ||
""" | ||
projector_image = np.full((resolution[0], resolution[1], len(color)), color, dtype=np.uint8) | ||
return projector_image | ||
|
||
|
||
def _main() -> None: | ||
with zivid.Application() as app: | ||
print("Connecting to camera") | ||
with app.connect_camera() as camera: | ||
print("Retrieving the projector resolution that the camera supports") | ||
projector_resolution = zivid.experimental.projection.projector_resolution(camera) | ||
|
||
red_color = (0, 0, 255, 255) | ||
|
||
projector_image = create_projector_image(projector_resolution, red_color) | ||
|
||
project_image_handle = zivid.experimental.projection.show_image_bgra(camera, projector_image) | ||
|
||
input('Press enter to stop projecting using the ".stop()" function') | ||
project_image_handle.stop() | ||
|
||
green_color = (0, 255, 0, 255) | ||
projector_image = create_projector_image(projector_resolution, green_color) | ||
with zivid.experimental.projection.show_image_bgra(camera, projector_image): | ||
input("Press enter to stop projecting with context manager") | ||
|
||
pink_color = (114, 52, 237, 255) | ||
projector_image = create_projector_image(projector_resolution, pink_color) | ||
project_image_handle = zivid.experimental.projection.show_image_bgra(camera, projector_image) | ||
|
||
input("Press enter to stop projecting by performing a 3D capture") | ||
settings = zivid.Settings() | ||
settings.acquisitions.append(zivid.Settings.Acquisition()) | ||
camera.capture(settings) | ||
|
||
input("Press enter to exit") | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
83 changes: 83 additions & 0 deletions
83
source/applications/basic/visualization/read_and_project_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
Read a 2D image from file and project it using the camera projector. | ||
The image for this sample can be found under the main instructions for Zivid samples. | ||
""" | ||
|
||
from datetime import timedelta | ||
from typing import Tuple | ||
|
||
import cv2 | ||
import numpy as np | ||
import zivid | ||
import zivid.experimental.calibration | ||
import zivid.experimental.projection | ||
from sample_utils.paths import get_sample_data_path | ||
|
||
|
||
def _resize_and_create_projector_image(image_to_resize: np.ndarray, final_resolution: Tuple) -> np.ndarray: | ||
"""Resizes an image to a given resolution. | ||
Args: | ||
image_to_resize: openCV image that needs to be resized | ||
final_resolution: resolution after resizing | ||
Returns: | ||
An image with a resolution that matches the projector resolution | ||
""" | ||
resized_image = cv2.resize( | ||
image_to_resize, (final_resolution[1], final_resolution[0]), interpolation=cv2.INTER_LINEAR | ||
) | ||
projector_image = cv2.cvtColor(resized_image, cv2.COLOR_BGR2BGRA) | ||
|
||
return projector_image | ||
|
||
|
||
def _main() -> None: | ||
with zivid.Application() as app: | ||
print("Connecting to camera") | ||
with app.connect_camera() as camera: | ||
image_file = get_sample_data_path() / "ZividLogo.png" | ||
print("Reading 2D image from file: ") | ||
input_image = cv2.imread(str(image_file)) | ||
if input_image is None: | ||
raise RuntimeError(f"File {image_file} not found or couldn't be read.") | ||
|
||
print(f"Input image size: {input_image.shape[:2]}") | ||
|
||
print("Retrieving the projector resolution that the camera supports") | ||
projector_resolution = zivid.experimental.projection.projector_resolution(camera) | ||
|
||
print(f"Resizing input image to fit projector resolution:{projector_resolution}") | ||
projector_image = _resize_and_create_projector_image( | ||
image_to_resize=input_image, final_resolution=projector_resolution | ||
) | ||
|
||
projector_image_file = "ProjectorImage.png" | ||
print(f"Saving the projector image to file: {projector_image_file}") | ||
cv2.imwrite(projector_image_file, projector_image) | ||
|
||
print("Displaying the projector image") | ||
|
||
with zivid.experimental.projection.show_image_bgra(camera, projector_image) as projected_image: | ||
settings_2d = zivid.Settings2D() | ||
settings_2d.acquisitions.append( | ||
zivid.Settings2D.Acquisition( | ||
brightness=0.0, exposure_time=timedelta(microseconds=20000), aperture=2.83 | ||
) | ||
) | ||
|
||
print("Capturing a 2D image with the projected image") | ||
frame_2d = projected_image.capture(settings_2d) | ||
|
||
captured_image_file = "CapturedImage.png" | ||
print(f"Saving the captured image: {captured_image_file}") | ||
frame_2d.image_bgra().save(captured_image_file) | ||
|
||
input("Press enter to stop projecting ...") | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.