使用 IC Imaging Control 4 SDK 進行 Jupyterlab開發
跳至導覽
跳至搜尋
安裝環境
- 安裝 JupyterLab 開啟終端機或命令提示字元,並輸入以下指令安裝 Jupyterlab:
pip install jupyterlab
- 安裝 IC Imaging Control 4 SDK 開啟終端機或命令提示字元,並輸入以下指令安裝 IC Imaging Control 4 SDK:
python3 -m pip install imagingcontrol4
- 安裝相機驅動 GigE Vision 相機 GenTL Producer / USB3 Vision 相機 GenTL Producer / 非 GenICam 相機的 GenTL Producer (BETA)
- 範例可透過連結下載 https://github.com/TheImagingSource/ic4-examples/tree/master/python
- 啟動 JupyterLab ,在終端機或命令提示字元輸入: 瀏覽器會自動開啟一個新的頁面,為 JupyterLab 的介面。
jupyter lab
擷取影像的範例:
import imagingcontrol4 as ic4
ic4.Library.init()
# Create a Grabber object
grabber = ic4.Grabber()
# Open the first available video capture device
first_device_info = ic4.DeviceEnum.devices()[0]
grabber.device_open(first_device_info)
# Set the resolution to 640x480
grabber.device_property_map.set_value(ic4.PropId.WIDTH, 640)
grabber.device_property_map.set_value(ic4.PropId.HEIGHT, 480)
# Create a SnapSink. A SnapSink allows grabbing single images (or image sequences) out of a data stream.
sink = ic4.SnapSink()
# Setup data stream from the video capture device to the sink and start image acquisition.
grabber.stream_setup(sink, setup_option=ic4.StreamSetupOption.ACQUISITION_START)
try:
# Grab a single image out of the data stream.
image = sink.snap_single(1000)
# Print image information.
print(f"Received an image. ImageType: {image.image_type}")
# Save the image.
image.save_as_bmp("test.bmp")
except ic4.IC4Exception as ex:
print(ex.message)
# Stop the data stream.
grabber.stream_stop()