Smart Vision C++ 接口文档
Smart Vision SDK C++ API
tip
To compile with Smart Vision SDK C++ API, include the Smart Vision SDK header file:
#include "smart_vision.hpp"
When linking, specify the Smart Vision SDK shared library, for example:
$g++ example.cpp -o demo -lsmartvision -L/usr/local/lib/
Smart Vision SDK header file path: /usr/local/include/aidlux/smartvision/smart_vision.hpp
Smart Vision SDK library file path: /usr/local/lib/libsmartvision.so
C++ API Overview
| Class | Public Member Functions | Description |
|---|---|---|
| Camera | int8_t open(GetImageCB cb) | Open camera in parameterless mode |
int8_t open(const DeviceParam & dev_param, GetImageCB cb) | Open camera with parameters | |
void start_capture(void) | Start streaming (Note: USB and Hikvision cameras do not support stream control, same below) | |
void stop_capture(void) | Stop streaming | |
int8_t close() | Close camera | |
void set_camera_type(CameraType camera_type) | Set camera type. Supported types: MIPI_CAMERA_ENUM1 / USB_CAMERA_ENUM2 / USB_CAMERA_ENUM3. Default is MIPI. |
| Struct | Member Variable | Type | Description |
|---|---|---|---|
| DeviceParam | cfg_name | const char * | Path to parameter configuration file |
| Image | data | const char * | Pointer to buffer containing image data |
| w | uint64_t | Target image width | |
| h | uint64_t | Target image height | |
| c | uint64_t | Number of image channels (typically 3) | |
| length | uint64_t | Memory length occupied by image data | |
| IOConfig | do1_keeptime | uint32_t | Signal 1 duration |
| do2_keeptime | uint32_t | Signal 2 duration | |
| do1 | SignalType | Pin 1 | |
| do2 | SignalType | Pin 2 | |
| TcpConfig | ip | const char * | IP address |
| port | uint16_t | Port number | |
| SVSdkMemfdInfo | srcYPlaneStride | int | Width of YUV data |
| srcSliceHeight | int | Height of YUV data | |
| memCopyStartIndex | int | Start index value (Note: Start index equals End index) | |
| memCopyEndIndex | int | End index value | |
| planeOffset | int | YUV offset value | |
| cam_id | int | Camera index ID |
| Public Function | Description |
|---|---|
void set_log_level(SVLogLevel log_level) | Set log level |
void set_log_destination(const char* destinationPath, bool also_to_stderr) | Set log file name and path |
void log_to_stderr() | Output logs to terminal. Once set, log files will not be saved. Generally not recommended. |
typedef std::function<int8_t( const Image & , const SVSdkMemfdInfo & )> GetImageCB | Used as input parameter for open() function to acquire image resources. This function is user-defined. The interface only provides type definition to standardize the callback function definition. |
int8_t get_signal_sending_mode(IOConfig & iosetting, TcpConfig & tcpsetting) | Get signal output configuration. Determine whether IO or TCP configuration is returned based on the return value. If return value is 1, IO configuration is returned from iosetting object. |
int8_t set_io_signal_send_mode(SignalType do1, SignalType do2, uint32_t do1_keeptime = 0, uint32_t do2_keeptime = 0) | Set IO signal output configuration. For example, setting do1 to NG_SIGNAL means pin 1 can only send NG signals. Note that pin 1 and pin 2 cannot be set to the same signal type simultaneously (e.g., both NG or both alarm). |
int8_t set_tcp_signal_send_mode(const char* ip, uint16_t port) | Set TCP signal output configuration. The IP address and port are for the server side. |
int8_t set_off_mode() | Set OFF mode to disable signal output. |
int8_t io_send_ng() | Send NG signal via IO. |
int8_t io_send_alarm_raising() | Send alarm signal via IO. |
int8_t io_send_alarm_clear() | Send alarm clear signal via IO. |
int8_t tcp_send_ng() | Send NG signal via TCP. |
int8_t tcp_send_alarm() | Send alarm signal via TCP. |
int8_t tcp_send_alarmclear() | Send alarm clear signal via TCP. |
int8_t save_result(const char *release_id, const char *release_version, const char *origin_file, const char *mask_file, const char *final_file, const char *additional = "") | Package image analysis task result file paths and additional information as JSON and report to local SVE service. |
int8_t notify_sve(SPhase phase_enum) | Send current task phase notification to local SVE service via HTTP (POST) request. |
| Enum | Member Variable | Type | Description |
|---|---|---|---|
| SVLogLevel | SINFO | uint8_t | Log level SINFO |
| SWARNING | uint8_t | Log level SWARNING | |
| SERROR | uint8_t | Log level SERROR | |
| SDEBUG | uint8_t | Log level SDEBUG | |
| SOFF | uint8_t | Log level SOFF (log disabled) | |
| SignalType | OFF | uint8_t | Disable signal output |
| NG_SIGNAL | uint8_t | NG signal output mode | |
| ALARM_SIGNAL | uint8_t | Alarm signal output mode | |
| OK_SIGNAL | uint8_t | OK signal output mode | |
| CameraType | MIPI_CAMERA_ENUM1 | uint8_t | MIPI camera |
| USB_CAMERA_ENUM2 | uint8_t | Generic USB camera | |
| USB_CAMERA_ENUM3 | uint8_t | Hikvision USB camera |
Camera Class
Operations related to instantiating Camera objects. Camera operations such as opening and capturing images are all based on instantiated Camera objects.
warning
Unless otherwise specified, all definitions belong to the Aidlux::SmartVision namespace. Import them in code using:
using namespace Aidlux::SmartVision;
Open Camera (Parameterless Mode)
| API | int8_t open(GetImageCB cb) |
|---|---|
| Description | Open camera in parameterless mode. |
| Parameters | Input parameter is a callback function. Callback function is user-defined. See Callback Function GetImageCB for details. |
| Return Value | 0: Success. -1: Failure. |
Example (camera is an instance of Camera class, same below):
// Open camera in parameterless mode
int8_t res = camera.open(my_get_img_cb);Open Camera (With Parameters)
| API | int8_t open(const DeviceParam & dev_param, GetImageCB cb) |
|---|---|
| Description | Open camera with parameters. |
| Parameters | dev_param: Instance of DeviceParam struct. cb: Callback function. Callback function is user-defined. See Callback Function GetImageCB for details. |
| Return Value | 0: Success. -1: Failure. |
Example:
// Open camera with parameters
int8_t res = camera.open(dev_param, my_get_img_cb);Start Streaming
| API | void start_capture(void) |
|---|---|
| Description | Start streaming |
| Parameters | None |
| Return Value | None |
Example:
// Start streaming
camera.start_capture();Stop Streaming
| API | void stop_capture(void) |
|---|---|
| Description | Stop streaming |
| Parameters | None |
| Return Value | None |
Example:
// Stop streaming
camera.stop_capture();Close Camera (Function close)
| API | int8_t close() |
|---|---|
| Description | Close camera |
| Parameters | None |
| Return Value | 0: Success. -1: Failure. |
Example:
// Close camera
camera.close();Set Camera Type (Function set_camera_type)
| API | void set_camera_type(CameraType camera_type) |
|---|---|
| Description | Set camera type |
| Parameters | camera_type: CameraType enum value. Supported types: MIPI_CAMERA_ENUM1 / USB_CAMERA_ENUM2 / USB_CAMERA_ENUM3 |
| Return Value | None |
Example:
// Set camera type to Hikvision camera
camera.set_camera_type(USB_CAMERA_ENUM3);Struct DeviceParam
Defines the path to parameter configuration file. This configuration file is used to configure camera parameters. Therefore, this struct is only used when opening camera with parameters.
| Member Variable | Type | Default | Description |
|---|---|---|---|
| cfg_name | const char* | Path to parameter configuration file |
Struct Image
Defines image data related information, including image configuration and pointer variables.
| Member Variable | Type | Default | Description |
|---|---|---|---|
| data | const char* | Pointer to buffer containing data | |
| w | uint64_t | Target image width | |
| h | uint64_t | Target image height | |
| c | uint64_t | Number of image channels (typically 3) | |
| length | uint64_t | Memory length occupied by image data |
Struct IOConfig
Defines IO signal output configuration.
| Member Variable | Type | Default | Description |
|---|---|---|---|
| do1_keeptime | uint32_t | Signal 1 duration | |
| do2_keeptime | uint32_t | Signal 2 duration | |
| do1 | SignalType | Pin 1 | |
| do2 | SignalType | Pin 2 |
Struct TcpConfig
Defines TCP signal output configuration.
| Member Variable | Type | Default | Description |
|---|---|---|---|
| ip | const char* | IP address | |
| port | uint16_t | Port number |
Struct SVSdkMemfdInfo
Defines data buffer information.
| Member Variable | Type | Default | Description |
|---|---|---|---|
| srcYPlaneStride | int | Width of YUV data | |
| srcSliceHeight | int | Height of YUV data | |
| memCopyStartIndex | int | Start index value (Note: Start index equals End index) | |
| memCopyEndIndex | int | End index value | |
| planeOffset | int | YUV offset value | |
| cam_id | int | Camera index ID |
Set Log Level (Function set_log_level)
| API | void set_log_level(SVLogLevel log_level) |
|---|---|
| Description | Set log level. |
| Parameters | log_level: SVLogLevel enum. See SVLogLevel Enum for details. |
| Return Value | None |
Example:
// Set log level
Aidlux::SmartVision::set_log_level(SVLogLevel::SINFO);Set Log File Name and Path (Function set_log_destination)
| API | void set_log_destination(const char* destinationPath, bool also_to_stderr) |
|---|---|
| Description | Set log file name and path |
| Parameters | destinationPath: Log file path, default is "./aidclog_smart_vision_". also_to_stderr: Whether to output to terminal, default is false |
| Return Value | None |
Example:
// Set log file name and path
const char* log_path = "./aidclog_smart_vision_";
Aidlux::SmartVision::set_log_destination(log_path);Output Logs to Terminal (Function log_to_stderr)
| API | void log_to_stderr() |
|---|---|
| Description | Output logs to terminal. Once set, log files will not be saved. Generally not recommended. |
| Parameters | None |
| Return Value | None |
Example:
// Set log output to terminal
log_to_stderr();Log Level (Enum SVLogLevel)
| Member Variable | Type | Default | Description |
|---|---|---|---|
| SINFO | uint8_t | 0 | Log level SINFO |
| SWARNING | uint8_t | Log level SWARNING | |
| SERROR | uint8_t | Log level SERROR | |
| SDEBUG | uint8_t | Log level SDEBUG | |
| SOFF | uint8_t | Log level SOFF (log disabled) |
Task Phase (Enum SPhase)
| Member Variable | Type | Default | Description |
|---|---|---|---|
| OPEN_CAMERA_ING_ENUM1 | 1 | start camera loading | |
| OPEN_CAMERA_SUC_ENUM2 | 2 | start camera successfully | |
| OPEN_CAMERA_FAIL_ENUM3 | 3 | start camera failed | |
| LOAD_MODEL_ING_ENUM4 | 4 | model loading | |
| LOAD_MODEL_SUC_ENUM5 | 5 | model loaded successfully | |
| LOAD_MODEL_FAIL_ENUM6 | 6 | Model load failed | |
| WAIT_IMAGE_ING_ENUM7 | 7 | waiting for image |
Callback Function GetImageCB
| API | typedef std::function<int8_t(const Image & , const SVSdkMemfdInfo &)> GetImageCB |
|---|---|
| Description | Used as input parameter for open() function to acquire image resources. This function is user-defined. The interface only provides type definition to standardize the callback function definition. |
| Parameters | First parameter is an Image struct instance through which data is passed. Second parameter is an SVSdkMemfdInfo struct containing buffer index, YUV data width/height, etc. |
| Return Value | User-defined |
Example:
// Callback function definition
int8_t my_get_img_cb(const Image & cap_img, const SVSdkMemfdInfo & mem_info)
{
......
return 0;
}Get Signal Output Configuration (Function get_signal_sending_mode)
| API | int8_t get_signal_sending_mode(IOConfig & iosetting, TcpConfig & tcpsetting) |
|---|---|
| Description | Get signal output configuration. Determine whether IO or TCP configuration is returned based on the return value. If return value is 1, IO configuration is returned from iosetting object. |
| Parameters | iosetting: IOConfig instance containing IO output information. tcpsetting: TcpConfig instance containing TCP output information. |
| Return Value | -1: Failed to get configuration. 0: Configuration is OFF (not set). 1: IO configuration returned from iosetting. 2: TCP configuration returned from tcpsetting. |
Example:
// Get signal output configuration
IOConfig iosetting;
TcpConfig tcpsetting;
int8_t res = get_signal_sending_mode(iosetting, tcpsetting);Set IO Signal Output Configuration (Function set_io_signal_send_mode)
| API | int8_t set_io_signal_send_mode(SignalType do1, SignalType do2, uint32_t do1_keeptime = 0, uint32_t do2_keeptime = 0) |
|---|---|
| Description | Set IO signal output configuration. For example, setting do1 to NG_SIGNAL means pin 1 can only send NG signals. Note that pin 1 and pin 2 cannot be set to the same signal type simultaneously. |
| Parameters | do1: Pin 1. do2: Pin 2. do1_keeptime: Signal 1 duration (default 0). do2_keeptime: Signal 2 duration (default 0) |
| Return Value | -1: Failure. 0: Success |
Example:
// Set IO signal output mode
SignalType do2 = NG_SIGNAL;
SignalType do1 = ALARM_SIGNAL;
uint32_t ng_keeptime = 6;
int8_t res = set_io_signal_send_mode(do1, do2, ng_keeptime);Set TCP Signal Output Configuration (Function set_tcp_signal_send_mode)
| API | int8_t set_tcp_signal_send_mode(const char* ip, uint16_t port) |
|---|---|
| Description | Set TCP signal output configuration. The IP address and port are for the server side. |
| Parameters | ip: Server IP address. port: Server port number |
| Return Value | -1: Failure. 0: Success |
Example:
// Set TCP signal output mode
int8_t res = set_tcp_signal_send_mode(ip, port);Set OFF Mode (Function set_off_mode)
| API | int8_t set_off_mode() |
|---|---|
| Description | Set OFF mode to disable signal output. |
| Parameters | None |
| Return Value | -1: Failure. 0: Success |
Example:
// Set OFF mode to disable signal output
int8_t res = set_off_mode();Send NG Signal via IO (Function io_send_ng)
| API | int8_t io_send_ng() |
|---|---|
| Description | Send NG signal via IO. |
| Parameters | None |
| Return Value | -1: Failure. 0: Success |
Example:
// Send NG signal via IO
int8_t res = io_send_ng();Send Alarm Signal via IO (Function io_send_alarm_raising)
| API | int8_t io_send_alarm_raising() |
|---|---|
| Description | Send alarm signal via IO. |
| Parameters | None |
| Return Value | -1: Failure. 0: Success |
Example:
// Send alarm signal via IO
int8_t res = io_send_alarm_raising();Send Alarm Clear Signal via IO (Function io_send_alarm_clear)
| API | int8_t io_send_alarm_clear() |
|---|---|
| Description | Send alarm clear signal via IO. |
| Parameters | None |
| Return Value | -1: Failure. 0: Success |
Example:
// Send alarm clear signal via IO
int8_t res = io_send_alarm_clear();Send NG Signal via TCP (Function tcp_send_ng)
| API | int8_t tcp_send_ng() |
|---|---|
| Description | Send NG signal via TCP. |
| Parameters | None |
| Return Value | -1: Failure. 0: Success |
Example:
// Send NG signal via TCP
int8_t res = tcp_send_ng();Send Alarm Signal via TCP (Function tcp_send_alarm)
| API | int8_t tcp_send_alarm() |
|---|---|
| Description | Send alarm signal via TCP. |
| Parameters | None |
| Return Value | -1: Failure. 0: Success |
Example:
// Send alarm signal via TCP
int8_t res = tcp_send_alarm();Send Alarm Clear Signal via TCP (Function tcp_send_alarmclear)
| API | int8_t tcp_send_alarmclear() |
|---|---|
| Description | Send alarm clear signal via TCP. |
| Parameters | None |
| Return Value | -1: Failure. 0: Success |
Example:
// Send alarm clear signal via TCP
int8_t res = tcp_send_alarmclear();Save Analysis Result (Function save_result)
| API | int8_t save_result(const char *release_id, const char *release_version, const char *origin_file, const char *mask_file, const char *final_file, const char *additional = "") |
|---|---|
| Description | Package image analysis task result file paths and additional information as JSON and report to local SVE service. |
| Parameters | release_id: Release/task ID. release_version: Version number. origin_file: Original image file path. mask_file: Mask image file path. final_file: Final result image file path. additional: Additional JSON string (can be empty). |
| Return Value | 0: Success. -1: Failure. |
Example:
int8_t ret = save_result(
"task_123", // release_id
"v1.0", // release_version
"/tmp/origin.jpg", // origin_file
"/tmp/mask.png", // mask_file
"/tmp/final.jpg", // final_file
"{\"defect_size\":23.5,\"confidence\":0.98}" // additional (JSON string)
);Send Task Phase Notification (Function notify_sve)
| API | int8_t notify_sve(SPhase phase_enum) |
|---|---|
| Description | Send current task phase notification to local SVE service via HTTP (POST) request. |
| Parameters | phase_enum: Task phase enum value, including PHASE_IDLE, PHASE_START, PHASE_END. |
| Return Value | 0: Success. -1: Failure. |
Example:
int8_t ret = notify_sve(PHASE_START);Signal Type Definition (Enum SignalType)
| Member Variable | Type | Default | Description |
|---|---|---|---|
| OFF | uint8_t | 0 | Disable signal output |
| NG_SIGNAL | uint8_t | NG signal output mode | |
| ALARM_SIGNAL | uint8_t | Alarm signal output mode | |
| OK_SIGNAL | uint8_t | OK signal output mode |
Convert YUV to BGR Format
| API | bool yuv_to_bgr(cv::Mat &destMat, int srcSliceHeight, int srcYPlaneStride, int planeOffset, void *memdata) |
|---|---|
| Description | Convert YUV format data to BGR format. Output converted data through the destMat parameter. |
| Parameters | None |
| Return Value | false: Failure. true: Success |
Convert YUV to BGR Format (Function yuv_to_bgr_y)
| API | bool yuv_to_bgr_y(cv::Mat &destMat, int srcSliceHeight, int srcYPlaneStride, int planeOffset, void *memdata) |
|---|---|
| Description | Convert YUV format data to BGR format. Output converted data through the destMat parameter. Compared to yuv_to_bgr, this function only converts Y plane data (grayscale, single channel). |
| Parameters | None |
| Return Value | false: Failure. true: Success |
Get SDK Version (Function get_build_version)
| API | const char *get_build_version() |
|---|---|
| Description | Get SDK version information. |
| Parameters | None |
| Return Value | SDK version string |
Example:
// Get SDK version information
const char* res = get_build_version();Get Latest Log (Function log_last_msg)
| API | const char* log_last_msg(SVLogLevel log_level) |
|---|---|
| Description | Get latest log message. |
| Parameters | SVLogLevel log level |
| Return Value | Latest log record |
Example:
// Get latest log message
const char* res = log_last_msg(log_level);Get FPS (Function get_fps)
| API | double get_fps(int idx) |
|---|---|
| Description | Get real-time FPS from callback function, which represents the camera capture frame rate. |
| Parameters | idx: Camera index. Range: 0~2 for MIPI cameras. Default is 0. |
| Return Value | FPS value |
Example:
// Get real-time camera capture FPS
double fps_v = get_fps();Configure MIPI Camera (Function configure_camera)
| API | int8_t configure_camera(const char *file_path, bool set_property = false, bool validation = true) |
|---|---|
| Description | Set camera parameters. |
| Parameters | file_path: Configuration file. set_property: Apply immediately (true: yes, false: no). validation: Validate parameters (true: yes, false: no) |
| Return Value | 0: Success. -1: Failure |
Example:
// Configure camera parameters
int8_t res = Aidlux::SmartVision::configure_camera("./param.json", true, true);Get MIPI Camera Configuration (Function get_camera_setting)
| API | const char *get_camera_setting(int idx) |
|---|---|
| Description | Get camera configuration parameters. |
| Parameters | idx: Camera index. Default is 0. Currently, use default value without input. |
| Return Value | JSON format string |
Example:
// Get camera configuration parameters
const char* res = get_camera_setting();Enable MIPI Camera Full Size (Function fullsize_enable)
| API | int fullsize_enable(bool enable) |
|---|---|
| Description | Enable MIPI camera full size configuration. |
| Parameters | enable: true to enable, false to disable. |
| Return Value | 0: Success. -1: Failure |
Example:
// Enable MIPI camera fullsize configuration
int res = fullsize_enable(true);Set MIPI Camera Binning Mode (Function set_binning_mode)
| API | int set_binning_mode(int mode) |
|---|---|
| Description | Set binning mode. |
| Parameters | mode: 1: Select nearest binning mode, 2: Select 2x2 binning mode. MIPI camera default is 0, equivalent to mode 1. |
| Return Value | 0: Success. -1: Failure |
Example:
// Set camera binning mode
int res = set_binning_mode(1);Query MIPI Camera Fullsize Parameter (Function query_fullsize)
| API | string query_fullsize() |
|---|---|
| Description | Query fullsize value. |
| Parameters | None |
| Return Value | Fullsize parameter as string |
Example:
// Get camera fullsize configuration
string res = query_fullsize();Query MIPI Camera Binning Mode (Function query_binning_mode)
| API | string query_binning_mode() |
|---|---|
| Description | Query binning mode. |
| Parameters | None |
| Return Value | Binning mode as string |
Example:
// Get camera binning mode configuration
string res = query_binning_mode();Get All Camera IDs (Function get_all_cam_ids)
| API | std::vector<std::string> get_all_cam_ids() |
|---|---|
| Description | Get all available camera IDs. |
| Parameters | None |
| Return Value | Vector of strings, each string is a camera ID. |
Example:
std::vector<std::string> cam_ids = Aidlux::SmartVision::get_all_cam_ids();Get All Camera Indices (Function get_all_cam_index)
| API | std::vector<int> get_all_cam_index() |
|---|---|
| Description | Get all available camera indices. |
| Parameters | None |
| Return Value | Vector of integers, each integer is a camera index. |
Example:
std::vector<int> cam_indices = Aidlux::SmartVision::get_all_cam_index();Get Camera Index by ID (Function get_cam_index)
| API | int get_cam_index(std::string cam_id) |
|---|---|
| Description | Convert camera ID to camera index. |
| Parameters | cam_id: Camera ID string |
| Return Value | Camera index. |
Example:
int index = Aidlux::SmartVision::get_cam_index("camera_0");Get Camera ID by Index (Function get_cam_id)
| API | std::string get_cam_id(int cam_index) |
|---|---|
| Description | Convert camera index to camera ID. |
| Parameters | cam_index: Camera index |
| Return Value | Camera ID string. |
Example:
std::string id = Aidlux::SmartVision::get_cam_id(0);Get Photo File Address (Function get_photo_file_addr)
| API | int8_t get_photo_file_addr(std::vector<std::string> &pic_path, int idx = 0) |
|---|---|
| Description | Get photo file paths for HDR feature. |
| Parameters | pic_path: Output vector to store file paths. idx: Camera index (default 0). |
| Return Value | 0: Success. -1: Failure. -2: Failure. |
Example:
std::vector<std::string> paths;
int8_t res = Aidlux::SmartVision::get_photo_file_addr(paths, 0);Get Photo BGR (Function get_photo_bgr)
| API | cv::Mat get_photo_bgr(int idx = 0) |
|---|---|
| Description | Get photo data in BGR format for HDR feature. |
| Parameters | idx: Camera index (default 0). |
| Return Value | cv::Mat object containing BGR image data. |
Example:
cv::Mat img = Aidlux::SmartVision::get_photo_bgr(0);Get Photo JPG (Function get_photo_jpg)
| API | int8_t get_photo_jpg(const char *file_path, int idx = 0) |
|---|---|
| Description | Save photo as JPG file for HDR feature. |
| Parameters | file_path: Output file path. idx: Camera index (default 0). |
| Return Value | 0: Success. 1: Failure. |
Example:
int8_t res = Aidlux::SmartVision::get_photo_jpg("/tmp/photo.jpg", 0);Get Analog Gain (Function get_analog_gain)
| API | float get_analog_gain() |
|---|---|
| Description | Get current analog gain value. |
| Parameters | None |
| Return Value | Analog gain value. 0.0: Failure. |
Example:
float gain = Aidlux::SmartVision::get_analog_gain();Get Digital Gain (Function get_digital_gain)
| API | float get_digital_gain() |
|---|---|
| Description | Get current digital gain value. |
| Parameters | None |
| Return Value | Digital gain value. 0.0: Failure. |
Example:
float gain = Aidlux::SmartVision::get_digital_gain();Set Gain (Function set_gain)
| API | int set_gain(float analog_gain, float digital_gain) |
|---|---|
| Description | Set analog and digital gain values. |
| Parameters | analog_gain: Analog gain value. digital_gain: Digital gain value. |
| Return Value | 0: Success. -1: Failure. |
Example:
int res = Aidlux::SmartVision::set_gain(1.5f, 1.0f);Distortion Calibration (Function distortion_calibration)
| API | cv::Mat distortion_calibration(const std::vector<cv::Mat>& images, cv::Size boardSize, cv::Mat& cameraMatrix, float squareSize) |
|---|---|
| Description | Perform distortion calibration using multiple chessboard images. |
| Parameters | images: Vector of calibration images. boardSize: Chessboard pattern size. cameraMatrix: Output camera matrix. squareSize: Chessboard square size. |
| Return Value | Distortion coefficients matrix. |
Example:
std::vector<cv::Mat> calib_images;
cv::Mat cameraMatrix;
cv::Mat distCoeffs = Aidlux::SmartVision::distortion_calibration(calib_images, cv::Size(9, 6), cameraMatrix, 0.02f);Distortion Correction (Function distortion_correction)
| API | cv::Mat distortion_correction(const cv::Mat &img, const cv::Mat &distCoeffs, cv::Mat &cameraMatrix) |
|---|---|
| Description | Correct image distortion using calibration parameters. |
| Parameters | img: Input image. distCoeffs: Distortion coefficients. cameraMatrix: Camera matrix. |
| Return Value | Corrected image. |
Example:
cv::Mat corrected = Aidlux::SmartVision::distortion_correction(img, distCoeffs, cameraMatrix);White Balance Calibration (Function white_balance_calibration)
| API | cv::Vec3f white_balance_calibration(const cv::Mat& img) |
|---|---|
| Description | Calculate white balance calibration coefficients from image. |
| Parameters | img: Input image. |
| Return Value | RGB gain coefficients. |
Example:
cv::Vec3f gains = Aidlux::SmartVision::white_balance_calibration(img);White Balance Correction (Function white_balance_correction)
| API | cv::Mat white_balance_correction(const cv::Mat& img, const cv::Vec3f& calibCoeff) |
|---|---|
| Description | Adjust image white balance using calibration coefficients. |
| Parameters | img: Input image. calibCoeff: White balance calibration coefficients. |
| Return Value | White balance corrected image. |
Example:
cv::Mat corrected = Aidlux::SmartVision::white_balance_correction(img, gains);Get Mode Value (Function get_mode_value)
| API | int8_t get_mode_value() |
|---|---|
| Description | Get current signal output mode. |
| Parameters | None |
| Return Value | 0: OFF, 1: IO_MODE, 2: TCP_MODE, 3: MODBUS_MODE, 4: UART_MODE, -1: Failure. |
Example:
int8_t mode = Aidlux::SmartVision::get_mode_value();IO Send (Function io_send)
| API | int8_t io_send(std::string io_str, std::string io_control_file) |
|---|---|
| Description | Write string to specific IO control file. |
| Parameters | io_str: String to write. io_control_file: Path to IO control file. |
| Return Value | 0: Success. -1: Failure. |
Example:
int8_t res = Aidlux::SmartVision::io_send("1", "/sys/aidlux/io_out/output_1p");Task Phase Type Definition (Enum SPhase)
| Member Variable | Value | Description |
|---|---|---|
| OPEN_CAMERA_ING_ENUM1 | 1 | Opening camera in progress |
| OPEN_CAMERA_SUC_ENUM2 | 2 | Camera opened successfully |
| OPEN_CAMERA_FAIL_ENUM3 | 3 | Camera open failed |
| LOAD_MODEL_ING_ENUM4 | 4 | Loading model in progress |
| LOAD_MODEL_SUC_ENUM5 | 5 | Model loaded successfully |
| LOAD_MODEL_FAIL_ENUM6 | 6 | Model load failed |
| WAIT_IMAGE_ING_ENUM7 | 7 | Waiting for image |
Camera Trigger Mode (Enum CameraTriggerMode)
| Member Variable | Value | Description |
|---|---|---|
| INVALID_TRIGGER_MODE_ENUM0 | 0 | Invalid trigger mode |
| INTERNAL_TRIGGER_MODE_ENUM1 | 1 | Internal trigger mode |
| EXTERNAL_TRIGGER_MODE_ENUM2 | 2 | External hardware trigger mode |
| SOFTWARE_TRIGGER_MODE_ENUM3 | 3 | Software trigger mode |
Camera Parameter Mode (Enum CameraParamMode)
| Member Variable | Value | Description |
|---|---|---|
| WITH_PARAM_MODE | 0 | With parameters |
| WITHOUT_PARAM_MODE | 1 | Without parameters |
Signal Mode (Enum SignalMode)
| Member Variable | Value | Description |
|---|---|---|
| IO_MODE | 0 | IO signal mode |
| TCP_MODE | 1 | TCP signal mode |
| MODBUS_MODE | 2 | MODBUS signal mode |
| UART_MODE | 3 | UART signal mode |
Struct USBCamera
| Member Variable | Type | Description |
|---|---|---|
| usb_type | int | USB type (0: None, 2: USB 2.0, 3: USB 3.0) |
| width | int | Image width |
| height | int | Image height |
| fps | int | Frame rate |
| bus_id | std::string | Bus ID |
| vendor_id | std::string | Vendor ID |
| device_id | std::string | Device ID |
| product_id | std::string | Product ID |
| vendor_product_id | std::string | Vendor product ID |
| manufacturer | std::string | Manufacturer name |
| video_path | std::string | Video device path |
| resolution | std::string | Resolution string |
| creation_timestamp | std::string | Creation timestamp |
| buffers[4] | void* | Memory-mapped buffer pointers |
| size[4] | int | Buffer sizes |
| config_path | std::string | Configuration file path |
| video_list | std::vectorstd::string | List of video paths |
Struct HIKCamera
| Member Variable | Type | Description |
|---|---|---|
| width | int | Image width |
| height | int | Image height |
| fps | int | Frame rate |
| trigger_mode | int | Trigger mode (0: continuous, 1: software) |
| config_path | std::string | Configuration file path |
Struct CameraParam
| Member Variable | Type | Description |
|---|---|---|
| camera_type | CameraType | Camera type |
| exposure_time | uint64_t | Exposure time in microseconds |
| gain | float | Gain value |
| width | int | Image width |
| height | int | Image height |
| c | int | Number of channels |
| fps | int | Frame rate |
| trigger_mode | CameraTriggerMode | Trigger mode |
| resolution_array | std::vectorstd::string | Supported resolutions list |
| resolution_idx | uint8_t | Current resolution index |
| horizontal_flip | bool | Horizontal flip enabled |
| vertical_flip | bool | Vertical flip enabled |
Additional Public APIs
The following APIs are public in V1 source code and are listed here as a quick index.
| API | Description |
|---|---|
const char *get_build_meta(void) | Get build metadata (for example, build timestamp). |
const char *get_build_id(void) | Get the Git hash of the current build. |
bool is_process_running(pid_t processId) | Check whether the specified process ID is still running. |
bool check_camera_running_status() | Check running status of the default camera. |
bool check_camera_running_status(int idx) | Check running status of the camera by index. |
void init_log_configuration() | Initialize real-time log configuration. |
void start_log_callback() | Start log-configuration callback listener. |
void svsdk_notification_callback(const std::string &event, const std::string &module, const std::string &message) | Entry point for SDK notification callback handling. |
void set_log_level(SVLogLevel log_level, std::string logger_name) | Set log level for a specified logger name. |
std::string get_global_logger() | Get global logger name. |
int8_t save_result(const char *release_id, const char *release_version, const char *origin_file, const char *mask_file, const char *final_file, const char *additional = "") | Report source/mask/result files and optional metadata to the local service. |
int8_t save_result(const char *release_id, const char *release_version, const char *srcAddr = "./", const char *dstAddr = "/var/opt/aidlux/global/") | Package result directory by release info and output to the target path. |
int8_t notify_sve(SPhase phase_enum) | Report current task phase to SVE. |
int8_t get_usb_camera_type() | Get current USB camera type (0/2/3). |
int get_dst_width() / int get_dst_width(int idx) | Get target output width. |
int get_dst_height() / int get_dst_height(int idx) | Get target output height. |
cv::Mat read_image(const std::string& image_path) | Read an image file into an OpenCV Mat. |
std::array<std::array<double, 3>, 3> computeCCM3x3FromImage(const cv::Mat &bgr, const cv::Point2f corners[4], double innerScale = 0.5) | Compute a 3x3 CCM from color-card image data (each row sums to 1). |
std::array<int, 18> ccmToAndroidColorTransform(const cv::Mat &bgr, const cv::Point2f corners[4], int denom = 10000, double innerScale = 0.5) | Convert CCM to Android color-transform parameters. |
cv::Mat get_cvimage(const Image &img, int idx = 0) | Convert SDK Image object to cv::Mat. |
bool is_bgr(const cv::Mat &image) | Check whether an image is in BGR format. |
cv::Mat get_roi_pic(const cv::Mat &obj, const cv::Rect &location) | Crop image by ROI rectangle. |
int8_t io_send_ng_clear() | Send NG-clear signal via IO. |
int8_t io_send_ok() | Send OK signal via IO. |
int8_t io_send_ok_clear() | Send OK-clear signal via IO. |
int8_t io_send_alarm(std::string alarm_message) | Send alarm signal with custom message via IO. |
int8_t tcp_send(std::string message) | Send custom message via TCP. |
bool isIPFormat(const char* str) | Check whether a string is a valid IP format. |
bool isFileExists(const std::string& filePath) | Check whether a file exists. |
bool createNewSignalFile(const std::string& filePath) | Create a new signal configuration file. |
RS485_IO Class
Singleton class for RS485 IO control.
| API | Description |
|---|---|
static RS485_IO &getInstance() | Get singleton instance |
int8_t send_do1() | Send DO1 raise command (COM0) |
int8_t send_do1_clear() | Send DO1 clear command (COM0) |
int8_t send_do2() | Send DO2 raise command (COM1) |
int8_t send_do2_clear() | Send DO2 clear command (COM1) |
Example:
RS485_IO &io = RS485_IO::getInstance();
io.send_do1();IO Class
Static class for IO operations.
SendNGType Enum
| Member Variable | Value | Description |
|---|---|---|
| INVALID_NG_TYPE | 0 | Invalid type |
| IO_NG_TYPE | 1 | IO NG type |
| MODBUS_NG_TYPE | 2 | MODBUS NG type |
| TCP_NG_TYPE | 3 | TCP NG type |
SendNGConfig Struct
| Member Variable | Type | Description |
|---|---|---|
| vol_time | uint32_t | Voltage duration (for IO) |
| reg_addr | uint32_t | Register address (for MODBUS) |
| ip | std::string | IP address (for TCP) |
| port | uint16_t | Port number (for TCP) |