ZWO ASI摄像头- Python SDK Package 器-不触发

t9aqgxwy  于 2023-11-15  发布在  Python
关注(0)|答案(1)|浏览(123)

我试图用触发器控制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")

  • 预期结果:* 相机触发并生成图像 * 结果:* 脚本保持阻塞。不生成图像

我错过了什么?

pinkon5k

pinkon5k1#

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

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

字符串

相关问题