
--------------------------------------------------------------------------------
-- Captcha Recognizer ONNX module
--------------------------------------------------------------------------------

---@type onnxruntime*
local _onnxruntime = require("onnxruntime")

---@type image_cv*
local _image_cv = require("image.cv")

---@alias captcha_recognizer_image_input string|ImageObject*

---@class captcha_recognizer_options*
---@field type? 'slider' Verification code type
---@field model_path? string model path
---@field model_dir? string Model catalog
---@field providers? string[] ONNX Runtime provider list
---@field fallback_to_cpu? boolean provider Fallback CPU on failure
---@field coreml_compute_units? 'all'|'cpu_only'|'cpu_and_gpu'|'cpu_and_neural_engine' CoreML computing unit
---@field coreml_enable_on_subgraph? boolean Whether to enable CoreML in subgraphs
---@field coreml_require_static_input_shapes? boolean Whether to require static input shape
---@field coreml_create_mlprogram? boolean Whether to create MLProgram

---@class captcha_recognizer_predict_options*
---@field confidence? number confidence threshold
---@field conf? number confidence threshold
---@field iou? number NMS IoU threshold
---@field imgsz? integer|{ [1]: integer, width?: integer, w?: integer } Enter dimensions
---@field input_size? integer Enter dimensions
---@field size? integer Enter dimensions

---@class captcha_recognizer_identify_options*
---@field confidence? number confidence threshold
---@field conf? number confidence threshold
---@field iou? number NMS IoU threshold
---@field show? boolean Whether to return to preview image
---@field y_iou? number Y Axis IoU threshold
---@field mask_compare_size? integer Mask comparison size

---@class captcha_recognizer_box*
---@field [1] number left border
---@field [2] number upper boundary
---@field [3] number right border
---@field [4] number lower boundary
---@field [5]? number Confidence
---@field [6]? integer Category ID

---@class captcha_recognizer_detection*
---@field box number[] detection frame
---@field score number Confidence
---@field class_id integer Category ID
---@field mask onnxruntime_mask_bitmap* segmentation mask

---@class captcha_recognizer_prediction_batch*
---@field [1] captcha_recognizer_box*[] Detection box list
---@field [2] onnxruntime_mask_bitmap*[] Mask list
---@field boxes captcha_recognizer_box*[] Detection box list
---@field masks onnxruntime_mask_bitmap*[] Mask list

---@class captcha_recognizer_model_info*
---@field mode? 'slider' mode
---@field model_path? string model path
---@field used_coreml? boolean Whether to use CoreML EP
---@field input_name? string Enter name
---@field input_shape? integer[] Enter shape
---@field providers? string[] provider list
---@field outputs? { name: string, shape: integer[] }[] Output information

---@class captcha_recognizer_instance*
---@field closed boolean Is it closed
---@field session onnxruntime_session* ONNX Runtime session
---@field output_names string[] output name
---@field model_info captcha_recognizer_model_info* Model information
---@field decoder_schema table decode schema
local captcha_recognizer_instance = {}

---@class captcha_recognizer*
---@field VERSION string module version
---@field AUTHOR string Author
---@field Slider fun(opts?: captcha_recognizer_options*): captcha_recognizer_instance* Create a slider recognition instance
---@type captcha_recognizer*
local M = {}

--- Create a verification code recognition instance
---@param opts? captcha_recognizer_options* Options
---@return captcha_recognizer_instance* instance Example
function M.new(opts) end

--- Create a slider recognition instance
---@param opts? captcha_recognizer_options* Options
---@return captcha_recognizer_instance* instance Example
function M.Slider(opts) end

--- Get module version
---@return string version module version
function M.version() end

--- Get available ONNX Runtime providers
---@return string[] providers provider list
function M.providers() end

--- Run the slider detection model
---@param input captcha_recognizer_image_input Image path, image data, or image object
---@param conf? number|captcha_recognizer_predict_options* Confidence threshold or option
---@param iou? number NMS IoU threshold
---@param imgsz? integer|table Enter dimensions
---@return captcha_recognizer_prediction_batch*[] result Prediction batch
function captcha_recognizer_instance:predict(input, conf, iou, imgsz) end

--- Identify slider notch position
---@param input captcha_recognizer_image_input Image path, image data, or image object
---@param conf? number|captcha_recognizer_identify_options* Confidence threshold or option
---@param iou? number NMS IoU threshold
---@param show? boolean Whether to return to preview image
---@return captcha_recognizer_box* box Detection box, empty list on failure
---@return number confidence Confidence
---@return ImageObject*? preview Preview
function captcha_recognizer_instance:identify(input, conf, iou, show) end

--- Identify slider lateral offset
---@param input captcha_recognizer_image_input Image path, image data, or image object
---@param conf? number|captcha_recognizer_identify_options* Confidence threshold or option
---@param iou? number NMS IoU threshold
---@param show? boolean Whether to return to preview image
---@return number offset Lateral offset
---@return number confidence Confidence
---@return ImageObject*? preview Preview
function captcha_recognizer_instance:identify_offset(input, conf, iou, show) end

--- Get model information
---@return captcha_recognizer_model_info* info Model information
function captcha_recognizer_instance:get_model_info() end

--- Close instance
function captcha_recognizer_instance:close() end

return M
