繁体   English   中英

与 Thorlabs uc480 相机的通信

[英]Communication with Thorlabs uc480 camera

我能够使用instrumental从 Thorlabs uc480 相机获取当前图像。 我的问题是当我尝试调整grab_image的参数时。 我可以将cxleft更改为任何值并获取图像。 但是cy和 top 仅在cy=600top=300时才有效。 目的是创建一个 GUI,以便用户可以为这些参数的 select 值放大/缩小图像。

这是我的代码

import instrumental
from instrumental.drivers.cameras import uc480
from matplotlib.figure import Figure
import matplotlib.pyplot as plt

paramsets = instrumental.list_instruments()
cammer = instrumental.instrument(paramsets[0])

plt.figure()
framer= cammer.grab_image(timeout='1s',copy=True,n_frames=1,exposure_time='5ms',cx=640,
                                      left=10,cy=600,top=300)
plt.pcolormesh(framer)

如果我选择cy=600top=10 ,上面的代码不会给出图像。 是否为这些参数设置了任何特定值? 如何获得完整传感器尺寸的图像?

Thorlabs 的 Python 编程接口可在其网站上下载。 它有很好的文档记录,可以通过 pip 在本地安装。

链接: https://www.thorlabs.com/software_pages/ViewSoftwarePage.cfm?Code=ThorCam

下面是一个简单的捕获算法示例,可能有助于您入门:

    from thorlabs_tsi_sdk.tl_camera import TLCameraSDK
    from thorlabs_tsi_sdk.tl_mono_to_color_processor import MonoToColorProcessorSDK
    from thorlabs_tsi_sdk.tl_camera_enums import SENSOR_TYPE

    # open the TLCameraSDK dll
    with TLCameraSDK() as sdk:
        cameras = sdk.discover_available_cameras()
        if len(cameras) == 0:
            print("Error: no cameras detected!")

    with sdk.open_camera(cameras[0]) as camera:
        #camera.disarm() # ensure any previous session is closed
        #  setup the camera for continuous acquisition
        camera.frames_per_trigger_zero_for_unlimited = 0
        camera.image_poll_timeout_ms = 2000  # 2 second timeout
        camera.arm(2)


        # need to save the image width and height for color processing
        image_width = camera.image_width_pixels
        image_height = camera.image_height_pixels

        # initialize a mono to color processor if this is a color camera
        is_color_camera = (camera.camera_sensor_type == SENSOR_TYPE.BAYER)
        mono_to_color_sdk = None
        mono_to_color_processor = None
        if is_color_camera:
            mono_to_color_sdk = MonoToColorProcessorSDK()
            mono_to_color_processor = mono_to_color_sdk.create_mono_to_color_processor(
                camera.camera_sensor_type,
                camera.color_filter_array_phase,
                camera.get_color_correction_matrix(),
                camera.get_default_white_balance_matrix(),
                camera.bit_depth
            )

        # begin acquisition
        camera.issue_software_trigger()
        
        # get the next frame
        frame = camera.get_pending_frame_or_null()
        
        # initialize frame attempts and max limit
        frame_attempts = 0 
        max_attempts = 10

        # if frame is null, try to get a frame until
        # successful or until max_attempts is reached
        if frame is None:
            
            while frame is None:
                frame = camera.get_pending_frame_or_null()
                frame_attempts += 1

                if frame_attempts == max_attempts:
                    raise TimeoutError("Timeout was reached while polling for a frame, program will now exit")

        image_data = frame.image_buffer
        if is_color_camera:

            # transform the raw image data into RGB color data
            color_data = mono_to_color_processor.transform_to_24(image_data, image_width, image_height) 
            save_data = np.reshape(color_data,(image_height, image_width,3))            


        camera.disarm()

您还可以使用 PIL 库在捕获后处理图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM