Crates.io | gxci |
lib.rs | gxci |
version | |
source | src |
created_at | 2024-07-11 16:22:27.143119 |
updated_at | 2024-12-05 15:17:43.321998 |
description | A safe raw-and-HAL camera interface based on Daheng-Image's GxIAPI(Galaxy Camera SDK) |
homepage | |
repository | https://github.com/zoneherobrine/gxci |
max_upload_size | |
id | 1299741 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Rust-based safe interface development for Daheng Industrial Camera GxIAPI
The plan of 0.4 can see the Roadmap in the bottom of README.
gxci(Galaxy Camera Interface)是一款用Rust基于大恒工业相机GxIAPI的库进行的接口开发;
目前已实现USB单相机的HAL库封装,raw内包含着C语言接口除去网络相机的全部内容(句柄、常量、结构、枚举、回调函数等)的直接rust实现;HAL内做了硬件抽象层的封装(目前包括连接、采图、推流),适合实际开发使用;utils内则是一些工具类函数(常用的Builder模式和Facade模式函数封装);
旧版是一个叫做gxi_hako的crate库,里面raw部分和utils部分的不完全实现,现在已经暂时弃用了;
新版也就是这一款gxci,里面包含了raw、HAL、utils三个部分的实现;
截至目前,2024年7月11日23点45分,已经完成了features=["solo"]
部分的HAL库编写,多相机的feature还未实现,等再次闲下来再来更新吧(๑˃ᴗ˂)ﻭ
2024年9月8日21点15分,2.0更新!主要是错误处理和安全化,现在所有的库函数都是安全的了,同时建立了非常规范和健壮的错误处理。此外也更新了所有例子,消除了所有的Warning。
2024年9月19日16点09分,3.0更新!主要是增加了config模块,现在所有的HAL和raw-binding的config模块都已经实现了,你可以调节宽高、增益、白平衡以及一切已实现的相机参数!但是由于inc中部分FeatureID的缺失,所以config模块还有一些函数没有实现。此外,增加了control模块,这是基于Galaxy Viewer的侧边栏常用部分的封装。
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);
The old version was a crate library called gxi_hako, which had unsafe raw-binding implementations of the raw and utilities parts and has now been temporarily abandoned;
The new version, also known as gxci, includes the implementation of three parts: raw, HAL, and utilities;
As of 23:45 on July 11, 2024, the HAL library for the 'features=["solo"]' section has been completed, but the multi camera features have not been implemented yet. i'll update it when i have more free time (๑˃ᴗ˂)ﻭ.
As of 21:15 on September 8, 2024, 2.0 update! Mainly error handling and security, now all library functions are safe, and very standardized and robust error handling has been established. In addition, all examples have been updated and all Warnings have been resolved.
As of 16:09 on September 19, 2024, 3.0 update! Mainly added the config module, now all HAL and raw-binding config modules have been implemented, you can adjust the width, height, gain, white balance, and all the camera parameters that have been implemented! But due to the lack of some FeatureID in inc, there are still some functions in the config module that have not been implemented. In addition, the control module has been added, which is an encapsulation of the commonly used part of the sidebar of the Galaxy Viewer.
You can get the sdk-dev-doc from the SDK of Daheng Imaging you have installed.
use-imageproc
feature to avoid using OpenCV by using the imageproc
lib. But I got a endless compilation during my 0.3.0 deving time,and it's now unfinished, so the use-opencv
feature is recommanded.)the document of the environment config is follow the quick start part.
in your Cargo.toml, add the following dependencies:
[dependencies]
gxci = { version = "0.3.5", features = [ "solo", "use-opencv" ] }
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::utils::debug::print_device_info;
fn main()->Result<()> {
// the default path is "C:\\Program Files\\Daheng Imaging\\GalaxySDK\\APIDll\\Win64\\GxIAPI.dll"
// or you can use the custom path as the following:
// let dll_path = "D:\\Program Files\\Daheng Imaging\\GalaxySDK\\APIDll\\Win64\\GxIAPI.dll";
// gxci_init(dll_path)?;
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_get_image()?;
// If you need the image data, you can use one of following:
// raw means &[u8], bytes means Vec<u8>
// let image_raw = gxi_get_image_as_raw()?;
// let image_bytes = gxi_get_image_as_bytes()?;
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.
if you want to use raw functions, you can see gxi_hako crate. The only difference is that gxi_hako's functions need unsafe block.
Here mainly 7 raw-examples and 5 hal-example are provided, they are:
you can run them like:
cargo run --example hal_capture_callback
if you get a error as
error: process didn't exit successfully: `target\debug\examples\hal_capture_callback.exe` (exit code: 0xc0000135, STATUS_DLL_NOT_FOUND)
you might need to copy a opencv_world490.dll to /target/debug/examples
The OpenCV lib here is used to easily matlization the image and provide a GUI to show the image.
Anyway I think OpenCV is exactly a necessary lib in image processing region.
But the shortcoming is that the OpenCV is a little bit heavy to config and build, so there also provide a feature use-imageproc
to avoid using OpenCV by using the imageproc
lib.
But the imageproc
's compile time is also very long, especially at the nalgebra part. One day I complie the imageproc
's nalgebra for 3 hours and it's still not finished. So I think the OpenCV is still a good choice.
(Now the newest OpenCV is 4.10.0, but I haven't try it yet. So here is a 4.9.0 tutorial)
In Windows 10/11, I would like using choco as the following command to install LLVM and OpenCV 4.9.0:
choco install llvm opencv
Following are the websites:
You can add the following path to the path environment variable:
Here is an example:
D:\ProgramUnsigned\Embedded\opencv\build\bin
D:\ProgramUnsigned\Embedded\opencv\build\x64\vc16\bin
C:\ProgramData\chocolatey\bin
C:\Program Files\LLVM\bin
OPENCV_INCLUDE_PATHS ...\opencv\build\include OPENCV_LINK_LIBS opencv_world490 OPENCV_LINK_PATHS ...\opencv\build\x64\vc16\lib
here is an example:
OPENCV_INCLUDE_PATHS D:\ProgramUnsigned\Embedded\opencv\build\include
OPENCV_LINK_LIBS opencv_world490
OPENCV_LINK_PATHS D:\ProgramUnsigned\Embedded\opencv\build\x64\vc16\lib
Sometimes, you need to copy the opencv_world490.dll to the target directory, which is the same as the exe file.
You also need to install the GxIAPI SDK, which can be downloaded from the official website.
Just install the SDK for your platform.
You need to connect the camera to your computer's USB, and make sure the camera is powered on.
Then all the environment is ready.
USB3.0 Camera
Gige Camera
Now, is Windows only.
Licensed under the MIT License.
Uhmmm... placeholder,I think i will do this solo in a part of time.
if you have some problem,just issue it.
other ways you can contact me by email: zoneherobrine@gmail.com;
or by Tencent QQ: 2212540603 (with related information in the friend request)
GXCI(GalaXy Camera Interface)的命名要感谢MoonWX同学的建议,这是一个简洁明确并且很帅的名字ヽ(・∀・)ノ;
同时也感谢同专业李同学的帮助,在gx_enum的冗长的类型转换中,他与我协力在十分钟之内完成了C枚举到Rust枚举的转换;
也感谢西西帮忙找的免费图床网站,进一步压缩了包的大小( - ω - )
同时也感谢OpenAI的GPT模型DELTA·E绘制的炫酷LOGO :D
he naming of GXCI (GalaXy Camera Interface) is thanks to MoonWX's suggestion, which is a concise, clear, and handsome nameヽ(・∀・)ノ;
Also, I would like to express my gratitude to fellow student Li for his assistance in the lengthy type conversion process at gx-enum. Together with me, we were able to complete the conversion from the C enum to the Rust enum within ten minutes;
Thanks to Sisyphus for helping me find a free image hosting website, which further compressed the package size ( - ω - )
Also thanks to OpenAI's GPT model DELTA·E for drawing the cool LOGO :D
Here total 7 modules in HAL, they are: