ZWO ASI 相机 - Python SDK 包装器 - 不触发

问题描述 投票:0回答:1

我正在尝试使用触发器控制 ZWO ASI 相机。相机不触发。

我使用 Python wrapper 作为 ZWO asi SDK。我可以控制相机但不能触发它。

什么有效

  • 我可以连接到相机并执行基本操作,例如更改图像格式和读取温度。我可以在正常模式下捕捉图像。
  • 相机属性表明相机是触发相机,并且所使用的相机模式在设备上可用。
  • Arduino 产生 5V 触发信号。使用示波器验证信号。

什么不起作用

  • 使用(软件生成的软触发器)触发相机。
  • 使用硬件 5V 触发器触发相机

此代码不会触发相机:

# Library loading
import zwoasi as asi
import os
import pprint
import time
asi.init(r"C:\Program Files\ASIStudio\ASICamera2.dll")


# Connect to the camera
num_cameras = asi.get_num_cameras()
print(num_cameras)

if num_cameras == 0:
    raise ValueError("No cameras found")

camera_id = 0  # use first camera from list
cameras_found = asi.list_cameras()
print(f"list of cameras found: {cameras_found}")

# Make camera object
camera = asi.Camera(camera_id)
camera_info = camera.get_camera_property()
print(f"Camera properties :")
pprint.pprint(camera_info)
print("Is triggercam : {}".format(camera_info["IsTriggerCam"]))
# this returns the camera is a trigger cam

# Verify that the trigger soft edge mode is available for this camera
support_mode = camera.get_camera_support_mode()
print(f"Camera support mode : {support_mode}")

# Try to take an image with a soft trigger
filename = "image_mono16_triggered.tiff"
camera.set_image_type(asi.ASI_IMG_RAW16)
camera.set_camera_mode(asi.ASI_MODE_TRIG_SOFT_EDGE)
camera.send_soft_trigger(True)
camera.capture(filename=filename)

*预期结果:* 相机触发并生成图像 *结果:*脚本保持阻塞状态。没有生成图像

或者,尝试使用硬件触发器:

camera.set_camera_mode(asi.ASI_MODE_TRIG_RISE_EDGE)
# Here, I trigger the Arduino to send the 5V signal. The signal is clearly present on the oscilloscope.
camera.capture(filename=filename)
print("Triggered image acquisition")

*预期结果:* 相机触发并生成图像 *结果:*脚本保持阻塞状态。没有生成图像

我错过了什么?

python sdk camera
1个回答
0
投票

最后,我能够通过两个线程来触发相机,一个用于读取相机,一个用于触发相机。

import zwoasi as asi
import os
import pprint
import time
import logging
import threading
import cv2

EXPOSURE_TIME = 310


def capture_frame(camera):
    logging.info("Thread starting")
    start_time = time.time()
    camera.stop_video_capture()
    camera.set_camera_mode(asi.ASI_MODE_TRIG_SOFT_EDGE)
    camera.start_video_capture()
    current_time = time.time()
    F_CAPTURED = False

    while (duration := (current_time - start_time)) < 20.0:
        try:
            image = camera.capture_video_frame(
                timeout=2 * EXPOSURE_TIME + 500, filename=f"triggered_image.png"
            )
            logging.info(f"image saved to triggered image")
            cv2.imshow("image", image)
            logging.info(f"image saved to triggered image")
            break
        except asi.ZWO_IOError:
            logging.debug("no image captured")
            pass
        current_time = time.time()
        logging.info(f"trigger capturing ongoing : {duration}")
    else:
        logging.info("trigger capturing timed out")
    logging.debug("End of capturing function")


asi.init(r"C:\Program Files\ASIStudio\ASICamera2.dll")

if __name__ == "__main__":
    format = "%(asctime)s: %(message)s"
    logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")

    num_cameras = asi.get_num_cameras()
    logging.info(f"Number of cameras: {num_cameras}")

    if num_cameras == 0:
        raise ValueError("No cameras found")

    camera_id = 0  # use first camera from list
    cameras_found = asi.list_cameras()
    logging.info(f"list of cameras found: {cameras_found}")
    camera = asi.Camera(camera_id)
    camera_info = camera.get_camera_property()
    logging.debug(f"Camera properties :\n{pprint.pformat(camera_info, depth=3)}")

    logging.debug("Is triggercam : {}".format(camera_info["IsTriggerCam"]))
    logging.debug(f"Camera mode : {camera.get_camera_mode()}")

    # Get all of the camera controls
    controls = camera.get_controls()
    logging.info(f"Camera controls : \n{pprint.pformat(controls)}")

    # Use minimum USB bandwidth permitted
    camera.set_control_value(
        asi.ASI_BANDWIDTHOVERLOAD, camera.get_controls()["BandWidth"]["MinValue"]
    )

    # Set some sensible defaults. They will need adjusting depending upon
    # the sensitivity, lens and lighting conditions used.
    camera.disable_dark_subtract()

    camera.set_control_value(asi.ASI_GAIN, 150)
    camera.set_control_value(asi.ASI_EXPOSURE, EXPOSURE_TIME)  # microseconds
    camera.set_control_value(asi.ASI_WB_B, 99)
    camera.set_control_value(asi.ASI_WB_R, 75)
    camera.set_control_value(asi.ASI_GAMMA, 50)
    camera.set_control_value(asi.ASI_BRIGHTNESS, 50)
    camera.set_control_value(asi.ASI_FLIP, 0)

    logging.info("Enabling stills mode")
    try:
        # Force any single exposure to be halted
        camera.stop_video_capture()
        camera.stop_exposure()
    except (KeyboardInterrupt, SystemExit):
        raise

    logging.info("Capturing a single 8-bit mono image")
    filename = "image_mono.jpg"
    camera.set_image_type(asi.ASI_IMG_RAW8)
    camera.capture(filename=filename)
    logging.debug("Saved to %s" % filename)

    logging.debug("Capturing a single 16-bit mono image")
    filename = "image_mono16.tiff"
    camera.set_image_type(asi.ASI_IMG_RAW16)
    st = time.time()
    camera.capture(filename=filename)
    fin = time.time()
    logging.info("Saved to %s" % filename)
    logging.debug(f"time to capture image : {fin - st}")
    logging.info(
        f"Camera temperature = {camera.get_control_value(asi.ASI_TEMPERATURE)}"
    )

    try:
        # Force any single exposure to be halted
        camera.stop_exposure()
    except (KeyboardInterrupt, SystemExit):
        raise

    support_mode = camera.get_camera_support_mode()

    print(f"Camera support mode : {support_mode}")

    filename = "image_mono16_triggered.tiff"

    camera.set_image_type(asi.ASI_IMG_RAW16)

    thread_capture = threading.Thread(target=capture_frame, args=(camera,))
    thread_capture.start()
    for i in range(5):
        time.sleep(2)
        logging.info("sending trigger")
        camera.send_soft_trigger(True)
        time.sleep(3)
        logging.info("waiting")

    camera.stop_video_capture()
    camera.close()
    logging.info("end")
© www.soinside.com 2019 - 2024. All rights reserved.