#camera-image #interface #api #image-format #zwo #asi #cameraunit

bin+lib cameraunit_asi

An efficient and ergonomic interface to capture images using cameras

13 stable releases

4.0.2 Apr 4, 2024
3.0.1 Apr 4, 2024
2.4.1 Oct 3, 2023
2.1.2 Sep 30, 2023

#173 in Hardware support

Download history 3/week @ 2024-02-16 4/week @ 2024-02-23 1/week @ 2024-03-01 10/week @ 2024-03-08 4/week @ 2024-03-15 438/week @ 2024-03-29 204/week @ 2024-04-05

652 downloads per month




cameraunit_asi implements the API traits provided by cameraunit to capture frames from CCD/CMOS based detectors from ZWO. This crate provides wrappers for the ASI Camera SDK C library to access the cameras for image capture and other housekeeping functions in a safe way. Images are obtained as cameraunit::ImageData with extensive metadata.

As is, this Rust driver is intended for use on Linux and macOS platforms.

You can use cameraunit_asi to:

  • Access a connected ZWO ASI camera,
  • Acquire images from the in supported pixel formats (using the image crate as a backend),
  • Save these images to FITS files (requires the cfitsio C library, and uses the fitsio crate) with extensive metadata,
  • Alternatively, use the internal image::DynamicImage object to obtain JPEG, PNG, BMP etc.


  1. Install libusb-1.0-dev on your system.
  2. Obtain the ZWO ASI Camera SDK.
  3. Extract the ASI_linux_mac_SDK_VX.XX.tar.bz2 from the ZIP, and extract its contents (tar -xf ASI_linux_mac_SDK_VX.XX.tar.bz2), which will extract the contents to ASI_linux_mac_SDK_VX.XX in the current directory.
  4. Copy ASI_linux_mac_SDK_VX.XX/include/ASICamera2.h to /usr/local/include, or any other directory in your include path.
  5. Open README.txt in ASI_linux_mac_SDK_VX.XX/lib to determine the applicable system platform. Follow the additional commands to install the udev rules so that the cameras can be accessed without sudo.
  6. Copy ASI_linux_mac_SDK_VX.XX/lib/your_target_platform/libASICamera* to a directory in your library path (probably /usr/local/lib), and ensure LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (macOS) contains the library path.


Add this to your Cargo.toml:

cameraunit_asi = "2.4.1"

and this to your source code:

use cameraunit::{CameraUnit, CameraInfo, ImageData};
use cameraunit_asi::{num_cameras, open_first_camera, ASIImageFormat};


Minimally, the following can open the first available camera, capture a single image, and save it to a FITS file:

let nc = num_cameras();
if nc <= 0 {
let (mut cam, _caminfo) = open_first_camera()
    .map_err(|x| println!("Opening camera: {}", x.to_string()))
    .map_err(|x| println!("Setting exposure: {}", x.to_string()))
    .map_err(|x| println!("Start exposure: {}", x.to_string()))
while !cam
    .map_err(|x| println!("Check exposure: {}", x.to_string()))
let img = cam
    .map_err(|x| println!("Downloading image: {}", x.to_string()))
img.save_fits(Path::new("./"), "test", "asicam_test", true, true)

Note, that the unused _caminfo object implements the cameraunit::CameraInfo trait and can be cloned and passed around to multiple threads.

For a more complete example, refer to the bundled program.


The example program can be installed using

$ cargo install cameraunit_asi

and executed using

$ asicamera_capture


~364K SLoC