使用 IC Imaging Control 4 SDK 進行 Jupyterlab開發

出自The Imaging Source Knowledgebase Taiwanese
跳至導覽 跳至搜尋

安裝環境

  • 安裝 JupyterLab 開啟終端機或命令提示字元,並輸入以下指令安裝 Jupyterlab:
    pip install jupyterlab
    

擷取影像的範例:

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()