---@meta image.cv

--------------------------------------------------------------------------------
-- XXTouch image.cv OpenCV module
--------------------------------------------------------------------------------

---@alias image_cv_source image_cv_mat*|ImageObject*
---@alias image_cv_result image_cv_mat*|ImageObject*
---@alias image_cv_scalar number|number[]|{ b?: number, g?: number, r?: number, a?: number }
---@alias image_cv_point { x: number, y: number }|number[]
---@alias image_cv_size { width: number, height: number }|number[]
---@alias image_cv_rect { x: integer, y: integer, width: integer, height: integer }|{ left: integer, top: integer, right: integer, bottom: integer }|integer[]
---@alias image_cv_contours image_cv_contour[]
---@alias image_cv_color_code integer|string
---@alias image_cv_interpolation integer|string
---@alias image_cv_border_type integer|string
---@alias image_cv_threshold_type integer|string
---@alias image_cv_norm_type integer|string
---@alias image_cv_distance_type integer|string
---@alias image_cv_template_method integer|string
---@alias image_cv_hist_compare_method integer|string
---@alias image_cv_line_type integer|string
---@alias image_cv_hough_circle_method integer|string

---@class image_cv_binary_options*
---@field inplace? boolean Process mat input in place
---@field return_image? boolean Return ImageObject* instead of cv mat

---@class image_cv_resize_options*: image_cv_binary_options*
---@field width? integer Output width
---@field height? integer Output high
---@field fx? number Horizontal scaling
---@field fy? number vertical scaling
---@field interpolation? image_cv_interpolation interpolation method

---@class image_cv_match_options*
---@field confidence_threshold? number Match threshold, range 1..100
---@field find_all? boolean Whether to return all matches
---@field downscale? number Downsampling ratio, range 0.1..1
---@field should_visualize? boolean Whether to return additional visualization pictures
---@field mask? ImageObject* Mask image of the same size as the template

---@class image_cv_match*
---@field x integer Upper left corner X
---@field y integer Upper left corner Y
---@field confidence number Confidence

---@class image_cv_stitch_long_options*
---@field auto_crop? boolean Automatic estimation of top/bottom fixed areas
---@field top_crop? integer Top crop pixels, -1 means automatic
---@field bottom_crop? integer Bottom crop pixels, -1 means automatic
---@field keep_first_top? boolean Whether to retain the top area of the first image
---@field keep_last_bottom? boolean Whether to retain the bottom area of the final image
---@field overlay_mode? '"none"'|'"remove_all"'|'"keep_first"' Floating occlusion processing method
---@field overlay_fill_mode? '"temporal_only"'|'"temporal_then_inpaint"' Occlusion backfill method
---@field overlay_regions? image_cv_rect[] Manually specify the floating occlusion area
---@field seam_blend_rows? integer Mixed rows of seams
---@field min_overlap_ratio? number Minimum overlap ratio of adjacent frames
---@field max_overlap_ratio? number Maximum overlap ratio of adjacent frames
---@field template_height? integer Template matching height, 0 means automatic estimation
---@field score_threshold? number match score threshold

---@class image_cv_find_polygon_options*
---@field min_sides? integer Minimum number of sides
---@field max_sides? integer Maximum number of sides, negative number means no limit
---@field min_side_length number Shortest side length
---@field max_side_length number longest side length
---@field min_area number minimum area
---@field max_area number maximum area
---@field blur_size? integer blur kernel size
---@field canny_threshold1? number Canny Threshold 1
---@field canny_threshold2? number Canny Threshold 2
---@field approx_epsilon? number Approximate polygon proportions
---@field closed? boolean Whether to process as closed contour
---@field should_visualize? boolean Whether to return additional visualization pictures

---@class image_cv_compare_options*
---@field should_visualize? boolean Whether to return additional visualization pictures
---@field approx_epsilon? number difference contour approximation scale

---@class image_cv_to_shapes_options*
---@field should_visualize? boolean Whether to return additional visualization pictures
---@field closed? boolean Whether to process as closed contour
---@field blur_size? integer blur kernel size
---@field canny_threshold1? number Canny Threshold 1
---@field canny_threshold2? number Canny Threshold 2
---@field approx_epsilon? number Approximate proportions of outline

---@class image_cv_find_shapes_options*: image_cv_to_shapes_options*
---@field min_area? number minimum area
---@field max_area? number maximum area
---@field diff_threshold? number shape difference threshold
---@field shape_match_mode? integer OpenCV matchShapes mode

---@class image_cv_detect_templates_options*
---@field [integer] ImageObject* Template image array item
---@field should_visualize? boolean Whether to return additional visualization pictures
---@field detector? 0|1|2 Feature detector, 0=ORB, 1=SIFT, 2=SURF
---@field score_thresh? number Feature matching score threshold, range 0..100

---@class image_cv_contour_attributes*
---@field diff_score? number shape difference score
---@field index? integer template index
---@field angle? number rotation angle
---@field confidence? number Confidence

---@class image_cv_contour*: image_cv_contour_attributes
---@field [integer] image_cv_point

---@class image_cv_rotated_rect*
---@field center image_cv_point center point
---@field size image_cv_size Size
---@field angle number rotation angle

---@class image_cv_contour_hierarchy*
---@field [1] integer next
---@field [2] integer prev
---@field [3] integer first_child
---@field [4] integer parent
---@field next integer next contour index
---@field prev integer Previous contour index
---@field first_child integer First subcontour index
---@field parent integer parent contour index

---@class image_cv_min_max_loc*
---@field min_val number minimum value
---@field max_val number maximum value
---@field min_loc image_cv_point Minimum coordinates
---@field max_loc image_cv_point Maximum coordinates

---@class image_cv_component*
---@field label integer label
---@field left integer left border
---@field top integer upper boundary
---@field width integer Width
---@field height integer height
---@field area integer area
---@field centroid image_cv_point center of mass

---@class image_cv_connected_components_result*
---@field count integer Number of connected domains
---@field labels image_cv_mat* label matrix
---@field stats image_cv_mat* statistical matrix
---@field centroids image_cv_mat* centroid matrix
---@field components image_cv_component[] connected domain list

---@class image_cv_text_size*
---@field width integer text width
---@field height integer text height
---@field baseline integer baseline

---@class image_cv_line_result*
---@field [1] number vx
---@field [2] number vy
---@field [3] number x
---@field [4] number y
---@field vx number Direction X
---@field vy number Direction Y
---@field x number Point X on the line
---@field y number Point Y on the line

---@class image_cv_circle_result*
---@field center image_cv_point center of circle
---@field radius number radius

---@class image_cv_triangle_result*
---@field area number area
---@field triangle image_cv_point[] triangle vertex

---@class image_cv_intersection_result*
---@field area number area
---@field contour image_cv_point[] Intersection area outline

---@class image_cv_moments*
---@field m00 number
---@field m10 number
---@field m01 number
---@field m20 number
---@field m11 number
---@field m02 number
---@field m30 number
---@field m21 number
---@field m12 number
---@field m03 number
---@field mu20 number
---@field mu11 number
---@field mu02 number
---@field mu30 number
---@field mu21 number
---@field mu12 number
---@field mu03 number
---@field nu20 number
---@field nu11 number
---@field nu02 number
---@field nu30 number
---@field nu21 number
---@field nu12 number
---@field nu03 number

---@class image_cv_hist_options*
---@field channel? integer channel
---@field hist_size? integer Histogram size
---@field ranges? number[] Value range {min, max}
---@field uniform? boolean Is it evenly distributed?
---@field accumulate? boolean Whether to accumulate
---@field mask? image_cv_source mask

---@class image_cv_paddle_ocr_config*
---@field det_path? string Detect model path
---@field cls_path? string Direction Classification Model Path
---@field rec_path? string Identify model paths
---@field config_path? string OCR Configuration path
---@field dict_path? string dictionary path
---@field power_mode? string Paddle Lite power mode
---@field threads? integer Number of threads
---@field downscale? number OCR Downsampling ratio
---@field should_visualize? boolean Whether to return additional visualization pictures

---@class image_cv_paddle_ocr_item*
---@field text string Recognize text
---@field confidence number Confidence
---@field x integer Upper left corner X
---@field y integer Upper left corner Y
---@field w integer wide
---@field h integer high

---@class image_cv_paddle_ocr_context*
local paddle_ocr_context = {}

--- Destroy the OCR context.
function paddle_ocr_context:destroy() end

--- Perform OCR on images.
---@param image ImageObject* pictures
---@param opts? image_cv_paddle_ocr_config Options
---@return image_cv_paddle_ocr_item[]? results Recognition results
---@return ImageObject*? visual Visualization pictures
function paddle_ocr_context:predict(image, opts) end

---@class image_cv_paddle_yolov3_options*
---@field model_path? string model path
---@field param_path? string Parameter path
---@field label_path? string label path
---@field power_mode? string Paddle Lite power mode
---@field threads? integer Number of threads
---@field score_threshold? number score threshold
---@field should_visualize? boolean Whether to return additional visualization pictures
---@field mean? number[] preprocessing mean
---@field std? number[] preprocessing std

---@class image_cv_paddle_yolov3_result*
---@field class_name string Class name
---@field x integer Upper left corner X
---@field y integer Upper left corner Y
---@field w integer wide
---@field h integer high
---@field confidence number Confidence

---@class image_cv_paddle_yolov3_context*
local paddle_yolov3_context = {}

--- Destroy the YOLOv3 context.
function paddle_yolov3_context:destroy() end

--- Perform object detection on images.
---@param image ImageObject* pictures
---@param opts? image_cv_paddle_yolov3_options Options
---@return image_cv_paddle_yolov3_result[] results Test results
---@return ImageObject*? visual Visualization pictures
function paddle_yolov3_context:predict(image, opts) end

---@class image_cv_mat*
local mat = {}

--- Get the cv mat type name.
---@return string type Type name
function mat:type() end

--- Get mat depth.
---@return integer depth Depth
function mat:depth() end

--- Get the number of channels.
---@return integer channels Number of channels
function mat:channels() end

--- Get dimensions.
---@return integer width wide
---@return integer height high
function mat:size() end

--- Get the matrix shape.
---@return table shape shape information
function mat:shape() end

--- Clone mat.
---@return image_cv_mat* mat mat copy
function mat:clone() end

--- Convert to image object.
---@return ImageObject* image Picture object
function mat:to_image() end

--- Convert mat data type.
---@param dtype integer|string target type
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Conversion result
function mat:astype(dtype, opts) end

--- Color space conversion.
---@param code image_cv_color_code transcoding
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Conversion result
function mat:cvt_color(code, opts) end

--- Separate channels.
---@return image_cv_mat[] channels channel mat array
function mat:split() end

--- Extract the specified channel.
---@param channel integer Channel index, starting from 0
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Single channel results
function mat:extract_channel(channel, opts) end

--- Insert single channel data into the target channel.
---@param dst image_cv_source target
---@param channel integer Channel index, starting from 0
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:insert_channel(dst, channel, opts) end

--- Rotate.
---@param rotate_code integer|string rotate code
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:rotate(rotate_code, opts) end

--- Flip.
---@param flip_code integer|string flip code
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:flip(flip_code, opts) end

--- Transpose.
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:transpose(opts) end

--- Perspective transformation.
---@param matrix image_cv_source 3x3 transformation matrix
---@param width integer Output width
---@param height integer Output high
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:warp_perspective(matrix, width, height, opts) end

--- Affine transformation.
---@param matrix image_cv_source 2x3 transformation matrix
---@param width integer Output width
---@param height integer Output high
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:warp_affine(matrix, width, height, opts) end

--- Adjust size.
---@param width? integer Output width
---@param height? integer Output high
---@param interpolation_or_opts? image_cv_interpolation|image_cv_resize_options Interpolation methods or options
---@param opts? image_cv_resize_options Options
---@return image_cv_result result Processing results
function mat:resize(width, height, interpolation_or_opts, opts) end

--- Repeat matrix.
---@param self image_cv_mat* current mat
---@param ny integer Number of vertical repetitions
---@param nx integer Lateral repetitions
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
mat["repeat"] = function(self, ny, nx, opts) end

--- Downsampling.
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:pyr_down(opts) end

--- upsampling.
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:pyr_up(opts) end

--- Capture a subpixel rectangle.
---@param width integer wide
---@param height integer high
---@param center image_cv_point center point
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:get_rect_sub_pix(width, height, center, opts) end

--- Add a border.
---@param top integer top border
---@param bottom integer bottom border
---@param left integer left border
---@param right integer right border
---@param border_type? image_cv_border_type Border type
---@param value? image_cv_scalar fill value
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:copy_make_border(top, bottom, left, right, border_type, value, opts) end

--- Absolutely bad.
---@param rhs image_cv_source rvalue
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:absdiff(rhs, opts) end

--- addition.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:add(rhs, opts) end

--- Subtraction.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:subtract(rhs, opts) end

--- multiplication.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param scale? number Zoom
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:multiply(rhs, scale, opts) end

--- Division.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param scale? number Zoom
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:divide(rhs, scale, opts) end

--- Compare.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param cmp_op integer|string comparison operation
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:compare(rhs, cmp_op, opts) end

--- Reduce.
---@param dim integer Dimensions
---@param op integer|string Operation
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:reduce(dim, op, opts) end

--- Sum.
---@return image_cv_scalar scalar summation result
function mat:sum() end

--- Calculate the norm.
---@param rhs_or_norm_type? image_cv_source|image_cv_norm_type rvalue or norm type
---@param norm_type_or_mask? image_cv_norm_type|image_cv_source norm type or mask
---@param mask? image_cv_source mask
---@return number norm norm
function mat:norm(rhs_or_norm_type, norm_type_or_mask, mask) end

--- Copied to a new mat, a mask can be assigned.
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:copy_to(mask_or_opts, opts) end

--- Set the pixel value.
---@param value image_cv_scalar value
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:set_to(value, mask_or_opts, opts) end

--- Fixed threshold binarization.
---@param thresh number threshold
---@param maxval number maximum value
---@param type? image_cv_threshold_type Threshold type
---@param opts? image_cv_binary_options|{ inplace?: boolean, return_image?: boolean, return_threshold?: boolean } Options
---@return image_cv_result result Processing results
---@return number? used_threshold actual threshold
function mat:threshold(thresh, maxval, type, opts) end

--- Adaptive threshold binarization.
---@param maxval number maximum value
---@param method integer|string adaptive method
---@param type image_cv_threshold_type Threshold type
---@param block_size integer block size
---@param c number constant
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:adaptive_threshold(maxval, method, type, block_size, c, opts) end

--- Mean blur.
---@param ksize integer core size
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:blur(ksize, opts) end

--- Gaussian blur.
---@param kx integer Lateral core size
---@param ky integer Longitudinal core size
---@param sigma_x? number sigma X
---@param sigma_y? number sigma Y
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:gaussian_blur(kx, ky, sigma_x, sigma_y, opts) end

--- The median is blurry.
---@param ksize integer core size
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:median_blur(ksize, opts) end

--- Bilateral filtering.
---@param d integer neighborhood diameter
---@param sigma_color number color sigma
---@param sigma_space number space sigma
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:bilateral_filter(d, sigma_color, sigma_space, opts) end

--- Histogram equalization.
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:equalize_hist(opts) end

--- CLAHE adaptive histogram equalization.
---@param clip_limit_or_opts? number|image_cv_binary_options clip limit or option
---@param tile_width? integer tile wide
---@param tile_height? integer tile high
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:clahe(clip_limit_or_opts, tile_width, tile_height, opts) end

--- Normalize.
---@param opts? image_cv_binary_options|{ alpha?: number, beta?: number, norm_type?: image_cv_norm_type, inplace?: boolean, return_image?: boolean } Options
---@return image_cv_result result Processing results
function mat:normalize(opts) end

--- average value.
---@param mask? image_cv_source mask
---@return image_cv_scalar scalar average value
function mat:mean(mask) end

--- mean and standard deviation.
---@param mask? image_cv_source mask
---@return image_cv_scalar mean average value
---@return image_cv_scalar stddev standard deviation
function mat:mean_std_dev(mask) end

--- Count the number of non-zero elements.
---@return integer count non-zero quantity
function mat:count_non_zero() end

--- Range detection.
---@param lower image_cv_scalar Nether
---@param upper image_cv_scalar upper bound
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:in_range(lower, upper, opts) end

--- Weighted blend.
---@param alpha number self weight
---@param src2 image_cv_source second picture
---@param beta number The weight of the second picture
---@param gamma? number offset
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:add_weighted(alpha, src2, beta, gamma, opts) end

--- Bitwise AND.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:bitwise_and(rhs, mask_or_opts, opts) end

--- Bitwise OR.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:bitwise_or(rhs, mask_or_opts, opts) end

--- Bitwise XOR.
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:bitwise_xor(rhs, mask_or_opts, opts) end

--- Bitwise negation.
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:bitwise_not(mask_or_opts, opts) end

--- Canny edge detection.
---@param threshold1 number Threshold 1
---@param threshold2 number Threshold 2
---@param aperture_size? integer aperture size
---@param l2gradient? boolean Whether to use L2 gradient
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:canny(threshold1, threshold2, aperture_size, l2gradient, opts) end

--- Sobel operator.
---@param ddepth integer|string Output depth
---@param dx integer X Order
---@param dy integer Y Order
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:sobel(ddepth, dx, dy, opts) end

--- Scharr operator.
---@param ddepth integer|string Output depth
---@param dx integer X Order
---@param dy integer Y Order
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:scharr(ddepth, dx, dy, opts) end

--- Laplacian operator.
---@param ddepth integer|string Output depth
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:laplacian(ddepth, opts) end

--- Scale and take absolute value.
---@param alpha? number Zoom
---@param beta? number offset
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:convert_scale_abs(alpha, beta, opts) end

--- corrosion.
---@param kernel image_cv_source Structural elements
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:erode(kernel, opts) end

--- swell.
---@param kernel image_cv_source Structural elements
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:dilate(kernel, opts) end

--- Morphological operations.
---@param op integer|string Operation
---@param kernel image_cv_source Structural elements
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:morphology_ex(op, kernel, opts) end

--- Remap.
---@param map1 image_cv_source map1
---@param map2 image_cv_source map2
---@param interpolation? image_cv_interpolation interpolation method
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:remap(map1, map2, interpolation, opts) end

--- Fill with water.
---@param seed_point image_cv_point seed point
---@param new_val image_cv_scalar fill value
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:flood_fill(seed_point, new_val, opts) end

--- Phase related.
---@param rhs image_cv_source rvalue
---@param window? image_cv_source window
---@return image_cv_point shift offset
---@return number response response
function mat:phase_correlate(rhs, window) end

--- Calculate the amplitude.
---@param y image_cv_source y weight
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Amplitude
function mat:magnitude(y, opts) end

--- Calculate the phase.
---@param y image_cv_source y weight
---@param angle_in_degrees? boolean Whether to return the angle
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Phase
function mat:phase(y, angle_in_degrees, opts) end

--- Convert Cartesian coordinates to polar coordinates.
---@param y image_cv_source y weight
---@param angle_in_degrees? boolean Whether to return the angle
---@param opts? image_cv_binary_options Options
---@return image_cv_result magnitude Amplitude
---@return image_cv_result angle angle
function mat:cart_to_polar(y, angle_in_degrees, opts) end

--- Convert polar coordinates to Cartesian coordinates.
---@param angle image_cv_source angle
---@param angle_in_degrees? boolean Angle unit
---@param opts? image_cv_binary_options Options
---@return image_cv_result x x weight
---@return image_cv_result y y weight
function mat:polar_to_cart(angle, angle_in_degrees, opts) end

--- Find the outline.
---@param mode? integer|string Search mode
---@param method? integer|string Approximate method
---@param opts? { return_hierarchy?: boolean } Options
---@return image_cv_contour[] contours outline array
---@return image_cv_contour_hierarchy[]? hierarchy hierarchical relationship
function mat:find_contours(mode, method, opts) end

--- Connected domain analysis.
---@param connectivity? 4|8 connectivity
---@param ltype? integer|string Tag type
---@return image_cv_connected_components_result result Connected domain results
function mat:connected_components_with_stats(connectivity, ltype) end

--- Find non-zero points.
---@return image_cv_point[] points non-zero point
function mat:find_non_zero() end

--- Calculate moments.
---@param binary_image? boolean Whether to process it as a binary image
---@return image_cv_moments moments moment
function mat:moments(binary_image) end

--- Calculate the Hu moments.
---@param binary_image? boolean Whether to process it as a binary image
---@return number[] hu_moments Hu moment array
function mat:hu_moments(binary_image) end

--- Template matching.
---@param templ image_cv_source Template
---@param method? image_cv_template_method matching method
---@param mask? image_cv_source mask
---@return image_cv_mat* result matching result matrix
function mat:match_template(templ, method, mask) end

--- Get the minimum, maximum value and position.
---@param mask? image_cv_source mask
---@return image_cv_min_max_loc result result
function mat:min_max_loc(mask) end

--- Calculate the histogram.
---@param opts? image_cv_hist_options Options
---@return image_cv_mat* hist Histogram
function mat:calc_hist(opts) end

--- Compare histograms.
---@param hist2 image_cv_source Histogram
---@param method? image_cv_hist_compare_method comparison method
---@return number score score
function mat:compare_hist(hist2, method) end

--- Probabilistic Hough line detection.
---@param rho number rho
---@param theta number theta
---@param threshold integer threshold
---@param min_line_length? number Minimum segment length
---@param max_line_gap? number Maximum segment gap
---@return table[] lines Segment list
function mat:hough_lines_p(rho, theta, threshold, min_line_length, max_line_gap) end

--- Hough circle detection.
---@param method image_cv_hough_circle_method Detection method
---@param dp number Accumulator resolution scale
---@param min_dist number Minimum distance between circle centers
---@param param1? number Parameter 1
---@param param2? number Parameter 2
---@param min_radius? integer minimum radius
---@param max_radius? integer maximum radius
---@return table[] circles circle list
function mat:hough_circles(method, dp, min_dist, param1, param2, min_radius, max_radius) end

--- distance transformation.
---@param distance_type? image_cv_distance_type distance type
---@param mask_size? integer mask size
---@param opts? image_cv_binary_options|{ dst_type?: integer|string, return_image?: boolean } Options
---@return image_cv_result result distance map
function mat:distance_transform(distance_type, mask_size, opts) end

--- Corner detection.
---@param max_corners integer Maximum number of corners
---@param quality_level number quality threshold
---@param min_distance number minimum distance
---@param mask_or_block_size? image_cv_source|integer Mask or block size
---@param use_harris? boolean Whether to use Harris
---@param k? number Harris parameters
---@return image_cv_point[] corners corner point
function mat:good_features_to_track(max_corners, quality_level, min_distance, mask_or_block_size, use_harris, k) end

--- Draw a rectangle.
---@param x1 integer Upper left corner X
---@param y1 integer Upper left corner Y
---@param x2 integer Lower right corner X
---@param y2 integer Lower right corner Y
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:rectangle(x1, y1, x2, y2, color, thickness, opts) end

--- Draw a circle.
---@param x integer Circle center X
---@param y integer Circle center Y
---@param radius integer radius
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:circle(x, y, radius, color, thickness, opts) end

--- Draw line segments.
---@param x1 integer Starting point
---@param y1 integer Starting point Y
---@param x2 integer end point
---@param y2 integer End point Y
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:line(x1, y1, x2, y2, color, thickness, opts) end

--- Draw a polyline.
---@param points image_cv_contours Point set
---@param is_closed boolean Is it closed?
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param line_type? image_cv_line_type linear
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:polylines(points, is_closed, color, thickness, line_type, opts) end

--- Filled polygon.
---@param points image_cv_contours Point set
---@param color image_cv_scalar Color
---@param line_type? image_cv_line_type linear
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:fill_poly(points, color, line_type, opts) end

--- Draw the outline.
---@param contours image_cv_contours outline array
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:draw_contours(contours, color, thickness, opts) end

--- Draw text.
---@param text string text
---@param org image_cv_point origin
---@param font_face integer|string font
---@param font_scale number Font scaling
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param line_type? image_cv_line_type linear
---@param bottom_left_origin? boolean Whether to take the lower left as the origin
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function mat:put_text(text, org, font_face, font_scale, color, thickness, line_type, bottom_left_origin, opts) end

---@class ImageObject*
local ImageObject = {}

--- Convert the image to cv mat.
---@return image_cv_mat* mat cv mat
function ImageObject:cv_to_mat() end

--- Find the template image in the image.
---@param template ImageObject* Template picture
---@param opts? image_cv_match_options Options
---@return integer|image_cv_match[] x_or_matches X coordinates or matching array
---@return integer|ImageObject*|nil y_or_visual Y Coordinates or visual images
---@return number? confidence Confidence
---@return ImageObject*? visual Visualization pictures
function ImageObject:cv_find_image(template, opts) end

--- Binarize and replace the current image.
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image Current picture
function ImageObject:cv_binaryzation(threshold) end

--- Binarize and return a copy.
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image new pictures
function ImageObject:cv_binaryzation_copy(threshold) end

--- Binarize and replace the current image.
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image Current picture
function ImageObject:cv_binarization(threshold) end

--- Binarize and return a copy.
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image new pictures
function ImageObject:cv_binarization_copy(threshold) end

--- Binarize and replace the current image.
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image Current picture
function ImageObject:cv_binarize(threshold) end

--- Binarize and return a copy.
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image new pictures
function ImageObject:cv_binarize_copy(threshold) end

--- Resize the image and replace the current image.
---@param width integer Output width
---@param height integer Output high
---@return ImageObject* image Current picture
function ImageObject:cv_resize(width, height) end

--- Resize the image and return a copy.
---@param width integer Output width
---@param height integer Output high
---@return ImageObject* image new pictures
function ImageObject:cv_resize_copy(width, height) end

--- Find polygons.
---@param opts image_cv_find_polygon_options Options
---@return image_cv_contour[] contours outline array
---@return ImageObject*? visual Visualization pictures
function ImageObject:cv_find_polygon(opts) end

--- Compare the differences between two pictures of the same size.
---@param image ImageObject* Compare pictures
---@param opts? image_cv_compare_options Options
---@return image_cv_contour[] contours difference contour
---@return ImageObject*? visual Visualization pictures
function ImageObject:cv_compare_image(image, opts) end

--- Find contours that are similar to the template shape.
---@param shape ImageObject*|image_cv_contours Template image or template outline
---@param opts? image_cv_find_shapes_options Options
---@return image_cv_contour[][] groups Matching contours corresponding to each template
---@return ImageObject*? visual Visualization pictures
function ImageObject:cv_find_shapes(shape, opts) end

--- Extract image outlines.
---@param opts? image_cv_to_shapes_options Options
---@return image_cv_contour[] contours outline array
---@return ImageObject*? visual Visualization pictures
function ImageObject:cv_to_shapes(opts) end

--- Detect multiple templates based on features.
---@param opts image_cv_detect_templates_options Template array and options
---@return image_cv_contour[] contours Detected template outline
---@return ImageObject*? visual Visualization pictures
function ImageObject:cv_detect_templates(opts) end

--- Perform OCR on images.
---@param opts? image_cv_paddle_ocr_config Options
---@return image_cv_paddle_ocr_item[]? results Recognition results
---@return ImageObject*? visual Visualization pictures
function ImageObject:paddle_ocr(opts) end

---@class image_cv_mat_namespace*
---@field is fun(value: any): boolean

---@class image_cv*
---@field _AUTHOR string Author
---@field _VERSION string module version
---@field _CV_VERSION string OpenCV version
---@field mat image_cv_mat_namespace* mat tool table
---@type image_cv*
local M = {}

M._AUTHOR = "XXTouch"
M._VERSION = "1.4.3"
M._CV_VERSION = ""
M.mat = {}

--- Determine whether a value is cv mat.
---@param value any Value to be judged
---@return boolean ok Whether it is cv mat
function M.mat.is(value) end

--- Determine whether a value is cv mat.
---@param value any Value to be judged
---@return boolean ok Whether it is cv mat
function M.is(value) end

--- Get the cv object type.
---@param value any Value to be judged
---@return string? type Type name
function M.type(value) end

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

--- Create cv mat from image.
---@param image ImageObject* pictures
---@return image_cv_mat* mat cv mat
function M.from_image(image) end

--- Convert cv mat to image.
---@param source image_cv_source cv mat or picture
---@return ImageObject* image pictures
function M.to_image(source) end

--- Color space conversion.
---@param source image_cv_source input
---@param code image_cv_color_code transcoding
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Conversion result
function M.cvt_color(source, code, opts) end

--- Separate channels.
---@param source image_cv_source input
---@return image_cv_mat[] channels channel mat array
function M.split(source) end

--- Merge channels.
---@param channels image_cv_source[] Channel list
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Merge results
function M.merge(channels, opts) end

--- Horizontal splicing.
---@param sources image_cv_source[] input list
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Splicing result
function M.hconcat(sources, opts) end

--- Vertical stitching.
---@param sources image_cv_source[] input list
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Splicing result
function M.vconcat(sources, opts) end

--- Extract the specified channel.
---@param source image_cv_source input
---@param channel integer Channel index, starting from 0
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Single channel results
function M.extract_channel(source, channel, opts) end

--- Insert single channel data into the target channel.
---@param source image_cv_source Single channel input
---@param dst image_cv_source target
---@param channel integer Channel index, starting from 0
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.insert_channel(source, dst, channel, opts) end

--- Rotate.
---@param source image_cv_source input
---@param rotate_code integer|string rotate code
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.rotate(source, rotate_code, opts) end

--- Flip.
---@param source image_cv_source input
---@param flip_code integer|string flip code
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.flip(source, flip_code, opts) end

--- Transpose.
---@param source image_cv_source input
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.transpose(source, opts) end

--- Get the perspective transformation matrix.
---@param src_points image_cv_point[] Source point, 4 points
---@param dst_points image_cv_point[] Target points, 4 points
---@return image_cv_mat* matrix transformation matrix
function M.get_perspective_transform(src_points, dst_points) end

--- Perform a perspective transformation on a set of points.
---@param points image_cv_point[] Point set
---@param matrix image_cv_source 3x3 transformation matrix
---@return image_cv_point[] points Transformed point set
function M.perspective_transform(points, matrix) end

--- Perspective transform image or mat.
---@param source image_cv_source input
---@param matrix image_cv_source 3x3 transformation matrix
---@param width integer Output width
---@param height integer Output high
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.warp_perspective(source, matrix, width, height, opts) end

--- Get the affine transformation matrix.
---@param src_points image_cv_point[] Source point, 3 points
---@param dst_points image_cv_point[] Target points, 3 points
---@return image_cv_mat* matrix transformation matrix
function M.get_affine_transform(src_points, dst_points) end

--- Perform an affine transformation on a set of points.
---@param points image_cv_point[] Point set
---@param matrix image_cv_source 2x3 transformation matrix
---@return image_cv_point[] points Transformed point set
function M.transform(points, matrix) end

--- Affine transform image or mat.
---@param source image_cv_source input
---@param matrix image_cv_source 2x3 transformation matrix
---@param width integer Output width
---@param height integer Output high
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.warp_affine(source, matrix, width, height, opts) end

--- Adjust size.
---@param source image_cv_source input
---@param width? integer Output width
---@param height? integer Output high
---@param interpolation_or_opts? image_cv_interpolation|image_cv_resize_options Interpolation methods or options
---@param opts? image_cv_resize_options Options
---@return image_cv_result result Processing results
function M.resize(source, width, height, interpolation_or_opts, opts) end

--- Repeat matrix.
---@param source image_cv_source input
---@param ny integer Number of vertical repetitions
---@param nx integer Lateral repetitions
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
M["repeat"] = function(source, ny, nx, opts) end

--- Downsampling.
---@param source image_cv_source input
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.pyr_down(source, opts) end

--- upsampling.
---@param source image_cv_source input
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.pyr_up(source, opts) end

--- Capture a subpixel rectangle.
---@param source image_cv_source input
---@param width integer wide
---@param height integer high
---@param center image_cv_point center point
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.get_rect_sub_pix(source, width, height, center, opts) end

--- Add a border.
---@param source image_cv_source input
---@param top integer top border
---@param bottom integer bottom border
---@param left integer left border
---@param right integer right border
---@param border_type? image_cv_border_type Border type
---@param value? image_cv_scalar fill value
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.copy_make_border(source, top, bottom, left, right, border_type, value, opts) end

--- Absolutely bad.
---@param src1 image_cv_source Enter 1
---@param src2 image_cv_source Enter 2
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.absdiff(src1, src2, opts) end

--- addition.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.add(src1, rhs, opts) end

--- Subtraction.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.subtract(src1, rhs, opts) end

--- multiplication.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param scale? number Zoom
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.multiply(src1, rhs, scale, opts) end

--- Division.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param scale? number Zoom
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.divide(src1, rhs, scale, opts) end

--- Compare.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param cmp_op integer|string comparison operation
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.compare(src1, rhs, cmp_op, opts) end

--- Reduce.
---@param source image_cv_source input
---@param dim integer Dimensions
---@param op integer|string Operation
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.reduce(source, dim, op, opts) end

--- Sum.
---@param source image_cv_source input
---@return image_cv_scalar scalar summation result
function M.sum(source) end

--- Calculate the norm.
---@param src1 image_cv_source Enter 1
---@param rhs_or_norm_type? image_cv_source|image_cv_norm_type rvalue or norm type
---@param norm_type_or_mask? image_cv_norm_type|image_cv_source norm type or mask
---@param mask? image_cv_source mask
---@return number norm norm
function M.norm(src1, rhs_or_norm_type, norm_type_or_mask, mask) end

--- Copied to a new mat, a mask can be assigned.
---@param source image_cv_source input
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.copy_to(source, mask_or_opts, opts) end

--- Set the pixel value.
---@param source image_cv_source input
---@param value image_cv_scalar value
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.set_to(source, value, mask_or_opts, opts) end

--- Fixed threshold binarization.
---@param source image_cv_source input
---@param thresh number threshold
---@param maxval number maximum value
---@param type? image_cv_threshold_type Threshold type
---@param opts? image_cv_binary_options|{ inplace?: boolean, return_image?: boolean, return_threshold?: boolean } Options
---@return image_cv_result result Processing results
---@return number? used_threshold actual threshold
function M.threshold(source, thresh, maxval, type, opts) end

--- Adaptive threshold binarization.
---@param source image_cv_source input
---@param maxval number maximum value
---@param method integer|string adaptive method
---@param type image_cv_threshold_type Threshold type
---@param block_size integer block size
---@param c number constant
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.adaptive_threshold(source, maxval, method, type, block_size, c, opts) end

--- Mean blur.
---@param source image_cv_source input
---@param ksize integer core size
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.blur(source, ksize, opts) end

--- Gaussian blur.
---@param source image_cv_source input
---@param kx integer Lateral core size
---@param ky integer Longitudinal core size
---@param sigma_x? number sigma X
---@param sigma_y? number sigma Y
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.gaussian_blur(source, kx, ky, sigma_x, sigma_y, opts) end

--- The median is blurry.
---@param source image_cv_source input
---@param ksize integer core size
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.median_blur(source, ksize, opts) end

--- Bilateral filtering.
---@param source image_cv_source input
---@param d integer neighborhood diameter
---@param sigma_color number color sigma
---@param sigma_space number space sigma
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.bilateral_filter(source, d, sigma_color, sigma_space, opts) end

--- Histogram equalization.
---@param source image_cv_source input
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.equalize_hist(source, opts) end

--- CLAHE adaptive histogram equalization.
---@param source image_cv_source input
---@param clip_limit_or_opts? number|image_cv_binary_options clip limit or option
---@param tile_width? integer tile wide
---@param tile_height? integer tile high
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.clahe(source, clip_limit_or_opts, tile_width, tile_height, opts) end

--- Normalize.
---@param source image_cv_source input
---@param opts? image_cv_binary_options|{ alpha?: number, beta?: number, norm_type?: image_cv_norm_type, inplace?: boolean, return_image?: boolean } Options
---@return image_cv_result result Processing results
function M.normalize(source, opts) end

--- average value.
---@param source image_cv_source input
---@param mask? image_cv_source mask
---@return image_cv_scalar scalar average value
function M.mean(source, mask) end

--- mean and standard deviation.
---@param source image_cv_source input
---@param mask? image_cv_source mask
---@return image_cv_scalar mean average value
---@return image_cv_scalar stddev standard deviation
function M.mean_std_dev(source, mask) end

--- Count the number of non-zero elements.
---@param source image_cv_source input
---@return integer count non-zero quantity
function M.count_non_zero(source) end

--- Range detection.
---@param source image_cv_source input
---@param lower image_cv_scalar Nether
---@param upper image_cv_scalar upper bound
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.in_range(source, lower, upper, opts) end

--- Weighted blend.
---@param src1 image_cv_source Enter 1
---@param alpha number src1 weight
---@param src2 image_cv_source Enter 2
---@param beta number src2 weight
---@param gamma? number offset
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.add_weighted(src1, alpha, src2, beta, gamma, opts) end

--- Bitwise AND.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.bitwise_and(src1, rhs, mask_or_opts, opts) end

--- Bitwise OR.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.bitwise_or(src1, rhs, mask_or_opts, opts) end

--- Bitwise XOR.
---@param src1 image_cv_source Enter 1
---@param rhs image_cv_source|image_cv_scalar rvalue
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.bitwise_xor(src1, rhs, mask_or_opts, opts) end

--- Bitwise negation.
---@param source image_cv_source input
---@param mask_or_opts? image_cv_source|image_cv_binary_options Mask or option
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.bitwise_not(source, mask_or_opts, opts) end

--- Canny edge detection.
---@param source image_cv_source input
---@param threshold1 number Threshold 1
---@param threshold2 number Threshold 2
---@param aperture_size? integer aperture size
---@param l2gradient? boolean Whether to use L2 gradient
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.canny(source, threshold1, threshold2, aperture_size, l2gradient, opts) end

--- Sobel operator.
---@param source image_cv_source input
---@param ddepth integer|string Output depth
---@param dx integer X Order
---@param dy integer Y Order
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.sobel(source, ddepth, dx, dy, opts) end

--- Scharr operator.
---@param source image_cv_source input
---@param ddepth integer|string Output depth
---@param dx integer X Order
---@param dy integer Y Order
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.scharr(source, ddepth, dx, dy, opts) end

--- Laplacian operator.
---@param source image_cv_source input
---@param ddepth integer|string Output depth
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.laplacian(source, ddepth, opts) end

--- Scale and take absolute value.
---@param source image_cv_source input
---@param alpha? number Zoom
---@param beta? number offset
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.convert_scale_abs(source, alpha, beta, opts) end

--- Get the structure element.
---@param shape integer|string shape
---@param width integer wide
---@param height integer high
---@param anchor? image_cv_point anchor point
---@return image_cv_mat* kernel Structural elements
function M.get_structuring_element(shape, width, height, anchor) end

--- corrosion.
---@param source image_cv_source input
---@param kernel image_cv_source Structural elements
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.erode(source, kernel, opts) end

--- swell.
---@param source image_cv_source input
---@param kernel image_cv_source Structural elements
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.dilate(source, kernel, opts) end

--- Morphological operations.
---@param source image_cv_source input
---@param op integer|string Operation
---@param kernel image_cv_source Structural elements
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.morphology_ex(source, op, kernel, opts) end

--- Remap.
---@param source image_cv_source input
---@param map1 image_cv_source map1
---@param map2 image_cv_source map2
---@param interpolation? image_cv_interpolation interpolation method
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.remap(source, map1, map2, interpolation, opts) end

--- Fill with water.
---@param source image_cv_source input
---@param seed_point image_cv_point seed point
---@param new_val image_cv_scalar fill value
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.flood_fill(source, seed_point, new_val, opts) end

--- Phase related.
---@param src1 image_cv_source Enter 1
---@param src2 image_cv_source Enter 2
---@param window? image_cv_source window
---@return image_cv_point shift offset
---@return number response response
function M.phase_correlate(src1, src2, window) end

--- Calculate the amplitude.
---@param x image_cv_source x weight
---@param y image_cv_source y weight
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Amplitude
function M.magnitude(x, y, opts) end

--- Calculate the phase.
---@param x image_cv_source x weight
---@param y image_cv_source y weight
---@param angle_in_degrees? boolean Whether to return the angle
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Phase
function M.phase(x, y, angle_in_degrees, opts) end

--- Convert Cartesian coordinates to polar coordinates.
---@param x image_cv_source x weight
---@param y image_cv_source y weight
---@param angle_in_degrees? boolean Whether to return the angle
---@param opts? image_cv_binary_options Options
---@return image_cv_result magnitude Amplitude
---@return image_cv_result angle angle
function M.cart_to_polar(x, y, angle_in_degrees, opts) end

--- Convert polar coordinates to Cartesian coordinates.
---@param magnitude image_cv_source Amplitude
---@param angle image_cv_source angle
---@param angle_in_degrees? boolean Angle unit
---@param opts? image_cv_binary_options Options
---@return image_cv_result x x weight
---@return image_cv_result y y weight
function M.polar_to_cart(magnitude, angle, angle_in_degrees, opts) end

--- Get the 2D rotation matrix.
---@param center image_cv_point center point
---@param angle number angle
---@param scale? number Zoom
---@return image_cv_mat* matrix rotation matrix
function M.get_rotation_matrix_2d(center, angle, scale) end

--- Create a Hanning window.
---@param width integer wide
---@param height integer high
---@param type? integer|string Type
---@return image_cv_mat* window window
function M.create_hanning_window(width, height, type) end

--- Find the outline.
---@param source image_cv_source input
---@param mode? integer|string Search mode
---@param method? integer|string Approximate method
---@param opts? { return_hierarchy?: boolean } Options
---@return image_cv_contour[] contours outline array
---@return image_cv_contour_hierarchy[]? hierarchy hierarchical relationship
function M.find_contours(source, mode, method, opts) end

--- Connected domain analysis.
---@param source image_cv_source input
---@param connectivity? 4|8 connectivity
---@param ltype? integer|string Tag type
---@return image_cv_connected_components_result result Connected domain results
function M.connected_components_with_stats(source, connectivity, ltype) end

--- Calculate the bounding rectangle.
---@param contour image_cv_contour contour
---@return image_cv_rect rect bounding rectangle
function M.bounding_rect(contour) end

--- Calculate the contour area.
---@param contour image_cv_contour contour
---@param oriented? boolean Whether to bring direction
---@return number area area
function M.contour_area(contour, oriented) end

--- Calculate the contour perimeter.
---@param contour image_cv_contour contour
---@param closed? boolean Is it closed?
---@return number length perimeter
function M.arc_length(contour, closed) end

--- Polygon approximation.
---@param contour image_cv_contour contour
---@param epsilon number Accuracy
---@param closed? boolean Is it closed?
---@return image_cv_contour contour Approximate contour
function M.approx_poly_dp(contour, epsilon, closed) end

--- Convex hull.
---@param contour image_cv_contour contour
---@param return_points? boolean Whether to return the point; false returns the index
---@return image_cv_contour|integer[] hull convex hull
function M.convex_hull(contour, return_points) end

--- Point-to-polygon testing.
---@param contour image_cv_contour contour
---@param point image_cv_point point
---@param measure_dist? boolean Whether to measure distance
---@return number result result
function M.point_polygon_test(contour, point, measure_dist) end

--- Find non-zero points.
---@param source image_cv_source input
---@return image_cv_point[] points non-zero point
function M.find_non_zero(source) end

--- Match the shapes.
---@param contour1 image_cv_contour Contour 1
---@param contour2 image_cv_contour Contour 2
---@param method? integer method
---@param parameter? number parameters
---@return number score score
function M.match_shapes(contour1, contour2, method, parameter) end

--- Fit the ellipse.
---@param contour image_cv_contour contour
---@return image_cv_rotated_rect rect rotate rectangle
function M.fit_ellipse(contour) end

--- Fit Ellipse AMS.
---@param contour image_cv_contour contour
---@return image_cv_rotated_rect rect rotate rectangle
function M.fit_ellipse_ams(contour) end

--- Fit ellipse Direct.
---@param contour image_cv_contour contour
---@return image_cv_rotated_rect rect rotate rectangle
function M.fit_ellipse_direct(contour) end

--- Rotated rectangles intersect.
---@param rect1 image_cv_rotated_rect Rectangle 1
---@param rect2 image_cv_rotated_rect Rectangle 2
---@return integer code intersection type
---@return image_cv_point[] points intersection point
function M.rotated_rectangle_intersection(rect1, rect2) end

--- Fit a straight line.
---@param contour image_cv_contour contour
---@param dist_type? image_cv_distance_type distance type
---@param param? number parameters
---@param reps? number Radius accuracy
---@param aeps? number Angle accuracy
---@return image_cv_line_result line straight line
function M.fit_line(contour, dist_type, param, reps, aeps) end

--- Minimum area rectangle.
---@param contour image_cv_contour contour
---@return image_cv_rotated_rect rect rotate rectangle
function M.min_area_rect(contour) end

--- Minimum circumscribed circle.
---@param contour image_cv_contour contour
---@return image_cv_circle_result circle round
function M.min_enclosing_circle(contour) end

--- Minimal circumscribed triangle.
---@param contour image_cv_contour contour
---@return image_cv_triangle_result triangle result
function M.min_enclosing_triangle(contour) end

--- Intersection of convex polygons.
---@param contour1 image_cv_contour Contour 1
---@param contour2 image_cv_contour Contour 2
---@param handle_nested? boolean Whether to handle nesting
---@return image_cv_intersection_result result result
function M.intersect_convex_convex(contour1, contour2, handle_nested) end

--- Get the four vertices of the rotated rectangle.
---@param rect image_cv_rotated_rect rotate rectangle
---@return image_cv_point[] points vertex array
function M.box_points(rect) end

--- Calculate moments.
---@param source image_cv_source|image_cv_contour input
---@param binary_image? boolean Whether to process it as a binary image
---@return image_cv_moments moments moment
function M.moments(source, binary_image) end

--- Calculate the Hu moments.
---@param source image_cv_source|image_cv_contour input
---@param binary_image? boolean Whether to process it as a binary image
---@return number[] hu_moments Hu moment array
function M.hu_moments(source, binary_image) end

--- Calculate the histogram.
---@param source image_cv_source input
---@param opts? image_cv_hist_options Options
---@return image_cv_mat* hist Histogram
function M.calc_hist(source, opts) end

--- Compare histograms.
---@param hist1 image_cv_source Histogram 1
---@param hist2 image_cv_source Histogram 2
---@param method? image_cv_hist_compare_method comparison method
---@return number score score
function M.compare_hist(hist1, hist2, method) end

--- Probabilistic Hough line detection.
---@param source image_cv_source input
---@param rho number rho
---@param theta number theta
---@param threshold integer threshold
---@param min_line_length? number Minimum segment length
---@param max_line_gap? number Maximum segment gap
---@return table[] lines Segment list
function M.hough_lines_p(source, rho, theta, threshold, min_line_length, max_line_gap) end

--- Hough circle detection.
---@param source image_cv_source input
---@param method image_cv_hough_circle_method Detection method
---@param dp number Accumulator resolution scale
---@param min_dist number Minimum distance between circle centers
---@param param1? number Parameter 1
---@param param2? number Parameter 2
---@param min_radius? integer minimum radius
---@param max_radius? integer maximum radius
---@return table[] circles circle list
function M.hough_circles(source, method, dp, min_dist, param1, param2, min_radius, max_radius) end

--- distance transformation.
---@param source image_cv_source input
---@param distance_type? image_cv_distance_type distance type
---@param mask_size? integer mask size
---@param opts? image_cv_binary_options|{ dst_type?: integer|string, return_image?: boolean } Options
---@return image_cv_result result distance map
function M.distance_transform(source, distance_type, mask_size, opts) end

--- Corner detection.
---@param source image_cv_source input
---@param max_corners integer Maximum number of corners
---@param quality_level number quality threshold
---@param min_distance number minimum distance
---@param mask_or_block_size? image_cv_source|integer Mask or block size
---@param use_harris? boolean Whether to use Harris
---@param k? number Harris parameters
---@return image_cv_point[] corners corner point
function M.good_features_to_track(source, max_corners, quality_level, min_distance, mask_or_block_size, use_harris, k) end

--- Template matching.
---@param image image_cv_source Original picture
---@param templ image_cv_source Template
---@param method? image_cv_template_method matching method
---@param mask? image_cv_source mask
---@return image_cv_mat* result matching result matrix
function M.match_template(image, templ, method, mask) end

--- Get the minimum, maximum value and position.
---@param source image_cv_source input
---@param mask? image_cv_source mask
---@return image_cv_min_max_loc result result
function M.min_max_loc(source, mask) end

--- Draw a rectangle.
---@param source image_cv_source input
---@param x1 integer Upper left corner X
---@param y1 integer Upper left corner Y
---@param x2 integer Lower right corner X
---@param y2 integer Lower right corner Y
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.rectangle(source, x1, y1, x2, y2, color, thickness, opts) end

--- Draw a circle.
---@param source image_cv_source input
---@param x integer Circle center X
---@param y integer Circle center Y
---@param radius integer radius
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.circle(source, x, y, radius, color, thickness, opts) end

--- Draw line segments.
---@param source image_cv_source input
---@param x1 integer Starting point
---@param y1 integer Starting point Y
---@param x2 integer end point
---@param y2 integer End point Y
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.line(source, x1, y1, x2, y2, color, thickness, opts) end

--- Draw a polyline.
---@param source image_cv_source input
---@param points image_cv_contours Point set
---@param is_closed boolean Is it closed?
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param line_type? image_cv_line_type linear
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.polylines(source, points, is_closed, color, thickness, line_type, opts) end

--- Filled polygon.
---@param source image_cv_source input
---@param points image_cv_contours Point set
---@param color image_cv_scalar Color
---@param line_type? image_cv_line_type linear
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.fill_poly(source, points, color, line_type, opts) end

--- Draw the outline.
---@param source image_cv_source input
---@param contours image_cv_contours outline array
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.draw_contours(source, contours, color, thickness, opts) end

--- Calculate text size.
---@param text string text
---@param font_face integer|string font
---@param font_scale number Font scaling
---@param thickness? integer Line width
---@return image_cv_text_size size text size
function M.get_text_size(text, font_face, font_scale, thickness) end

--- Draw text.
---@param source image_cv_source input
---@param text string text
---@param org image_cv_point origin
---@param font_face integer|string font
---@param font_scale number Font scaling
---@param color image_cv_scalar Color
---@param thickness? integer Line width
---@param line_type? image_cv_line_type linear
---@param bottom_left_origin? boolean Whether to take the lower left as the origin
---@param opts? image_cv_binary_options Options
---@return image_cv_result result Processing results
function M.put_text(source, text, org, font_face, font_scale, color, thickness, line_type, bottom_left_origin, opts) end

--- Find the template image in the image.
---@param image ImageObject* Original picture
---@param template ImageObject* Template picture
---@param opts? image_cv_match_options Options
---@return integer|image_cv_match[] x_or_matches X coordinates or matching array
---@return integer|ImageObject*|nil y_or_visual Y Coordinates or visual images
---@return number? confidence Confidence
---@return ImageObject*? visual Visualization pictures
function M.find_image(image, template, opts) end

--- Binarize and replace the current image.
---@param image ImageObject* pictures
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image Current picture
function M.binaryzation(image, threshold) end

--- Binarize and return a copy.
---@param image ImageObject* pictures
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image new pictures
function M.binaryzation_copy(image, threshold) end

--- Binarize and replace the current image.
---@param image ImageObject* pictures
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image Current picture
function M.binarization(image, threshold) end

--- Binarize and return a copy.
---@param image ImageObject* pictures
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image new pictures
function M.binarization_copy(image, threshold) end

--- Binarize and replace the current image.
---@param image ImageObject* pictures
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image Current picture
function M.binarize(image, threshold) end

--- Binarize and return a copy.
---@param image ImageObject* pictures
---@param threshold? number Threshold, OTSU is used when omitted
---@return ImageObject* image new pictures
function M.binarize_copy(image, threshold) end

--- Resize the image and return a copy.
---@param image ImageObject* pictures
---@param width integer Output width
---@param height integer Output high
---@return ImageObject* image new pictures
function M.resize_copy(image, width, height) end

--- Splice long images.
---@param images ImageObject*[] Picture array
---@param opts? image_cv_stitch_long_options Options
---@return ImageObject* image Long picture after splicing
function M.stitch_long(images, opts) end

--- Find polygons.
---@param image ImageObject* pictures
---@param opts image_cv_find_polygon_options Options
---@return image_cv_contour[] contours outline array
---@return ImageObject*? visual Visualization pictures
function M.find_polygon(image, opts) end

--- Compare the differences between two pictures of the same size.
---@param image1 ImageObject* Picture 1
---@param image2 ImageObject* Picture 2
---@param opts? image_cv_compare_options Options
---@return image_cv_contour[] contours difference contour
---@return ImageObject*? visual Visualization pictures
function M.compare_image(image1, image2, opts) end

--- Find contours that are similar to the template shape.
---@param image ImageObject* pictures
---@param shape ImageObject*|image_cv_contours Template image or template outline
---@param opts? image_cv_find_shapes_options Options
---@return image_cv_contour[][] groups Matching contours corresponding to each template
---@return ImageObject*? visual Visualization pictures
function M.find_shapes(image, shape, opts) end

--- Extract image outlines.
---@param image ImageObject* pictures
---@param opts? image_cv_to_shapes_options Options
---@return image_cv_contour[] contours outline array
---@return ImageObject*? visual Visualization pictures
function M.to_shapes(image, opts) end

--- Detect multiple templates based on features.
---@param image ImageObject* pictures
---@param opts image_cv_detect_templates_options Template array and options
---@return image_cv_contour[] contours Detected template outline
---@return ImageObject*? visual Visualization pictures
function M.detect_templates(image, opts) end

--- Initialize the global Paddle OCR context.
---@param opts? image_cv_paddle_ocr_config Options
---@return boolean ok Is it successful?
---@return string? errMsg error message
function M.paddle_ocr_init(opts) end

--- Perform OCR on images.
---@param image ImageObject* pictures
---@param opts? image_cv_paddle_ocr_config Options
---@return image_cv_paddle_ocr_item[]? results Recognition results
---@return ImageObject*|string|nil visual_or_err Visual images or error messages
function M.paddle_ocr(image, opts) end

--- Create a Paddle OCR context.
---@param opts? image_cv_paddle_ocr_config Options
---@return image_cv_paddle_ocr_context*? context OCR context
---@return string? errMsg error message
function M.new_paddle_ocr(opts) end

--- Create Paddle YOLOv3 object detection context.
---@param opts? image_cv_paddle_yolov3_options Options
---@return image_cv_paddle_yolov3_context*? context YOLOv3 context
---@return string? errMsg error message
function M.new_paddle_yolov3(opts) end

--- Create Paddle YOLOv3 object detection context.
---@param opts? image_cv_paddle_yolov3_options Options
---@return image_cv_paddle_yolov3_context*? context YOLOv3 context
---@return string? errMsg error message
function M.new_paddle_yolov3_object_detector(opts) end

return M
