
--------------------------------------------------------------------------------
-- DdddOCR ONNX module
--------------------------------------------------------------------------------

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

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

---@alias ddddocr_image_input string|ImageObject*

---@class ddddocr_options*
---@field ocr? boolean Whether to create an OCR instance
---@field det? boolean Whether to create a detection instance
---@field old? boolean Whether to use old model
---@field beta? boolean Whether to use beta model
---@field show_ad? boolean Whether to display prompts
---@field model_dir? string Model catalog
---@field import_onnx_path? string Custom model path
---@field charsets_path? string Character set JSON path
---@field device_id? integer Device ID
---@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 ddddocr_ocr_options*
---@field png_fix? boolean Whether to fix PNG transparent background
---@field color_filter_colors? string[] Preset color filters
---@field color_filter_custom_ranges? table Custom HSV color range
---@field probability? boolean Whether to return probability information
---@field charset_range? string|string[]|integer Character set range

---@class ddddocr_ocr_result*
---@field text string Recognize text
---@field confidence? number average confidence
---@field probabilities? table Probability details
---@field charset? string[] character set

---@class ddddocr_box*
---@field [1] number left border
---@field [2] number upper boundary
---@field [3] number right border
---@field [4] number lower boundary
---@field score? number Confidence

---@class ddddocr_slide_result*
---@field target_x number target abscissa
---@field target_y number Target vertical coordinate
---@field target_width number target width
---@field target_height number target height
---@field confidence number Confidence

---@class ddddocr_model_info*
---@field mode? 'ocr'|'det'|'slide' mode
---@field model_path? string model path
---@field used_coreml? boolean Whether to use CoreML EP
---@field device_id? integer Device ID
---@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 ddddocr_charset_config*
---@field charset string[] character set
---@field map? table character map

---@class ddddocr_instance*
---@field mode? 'ocr'|'det'|'slide' Instance mode
---@field closed boolean Is it closed
---@field session? onnxruntime_session* ONNX Runtime session
---@field model_info? ddddocr_model_info* Model information
---@field output_names? string[] output name
---@field charset_config? ddddocr_charset_config* Character set configuration, only exists in OCR mode
---@field persistent_charset_range? table Persistent character set range
---@field device_id? integer Device ID
local ddddocr_instance = {}

---@class ddddocr*
---@field VERSION string module version
---@field AUTHOR string Author
---@type ddddocr*
local M = {}

--- Create DdddOCR instance
---@param opts? ddddocr_options* Options
---@return ddddocr_instance* instance Example
function M.new(opts) end

--- Get available color filter names
---@return string[] colors Color name list
function M.available_colors() end

--- Slider template matching
---@param target ddddocr_image_input target image
---@param background ddddocr_image_input background image
---@param simpleTarget? boolean Whether to use simple slider mode
---@return ddddocr_slide_result* result Match results
function M.slide_match(target, background, simpleTarget) end

--- Slider gap comparison
---@param target ddddocr_image_input target image
---@param background ddddocr_image_input background image
---@return ddddocr_slide_result* result Comparison results
function M.slide_comparison(target, background) end

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

--- OCR recognition
---@param input ddddocr_image_input Image path, image data, or image object
---@param opts? ddddocr_ocr_options* Options
---@return string|ddddocr_ocr_result* result Text is returned by default, details are returned when probability is true
function ddddocr_instance:ocr(input, opts) end

--- OCR recognition
---@param input ddddocr_image_input Image path, image data, or image object
---@param opts? ddddocr_ocr_options* Options
---@return string|ddddocr_ocr_result* result Text is returned by default, details are returned when probability is true
function ddddocr_instance:classification(input, opts) end

--- Target detection
---@param input ddddocr_image_input Image path, image data, or image object
---@return ddddocr_box*[] boxes Detection box list
function ddddocr_instance:det(input) end

--- Target detection
---@param input ddddocr_image_input Image path, image data, or image object
---@return ddddocr_box*[] boxes Detection box list
function ddddocr_instance:detect(input) end

--- Target detection
---@param input ddddocr_image_input Image path, image data, or image object
---@return ddddocr_box*[] boxes Detection box list
function ddddocr_instance:detection(input) end

--- Slider template matching
---@param target ddddocr_image_input target image
---@param background ddddocr_image_input background image
---@param simpleTarget? boolean Whether to use simple slider mode
---@return ddddocr_slide_result* result Match results
function ddddocr_instance:slide_match(target, background, simpleTarget) end

--- Slider gap comparison
---@param target ddddocr_image_input target image
---@param background ddddocr_image_input background image
---@return ddddocr_slide_result* result Comparison results
function ddddocr_instance:slide_comparison(target, background) end

--- Set persistent character set range
---@param value string|string[]|integer Character set range
---@return boolean ok Is it successful?
function ddddocr_instance:set_ranges(value) end

--- Get the current model character set
---@return string[] charset character set
function ddddocr_instance:get_charset() end

--- Get model information
---@return ddddocr_model_info* info Model information
function ddddocr_instance:get_model_info() end

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

return M
