-
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.
This commit * Adds projection samples project_image_start_and_stop.py and read_and_project_image.py. The samples respectively, * Show how to start and stop image projection with the projector. * Show how to create a projector image from a 2d image from file and project it. See support.zivid.com/en/latest/academy/camera/2d-image-projection.html for details. * Adds verify_camera_in_field_from_zdf.py to check dimension trueness of a Zivid camera from a ZDF file. This allows the camera to be verified while it is running in production. * Modifies capture_2d_and_3d.py to use a new API function call; zivid.Pixelmapping. The API function simplifies mapping from a full resolution 2d image to a subsampled point cloud since 2.11 adds 4x4subsampling. See support.zivid.com/en/latest/academy/applications/piece-picking/ 2d3d-strategy.html and support.zivid.com/en/latest/academy/ camera/monochrome-capture.html for details. * Modifies samples that output camera info to also output the camera state. SDK 2.11 adds camera status to camera state. The camera status shows if a camera is available, inaccessible, busy, requires firmware update, etc. This is a result of improved network discovery. See the SDK Changelog support.zivid.com/en/latest/api-reference/changelog.html#sdk-changelog for further details.
- Loading branch information
Showing
14 changed files
with
304 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
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
63 changes: 63 additions & 0 deletions
63
source/camera/maintenance/verify_camera_in_field_from_zdf.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,63 @@ | ||
""" | ||
Check the dimension trueness of a Zivid camera from a ZDF file. | ||
This example shows how to verify the local dimension trueness of a camera from a ZDF file. If the trueness is much worse | ||
than expected, the camera may have been damaged by shock in shipping or handling. If so, look at the | ||
correct_camera_in_field sample sample. | ||
Why is verifying camera accuracy from a ZDF file useful? | ||
Let us assume that your system is in production. You want to verify the accuracy of the camera while the system is running. | ||
At the same time, you want to minimize the time the robot and the camera are used for anything else than their main task, | ||
e.g., bin picking. Instead of running a full infield verification live, which consists of capturing, detecting, and | ||
estimating accuracy, you can instead only capture and save results to ZDF files on disk. As the robot and the camera go | ||
back to their main tasks, you can load the ZDF files and verify the accuracy offline, using a different PC than the one | ||
used in production. In addition, you can send these ZDF files to Zivid Customer Success for investigation. | ||
Note: This example uses experimental SDK features, which may be modified, moved, or deleted in the future without notice. | ||
""" | ||
|
||
import zivid | ||
from sample_utils.paths import get_sample_data_path | ||
from zivid.experimental import calibration | ||
|
||
|
||
def _main() -> None: | ||
app = zivid.Application() | ||
|
||
file_camera = get_sample_data_path() / "BinWithCalibrationBoard.zfc" | ||
print(f"Creating virtual camera using file: {file_camera}") | ||
with app.create_file_camera(file_camera) as camera: | ||
# Calibration board can be captured live, while the system is in production, and saved to ZDF file, for later use in | ||
# offline infield verification | ||
|
||
print("Capturing calibration board") | ||
with calibration.capture_calibration_board(camera) as frame: | ||
data_file = "FrameWithCalibrationBoard.zdf" | ||
print(f"Saving frame to file: {data_file}, for later use in offline infield verification") | ||
frame.save(data_file) | ||
|
||
# The ZDF captured with captureCalibrationBoard(camera) that contains the calibration board can be loaded for | ||
# offline infield verification | ||
|
||
print(f"Reading frame from file: {data_file}, for offline infield verification") | ||
with zivid.Frame(data_file) as frame: | ||
print("Detecting calibration board") | ||
detection_result = calibration.detect_feature_points(frame) | ||
|
||
infield_input = calibration.InfieldCorrectionInput(detection_result) | ||
if not infield_input.valid(): | ||
raise RuntimeError( | ||
f"Capture not valid for infield verification! Feedback: {infield_input.status_description()}" | ||
) | ||
|
||
print(f"Successful measurement at {detection_result.centroid()}") | ||
camera_verification = calibration.verify_camera(infield_input) | ||
print( | ||
f"Estimated dimension trueness error at measured position: {camera_verification.local_dimension_trueness()*100:.3f}%" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |