#camera #hal #galaxy #abstraction-layer #hardware-interface #interface #daheng

gxci

A safe raw-and-HAL camera interface based on Daheng-Image's GxIAPI(Galaxy Camera SDK)

16 releases

0.3.6 Dec 21, 2024
0.3.5 Dec 5, 2024
0.3.4 Oct 24, 2024
0.3.2 Sep 28, 2024
0.1.3 Jul 12, 2024

#104 in Hardware support

Download history 345/week @ 2024-09-18 301/week @ 2024-09-25 94/week @ 2024-10-02 18/week @ 2024-10-09 4/week @ 2024-10-16 127/week @ 2024-10-23 6/week @ 2024-10-30 5/week @ 2024-11-06 1/week @ 2024-11-13 12/week @ 2024-11-27 229/week @ 2024-12-04 91/week @ 2024-12-11 124/week @ 2024-12-18 9/week @ 2024-12-25 28/week @ 2025-01-01

298 downloads per month

MIT license

240KB
3.5K SLoC

Logo逃走啦~

GXCI

Rust-based safe interface development for Daheng Industrial Camera GxIAPI


Now, the document site is available!

  1. English: https://hakochest.github.io/gxci-en/
  2. 中文: https://hakochest.github.io/gxci-cn/

Introduction

gxci(Galaxy Camera Interface)是一款用Rust基于大恒工业相机GxIAPI的库进行的接口开发;

目前已实现USB单相机的HAL库封装,raw内包含着C语言接口除去网络相机的全部内容(句柄、常量、结构、枚举、回调函数等)的直接rust实现;HAL内做了硬件抽象层的封装(目前包括连接、采图、推流),适合实际开发使用;utils内则是一些工具类函数(常用的Builder模式和Facade模式函数封装);

Gxci (Galaxy Camera Interface) is an interface developed using Rust based on the Daxi API library of Daheng Industrial Camera;

At present, HAL library encapsulation for USB single camera has been implemented, and raw contains a direct Rust implementation of all contents (handles, constants, structures, enumerations, callback functions, etc.) of the C language interface except for the network camera; HAL has encapsulated the hardware abstraction layer (currently including connections, image capture, and streaming), which is suitable for practical development and use; Inside the utilities are some utility class functions (encapsulated with commonly used Builder and Facade pattern functions);

Overview

You can get the sdk-dev-doc from the SDK of Daheng Imaging you have installed.

Quick Start

  1. Ensure you have OpenCV Rust Bindings installed.
  2. Ensure your camera version is supported by the GxIAPI SDK,and ensure you have installed the GxIAPI SDK.

the document of the environment config is follow the quick start part.

in your Cargo.toml, add the following dependencies:

[dependencies]
gxci = "0.3.6"
# It default with the feature "solo" and "use-opencv", and now there're only this two features can be used.

The solo feature can simplify some operation if you only have one camera, because it will default to the first camera in all functions.

then, you can use the following code to get a single image from the camera and save it as png.

use gxci::hal::device::*;
use gxci::hal::base::*;
use gxci::hal::control::analog::gxi_set_gain_auto_continuous;
use gxci::utils::debug::print_device_info;

fn main()->Result<()> {
    gxci_init_default()?;

    let device_num = gxi_count_devices(1000)?;
    println!("Device number: {}", device_num);

    let base_info = gxi_list_devices()?;
    for device in &base_info {
        print_device_info(&device);
    }
    
    gxi_open_device()?;

    gxi_set_gain_auto_continuous()?;

    gxi_get_image()?;

    gxi_save_image_as_png("test.png")?;

    gxi_close_device()?;

    gxci_close()?;

    Ok(())
}

The terminal output should be like this:

PS C:\Users\Chest\Documents\GitHub\crate_zone\gxci> cargo run --example hal_get_image
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
     Running `target\debug\examples\hal_get_image.exe`
Initializing GXI with DLL path: C:\Program Files\Daheng Imaging\GalaxySDK\APIDll\Win64\GxIAPI.dll
Device number: 1
p_device_info: 0x1d10264e0b0, p_buffer_size: 0x69120ff590
Vendor Name: Daheng Imaging
Model Name: MER-050-560U3C
Serial Number: KJ0180110048
Display Name: MER-050-560U3C(KJ0180110048)
Device ID: MER-050-560U3C(KJ0180110048)
User ID:
Access Status: GX_ACCESS_STATUS_UNKNOWN
Device Class: GX_DEVICE_CLASS_U3V
-----------------------
Successfully opened device index 1
Successfully sent command
int_value: 0x69120fefd8
int_value: 0x69120fefe0
enum_value: 0x69120feff8
enum_value: 0x69120fefe8
int_value: 0x69120feff0
p_frame_data: 0x69120ff448
frame_data: GX_FRAME_DATA { nStatus: 0, pImgBuf: 0x1d1042c6040, nWidth: 640, nHeight: 480, nPixelFormat: 17301513, nImgSize: 2457600, nFrameID: 0, nTimestamp: 0, reserved: [17301513] }
Successfully sent command
Successfully got image
Image saved successfully.
Successfully closed device

if your camera is as the following:

图片逃走啦~

then you will get a test.png as

图片逃走啦~

more codes just see the examples and document.

Platform Support

Now, is Windows only.

Licensing

Licensed under the MIT License.

Contributing

If you have any questions, please issue it.

If you want to contribute, please fork it and pull request.

If you want to contact me, you can email me: zoneherobrine@gmail.com;

or by Tencent QQ: 2212540603 (with related information in the friend request)

Acknowledgments

GXCI(GalaXy Camera Interface)的命名要感谢MoonWX同学的建议,这是一个简洁明确并且很帅的名字ヽ(・∀・)ノ;

同时也感谢同专业李同学的帮助,在gx_enum的冗长的类型转换中,他与我协力在十分钟之内完成了C枚举到Rust枚举的转换;

也感谢西西帮忙找的免费图床网站,进一步压缩了包的大小( - ω - )

Also thanks to OpenAI's GPT model DELTA·E for drawing the cool LOGO :D

Dependencies

~3–31MB
~369K SLoC