image.doc

    MoonBit document scene entry: OCR, barcode, document metadata, form-field imaging.

    Download zip
    Author
    Version
    0.1.31
    License
    MIT
    Last updated
    1 hour ago
    Downloads
    14

    #walkzzz/image.doc

    文档场景入口(S16):扫描件、票据、证件、表单类任务需要的 OCR、条码、元数据与字段图像能力,一次 import 全拿到。

    moon add walkzzz/image.doc

    import "walkzzz/image.doc"
    // 之后直接写 @doc.<符号>;符号清单见本包 pkg.generated.mbti

    #再导出了什么

    原子包提供
    walkzzz/image.vision/ocrOCR 主流程、版面理解、手写与多语种识别、置信度校准
    walkzzz/image.codec/barcode一维码(Code128/Code39/EAN…)与二维码(QR)编码解码
    walkzzz/image.codec/metaEXIF / 文档元数据读写
    walkzzz/image.vision/fieldimg字段图像处理(表格线、印章、签字区裁切)

    #约定

    • 本包只有 pub using 再导出,没有实现;moon.pkg 与 doc_scene.mbt 由 scripts/gen_scenes.mjs 生成,请勿手改。
    • 归属真值在仓库的 docs/scenes.json;改归属改那里再重跑生成器。
    • #deprecated 符号不会出现在入口里(生成器跳过),新代码不会踩到历史包袱。
    • 需要深层原子包的其它符号时,仍可单独 moon add walkzzz/image.vision 后 import "walkzzz/image.vision/ocr"——两条路径指向同一份实现。

    #文档

    • 场景总览:https://github.com/walkzzz/image.mbt/blob/main/docs/scenes.md
    • API 索引:https://github.com/walkzzz/image.mbt/blob/main/docs/api_index.md
    • 完整签名以本包 pkg.generated.mbti 为准。

    AccuracyStats

    准确率统计

    AdaptivePreprocessConfig

    自适应预处理配置

    AdvancedChineseOcrConfig

    完善中文 OCR 配置

    ApiServerConfig

    API Server 配置

    AugmentationConfig

    数据增强配置

    AugmentationType

    数据增强类型 #non_exhaustive 表示未来可能添加新构造器

    BarcodeConfig

    条形码识别配置

    BarcodeResult

    条形码识别结果

    BarcodeType

    条形码类型 #non_exhaustive 表示未来可能添加新构造器

    BatchOcrConfig

    批处理配置

    BatchProgress

    批处理进度

    BatchResultSummary

    批处理结果汇总

    BatchTask

    单个批处理任务

    BatchTaskStatus

    批处理任务状态

    CharRecognitionResult

    字符识别结果

    CharSegment

    字符分割结构体

    ChineseCharInfo

    汉字结构信息(增强版)

    ChineseCharStructure

    汉字结构信息

    ChineseOcrConfig

    中文 OCR 配置

    ChineseRadical

    汉字部件结构体

    ClassificationResult

    分类结果结构体

    CliConfig

    CLI 配置

    Code128Charset

    Code128 字符集类型

    CommonErrorPattern

    常见错误模式

    ComplexLayoutAnalysis

    复杂版面分析结果

    ComplexLayoutType

    复杂版面类型 #non_exhaustive 表示未来可能添加新构造器

    ConfusionEntry

    混淆矩阵条目

    ConfusionMatrix

    混淆矩阵

    CorrectionEntry

    纠错条目

    CorrectionResult

    纠错结果

    DLCnnModelConfig

    CNN 模型配置

    DLConv2DConfig

    卷积层配置

    DLDenseConfig

    全连接层配置

    DLFeatureExtractor

    特征提取器

    DLInferenceResult

    推理结果

    DLLayerType

    神经网络层类型 #non_exhaustive 表示未来可能添加新构造器

    DLNeuralLayer

    神经网络层

    DLTrainingHistory

    训练历史

    DLTrainingSample

    训练样本

    DataLoader

    数据加载器

    DeploymentEnvironment

    部署环境类型 #non_exhaustive 表示未来可能添加新构造器

    DictCharEntry

    汉字条目

    DictCharMatch

    汉字相似度匹配结果

    DictCharStructure

    汉字结构类型 #non_exhaustive 表示未来可能添加新构造器

    DictChineseDict

    中文字库

    DictComponent

    汉字部件

    DictComponentResult

    部件识别结果

    Dictionary

    词典结构体

    DictionaryEntry

    词典条目

    DigitOcrConfig

    数字 OCR 配置

    DistanceMetric

    距离度量类型 #non_exhaustive 表示未来可能添加新构造器

    DistortionDetectionResult

    畸变检测结果

    DistortionType

    畸变类型 #non_exhaustive 表示未来可能添加新构造器

    DockerConfig

    Docker 配置

    DocumentBlock

    文档块结构体(增强版)

    DocumentBlockType

    文档块类型(增强版) #non_exhaustive 表示未来可能添加新构造器

    DocumentElement

    文档元素结构体

    DocumentElementType

    文档元素类型 #non_exhaustive 表示未来可能添加新构造器

    DocumentStructure

    文档结构结构体

    DocumentTreeNode

    文档结构树节点

    DocumentUnderstandingEnhancedConfig

    增强文档理解配置

    DropFallResult

    滴水算法分割结果

    EnglishOcrConfig

    英文 OCR 配置

    EnhancedChineseOcrConfig

    增强中文 OCR 配置

    EnhancedDocument

    增强版文档结构

    EnhancedDocumentElement

    增强版文档元素

    EnhancedTableResult

    完整表格识别结果

    EnsembleConfig

    集成分类器配置

    ErrorAnalysisEntry

    错误分析条目

    ErrorAnalysisReport

    错误分析报告

    ExifInfo

    EXIF 元数据信息

    ExifInfoExtended

    扩展 EXIF 元数据信息

    ExtractedImage

    提取的图片区域

    GridFeatures

    网格特征

    HandwritingCharFeature

    手写字符特征

    HandwritingOcrConfig

    手写体识别配置

    HandwritingOcrEnhancedConfig

    增强手写体识别配置

    HandwritingRecognitionConfig

    手写识别配置

    HandwritingRecognitionResult

    手写识别结果

    HandwritingStrokeFeatures

    手写体笔画特征

    HandwritingStyle

    手写体类型 #non_exhaustive 表示未来可能添加新构造器

    HandwritingTemplate

    手写字体模板

    HogFeatures

    HOG 特征描述子

    IptcInfo

    IPTC IIM 元数据(常用字段)

    KnnClassifier

    KNN 分类器

    LRSchedulerConfig

    学习率调度器配置

    LRSchedulerType

    学习率调度器类型 #non_exhaustive 表示未来可能添加新构造器

    LanguageDetectionResult

    语言检测结果

    LanguageModelState

    语言模型状态

    LanguageType

    语言类型 #non_exhaustive 表示未来可能添加新构造器

    LayoutType

    布局类型 #non_exhaustive 表示未来可能添加新构造器

    LbpFeatures

    LBP 特征描述子

    ListItemInfo

    列表项

    ListItemType

    列表项类型 #non_exhaustive 表示未来可能添加新构造器

    MarkdownDocument

    完整 Markdown 文档

    MarkdownElement

    Markdown 元素

    MarkdownElementType

    Markdown 元素类型 #non_exhaustive 表示未来可能添加新构造器

    MarkdownImage

    图片区域

    MarkdownSymbol

    符号识别结果

    MarkdownTable

    表格数据

    MemoryUsageStats

    内存使用统计

    ModelPackageConfig

    模型打包配置

    MultilingualOcrConfig

    多语言识别配置

    MultilingualOcrEnhancedConfig

    增强多语言识别配置

    NgramModel

    N-gram 语言模型

    OCRPageResult

    OCR 页面结果

    OcrAccuracyEnhancedConfig

    准确率提升配置

    OcrCharResult

    单个字符识别结果

    OcrConnectedComponent

    连通域结构体

    OcrConnectedComponentsResult

    连通域标记结果

    OcrErrorType

    错误类型 #non_exhaustive 表示未来可能添加新构造器

    OcrResult

    OCR 识别结果结构体

    OptimizerConfig

    优化器配置

    OptimizerType

    优化器类型 #non_exhaustive 表示未来可能添加新构造器

    PageRegion

    页面区域

    PageRegionType

    页面区域类型 #non_exhaustive 表示未来可能添加新构造器

    PerformanceBenchmark

    性能基准结果

    PngTextChunk

    PNG text chunk(关键字-文本对)

    PostProcessConfig

    后处理配置

    ProjectionFeatures

    投影特征

    ProjectionResult

    投影结果结构体

    PunctuationTemplate

    标点符号模板

    QrDecodeResult

    QR Code 解码结果

    QrFinderPattern

    QR Code 定位图案(Finder Pattern)

    RobustnessReport

    鲁棒性评估报告

    ScalarField

    标量场:2D 标量场,data 为行主序 Float 数组,长度 = width * height。 标量场:2D Scalar field: 2D

    ScanOCRConfig

    扫描文档配置

    ScanQuality

    扫描质量评估结果

    ScanQualityLevel

    扫描质量等级 #non_exhaustive 表示未来可能添加新构造器

    SimilarCharMapping

    相似字符映射

    SplitPoint

    分割点结构体

    StatisticalFeatures

    统计特征

    StrokeFeature

    笔画特征

    StrokeSegmentationResult

    连笔分割结果

    StrokeType

    笔画类型 #non_exhaustive 表示未来可能添加新构造器

    TableCell

    单元格结构体

    TableCellContent

    单元格内容

    TableDetectionResult

    表格线检测结果

    TableLine

    表格线结构体

    TableLineType

    表格线类型 #non_exhaustive 表示未来可能添加新构造器

    TableStructure

    表格结构结构体

    TemplateMatcher

    模板匹配分类器

    TensorField

    张量场:2D 张量场,data 为行主序,长度 = width * height * rows * cols。 张量场:2D Tensor field: 2D

    TextBlock

    文本块(版面分析结果)

    TextLine

    文本行结构体

    TextLineAttributes

    文本行属性

    TextLineInfo

    文本行结构体

    TextRegion

    文本区域结构体

    TextRegionType

    文本区域类型 #non_exhaustive 表示未来可能添加新构造器

    TrainingConfig

    训练配置

    TrainingDataset

    训练样本数据集

    TrainingMetrics

    训练指标

    TrainingSample

    训练样本结构体

    TrainingState

    训练状态

    VectorField

    矢量场:2D 矢量场,data 为行主序 Float 数组,长度 = width * height * dim。 向量场:2D 向量场,行主序 Vector field: 2D vector field, data is row-major, length = width * height * dim.

    XmpInfo

    XMP 元数据(常用字段)

    adaptive_threshold_ocr

    fn adaptive_threshold_ocr(img :
    core
    /types.Image, block_size? : Int, c? : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    OCR 专用自适应阈值(结合全局阈值和局部阈值) 适用于光照不均匀的文档图像

    advanced_chinese_ocr_default_config

    fn advanced_chinese_ocr_default_config() ->
    vision
    /ocr.AdvancedChineseOcrConfig

    创建默认完善中文 OCR 配置

    analyze_complex_layout

    fn analyze_complex_layout(text_blocks : Array[
    vision
    /ocr.TextBlock], page_width : Int, page_height : Int) ->
    vision
    /ocr.ComplexLayoutAnalysis

    分析复杂版面

    analyze_document_layout

    fn analyze_document_layout(img :
    core
    /types.Image) ->
    vision
    /ocr.DocumentStructure raise
    core
    /types.LoadError

    分析文档版面(检测文本块、分类元素类型)

    analyze_layout_enhanced

    fn analyze_layout_enhanced(img :
    core
    /types.Image, config? :
    vision
    /ocr.DocumentUnderstandingEnhancedConfig) -> Array[
    vision
    /ocr.DocumentBlock] raise
    core
    /types.LoadError

    增强版面分析(基于连通域的文本块检测)

    analyze_layout_scan

    fn analyze_layout_scan(binary_img :
    core
    /types.Image) -> Array[
    vision
    /ocr.TextBlock] raise
    core
    /types.LoadError

    版面分析(基于投影的文本块检测)

    analyze_markdown_element_distribution

    fn analyze_markdown_element_distribution(doc :
    vision
    /ocr.MarkdownDocument) -> Array[(String, Int)]

    统计文档元素类型分布

    analyze_table_results

    fn analyze_table_results(tables : Array[
    vision
    /ocr.EnhancedTableResult]) -> Array[(String, Int)]

    统计表格识别结果

    analyze_table_structure

    fn analyze_table_structure(horizontal_lines : Array[
    vision
    /ocr.TableLine], vertical_lines : Array[
    vision
    /ocr.TableLine]) ->
    vision
    /ocr.TableStructure raise
    core
    /types.LoadError

    分析表格结构(基于水平线和垂直线)

    apply_augmentation

    fn apply_augmentation(sample :
    vision
    /ocr.DLTrainingSample, config :
    vision
    /ocr.AugmentationConfig) ->
    vision
    /ocr.DLTrainingSample

    应用数据增强

    augment_features

    fn augment_features(features : Array[Double], noise_level? : Double) -> Array[Double]

    特征增广(添加噪声、缩放、平移)

    augment_random_noise

    fn augment_random_noise(sample :
    vision
    /ocr.DLTrainingSample, noise_level : Double) ->
    vision
    /ocr.DLTrainingSample

    数据增强:随机噪声

    augment_random_rotation

    fn augment_random_rotation(sample :
    vision
    /ocr.DLTrainingSample, angle_range : Double) ->
    vision
    /ocr.DLTrainingSample

    数据增强:随机旋转

    augment_random_scale

    fn augment_random_scale(sample :
    vision
    /ocr.DLTrainingSample, scale_range : Double) ->
    vision
    /ocr.DLTrainingSample

    数据增强:随机缩放

    augment_random_shift

    fn augment_random_shift(sample :
    vision
    /ocr.DLTrainingSample, shift_range : Double) ->
    vision
    /ocr.DLTrainingSample

    数据增强:随机平移

    background_normalization

    fn background_normalization(img :
    core
    /types.Image, kernel_size? : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    背景归一化(将背景统一为白色) 适用于背景不均匀的文档图像

    barcode_default_config

    fn barcode_default_config() ->
    codec
    /barcode.BarcodeConfig

    创建默认条形码识别配置

    batch_correct_texts

    fn batch_correct_texts(texts : Array[String], context_type? : String) -> Array[
    vision
    /ocr.CorrectionResult] raise
    core
    /types.LoadError

    批量文本纠错

    batch_recognize_chars

    fn batch_recognize_chars(images : Array[
    core
    /types.Image], config :
    vision
    /ocr.DLCnnModelConfig, labels : Array[String]) -> Array[
    vision
    /ocr.DLInferenceResult] raise
    core
    /types.LoadError

    批量字符识别优化(减少重复计算)

    batch_scan_ocr

    fn batch_scan_ocr(images : Array[
    core
    /types.Image], config :
    vision
    /ocr.ScanOCRConfig) -> Array[
    vision
    /ocr.OCRPageResult] raise
    core
    /types.LoadError

    批量扫描文档 OCR

    batch_summary_to_string

    fn batch_summary_to_string(summary :
    vision
    /ocr.BatchResultSummary) -> String

    生成批处理报告

    build_document_structure_tree

    fn build_document_structure_tree(blocks : Array[
    vision
    /ocr.DocumentBlock]) -> Array[
    vision
    /ocr.DocumentTreeNode]

    构建文档结构树(层级结构)

    build_enhanced_elements

    fn build_enhanced_elements(lines : Array[
    vision
    /ocr.TextLineAttributes], page_width : Int, page_height : Int) ->
    vision
    /ocr.EnhancedDocument raise
    core
    /types.LoadError

    从文本行构建增强版文档元素

    build_gaussian_kernel_lut

    fn build_gaussian_kernel_lut(sigma : Double, radius : Int) -> Array[Double] raise
    core
    /types.LoadError

    预计算高斯核查找表

    build_grayscale_lut

    fn build_grayscale_lut() -> Array[Int]

    预计算灰度查找表(0-255 映射)

    build_markdown_document

    fn build_markdown_document(ocr_result :
    vision
    /ocr.OCRPageResult, title? : String) ->
    vision
    /ocr.MarkdownDocument raise
    core
    /types.LoadError

    从 OCR 结果构建 Markdown 文档

    build_threshold_lut

    fn build_threshold_lut(threshold : Int) -> Array[Int]

    预计算二值化查找表

    cache_friendly_horizontal_projection

    fn cache_friendly_horizontal_projection(img :
    core
    /types.Image) -> Array[Int] raise
    core
    /types.LoadError

    缓存友好的水平投影计算(按行连续访问)

    cache_friendly_vertical_projection

    fn cache_friendly_vertical_projection(img :
    core
    /types.Image) -> Array[Int] raise
    core
    /types.LoadError

    缓存友好的垂直投影计算(转置后按行访问)

    calculate_accuracy

    fn calculate_accuracy(predictions : Array[Int], labels : Array[Int]) -> Double

    计算准确率

    calculate_accuracy_improvement

    fn calculate_accuracy_improvement(before_results : Array[
    vision
    /ocr.CorrectionResult], expected_texts : Array[String]) -> (Double, Double, Double)

    计算纠错前后准确率提升

    calculate_accuracy_stats

    fn calculate_accuracy_stats(expected_lines : Array[String], actual_lines : Array[String]) ->
    vision
    /ocr.AccuracyStats raise
    core
    /types.LoadError

    计算完整准确率统计

    calculate_batch_progress

    fn calculate_batch_progress(tasks : Array[
    vision
    /ocr.BatchTask], elapsed_time_ms : Double) ->
    vision
    /ocr.BatchProgress raise
    core
    /types.LoadError

    计算批处理进度

    calculate_char_accuracy

    fn calculate_char_accuracy(expected : String, actual : String) -> Double

    计算字符级准确率

    calculate_chinese_similarity

    fn calculate_chinese_similarity(char1 :
    vision
    /ocr.DictCharEntry, char2 :
    vision
    /ocr.DictCharEntry) -> Double

    计算两个汉字的结构相似度

    calculate_edit_distance

    fn calculate_edit_distance(s1 : String, s2 : String) -> Int

    计算编辑距离(Levenshtein)

    calculate_learning_rate

    fn calculate_learning_rate(config :
    vision
    /ocr.LRSchedulerConfig, epoch : Int, current_lr : Double, val_loss : Double) -> Double raise
    core
    /types.LoadError

    计算学习率

    calculate_word_accuracy

    fn calculate_word_accuracy(expected : String, actual : String) -> Double

    计算词级准确率

    calibrate_confidence_enhanced

    fn calibrate_confidence_enhanced(raw_confidence : Double, distance_distribution : Array[Double]) -> Double

    置信度校准(基于距离分布的 Platt 缩放简化版)

    chebyshev_distance

    fn chebyshev_distance(a : Array[Double], b : Array[Double]) -> Double raise
    core
    /types.LoadError

    计算切比雪夫距离

    check_accuracy_threshold

    fn check_accuracy_threshold(stats :
    vision
    /ocr.AccuracyStats, min_char_accuracy? : Double, min_word_accuracy? : Double, min_f1_score? : Double) -> (Bool, Array[String]) raise
    core
    /types.LoadError

    验证准确率是否达标

    check_early_stopping

    fn check_early_stopping(state :
    vision
    /ocr.TrainingState, config :
    vision
    /ocr.TrainingConfig, current_val_accuracy : Double) -> (Bool,
    vision
    /ocr.TrainingState)

    早停检查

    chinese_ocr_default_config

    fn chinese_ocr_default_config() ->
    vision
    /ocr.ChineseOcrConfig

    创建默认中文 OCR 配置

    classify_markdown_element

    fn classify_markdown_element(block :
    vision
    /ocr.TextBlock, avg_font_size? : Double) ->
    vision
    /ocr.MarkdownElementType

    分类 Markdown 元素类型

    cnn_confusion_matrix

    fn cnn_confusion_matrix(test_samples : Array[
    vision
    /ocr.DLTrainingSample], config :
    vision
    /ocr.DLCnnModelConfig, labels : Array[String]) -> Array[Array[Int]] raise
    core
    /types.LoadError

    计算混淆矩阵

    cnn_infer

    fn cnn_infer(image_data : Array[Double], config :
    vision
    /ocr.DLCnnModelConfig, labels : Array[String]) ->
    vision
    /ocr.DLInferenceResult

    CNN 推理(简化版)

    cnn_recognize_char

    fn cnn_recognize_char(img :
    core
    /types.Image, config :
    vision
    /ocr.DLCnnModelConfig, labels : Array[String]) ->
    vision
    /ocr.DLInferenceResult raise
    core
    /types.LoadError

    CNN 字符识别:输入图像,返回识别结果

    cnn_recognize_digits

    fn cnn_recognize_digits(img :
    core
    /types.Image, config :
    vision
    /ocr.DLCnnModelConfig) ->
    vision
    /ocr.DLInferenceResult raise
    core
    /types.LoadError

    CNN 数字识别

    cnn_recognize_letters

    fn cnn_recognize_letters(img :
    core
    /types.Image, config :
    vision
    /ocr.DLCnnModelConfig) ->
    vision
    /ocr.DLInferenceResult raise
    core
    /types.LoadError

    CNN 字母识别

    cnn_train

    fn cnn_train(samples : Array[
    vision
    /ocr.DLTrainingSample], conv_weights : Array[Double], conv_bias : Array[Double], dense_weights : Array[Double], dense_bias : Array[Double], in_h : Int, in_w : Int, in_c : Int, conv_out_c : Int, k_size : Int, num_classes : Int, learning_rate : Double, epochs : Int) -> (Array[Double], Array[Double], Array[Double], Array[Double], Array[
    vision
    /ocr.DLTrainingHistory]) raise
    core
    /types.LoadError

    CNN 完整训练:多 epoch 训练

    cnn_train_step

    fn cnn_train_step(input : Array[Double], target : Int, conv_weights : Array[Double], conv_bias : Array[Double], dense_weights : Array[Double], dense_bias : Array[Double], in_h : Int, in_w : Int, in_c : Int, conv_out_c : Int, k_size : Int, num_classes : Int, learning_rate : Double) -> (Array[Double], Array[Double], Array[Double], Array[Double], Double) raise
    core
    /types.LoadError

    CNN 单步训练

    combined_features

    fn combined_features(img :
    core
    /types.Image) -> Array[Double] raise
    core
    /types.LoadError

    组合特征(将多种特征拼接成一个向量)

    complete_char_segmentation

    fn complete_char_segmentation(img :
    core
    /types.Image, min_char_width? : Int, max_char_width? : Int) -> Array[(Int, Int, Int, Int)] raise
    core
    /types.LoadError

    完整字符分割流水线
    1. 连通域初步分割
    2. 粘连字符检测
    3. 滴水算法分割粘连字符
    4. 后处理(合并过小、过滤噪声)

    compute_confusion_matrix

    fn compute_confusion_matrix(predictions : Array[Int], labels : Array[Int], num_classes : Int) -> Array[Array[Int]]

    混淆矩阵计算

    compute_distance

    fn compute_distance(a : Array[Double], b : Array[Double], metric :
    vision
    /ocr.DistanceMetric) -> Double raise
    core
    /types.LoadError

    计算距离(根据度量类型)

    compute_per_class_accuracy

    fn compute_per_class_accuracy(confusion_matrix : Array[Array[Int]]) -> Array[Double]

    计算每类准确率

    compute_reading_order

    fn compute_reading_order(elements : Array[
    vision
    /ocr.DocumentElement]) -> Array[Int] raise
    core
    /types.LoadError

    计算阅读顺序(从上到下,从左到右)

    connected_components_analysis

    fn connected_components_analysis(img :
    core
    /types.Image, connectivity? : Int) ->
    vision
    /ocr.OcrConnectedComponentsResult raise
    core
    /types.LoadError

    二值图像连通域标记(4邻域或8邻域) 使用两遍扫描算法

    conv2d

    fn conv2d(input : Array[Double], in_h : Int, in_w : Int, in_c : Int, kernel : Array[Double], out_c : Int, k_size : Int, stride : Int, padding : Int) -> Array[Double] raise
    core
    /types.LoadError

    2D 卷积操作(简化版)

    correct_common_patterns

    fn correct_common_patterns(text : String) ->
    vision
    /ocr.CorrectionResult

    基于常见错误模式的纠错

    correct_similar_chars

    fn correct_similar_chars(text : String, context_type : String) ->
    vision
    /ocr.CorrectionResult raise
    core
    /types.LoadError

    基于相似字符的单字符纠错

    correct_slant

    fn correct_slant(img :
    core
    /types.Image, max_slant? : Double) ->
    core
    /types.Image raise
    core
    /types.LoadError

    倾斜校正(手写体专用)

    cosine_distance

    fn cosine_distance(a : Array[Double], b : Array[Double]) -> Double raise
    core
    /types.LoadError

    计算余弦相似度(返回距离 = 1 - 相似度)

    cosine_similarity

    fn cosine_similarity(feat1 : Array[Double], feat2 : Array[Double]) -> Double

    计算特征余弦相似度

    create_batch_tasks

    fn create_batch_tasks(input_files : Array[String], output_directory : String, output_format : String) -> Array[
    vision
    /ocr.BatchTask] raise
    core
    /types.LoadError

    创建批处理任务列表

    create_data_loader

    fn create_data_loader(samples : Array[
    vision
    /ocr.DLTrainingSample], batch_size : Int, shuffle : Bool) ->
    vision
    /ocr.DataLoader raise
    core
    /types.LoadError

    创建数据加载器

    create_default_api_server_config

    fn create_default_api_server_config() ->
    vision
    /ocr.ApiServerConfig

    创建默认 API Server 配置

    create_default_batch_config

    fn create_default_batch_config() ->
    vision
    /ocr.BatchOcrConfig

    创建默认批处理配置

    create_default_char_cnn_config

    fn create_default_char_cnn_config(num_classes : Int) ->
    vision
    /ocr.DLCnnModelConfig

    创建默认 CNN 模型配置(用于字符识别)

    create_default_chinese_dictionary

    fn create_default_chinese_dictionary() ->
    vision
    /ocr.DictChineseDict

    创建默认中文字库(高频 20 字 + 可扩展)

    create_default_cli_config

    fn create_default_cli_config() ->
    vision
    /ocr.CliConfig

    创建默认 CLI 配置

    create_default_docker_config

    fn create_default_docker_config() ->
    vision
    /ocr.DockerConfig

    创建默认 Docker 配置

    create_default_handwriting_config

    fn create_default_handwriting_config() ->
    vision
    /ocr.HandwritingRecognitionConfig

    创建默认手写识别配置

    create_default_language_model

    fn create_default_language_model() ->
    vision
    /ocr.LanguageModelState

    创建默认语言模型

    create_default_model_package_config

    fn create_default_model_package_config() ->
    vision
    /ocr.ModelPackageConfig

    创建默认模型打包配置

    create_default_training_config

    fn create_default_training_config() ->
    vision
    /ocr.TrainingConfig

    创建默认训练配置

    create_exif_segment

    fn create_exif_segment(info :
    codec
    /meta.ExifInfo) -> Bytes

    构造 EXIF APP1 segment 数据(不含 FF E1 前缀和长度)。 返回 "Exif\0\0" + TIFF 头(大端) + IFD0 + 数据区

    create_feature_extractor

    fn create_feature_extractor(model_name : String, feature_dim : Int) ->
    vision
    /ocr.DLFeatureExtractor

    创建特征提取器

    create_handwriting_template

    fn create_handwriting_template(char : String, style :
    vision
    /ocr.HandwritingStyle, samples : Array[
    core
    /types.Image]) ->
    vision
    /ocr.HandwritingTemplate raise
    core
    /types.LoadError

    创建手写字体模板

    create_iptc_segment

    fn create_iptc_segment(info :
    codec
    /meta.IptcInfo) -> Bytes

    构造 IPTC APP13 段数据(不含 FF ED 前缀和长度)

    create_neural_layer

    fn create_neural_layer(layer_type :
    vision
    /ocr.DLLayerType, name : String, input_shape : Array[Int]) ->
    vision
    /ocr.DLNeuralLayer

    创建神经网络层

    create_training_history

    fn create_training_history(epoch : Int, train_loss : Double, train_accuracy : Double, val_loss : Double, val_accuracy : Double, learning_rate : Double, time_ms : Double) ->
    vision
    /ocr.DLTrainingHistory

    训练历史记录

    create_training_sample

    fn create_training_sample(img :
    core
    /types.Image, label : Int, label_text : String) ->
    vision
    /ocr.DLTrainingSample raise
    core
    /types.LoadError

    创建训练样本

    create_training_state

    fn create_training_state() ->
    vision
    /ocr.TrainingState

    创建训练状态

    create_xmp_segment

    fn create_xmp_segment(info :
    codec
    /meta.XmpInfo) -> Bytes

    构造 XMP APP1 段数据(不含 FF E1 前缀和长度)

    cross_entropy_loss

    fn cross_entropy_loss(predicted : Array[Double], target : Int) -> Double

    计算交叉熵损失

    dataset_add_sample

    fn dataset_add_sample(dataset :
    vision
    /ocr.TrainingDataset, features : Array[Double], label : String) ->
    vision
    /ocr.TrainingDataset

    添加样本到数据集

    dataset_create

    fn dataset_create() ->
    vision
    /ocr.TrainingDataset

    创建空训练数据集

    dataset_stats

    fn dataset_stats(dataset :
    vision
    /ocr.TrainingDataset) -> (Int, Int, Array[(String, Int)])

    数据集统计信息

    decode_barcode

    fn decode_barcode(img :
    core
    /types.Image, config? :
    codec
    /barcode.BarcodeConfig) -> Array[
    codec
    /barcode.BarcodeResult] raise
    core
    /types.LoadError

    通用条形码识别(自动尝试所有启用的类型)

    decode_code128

    fn decode_code128(img :
    core
    /types.Image) ->
    codec
    /barcode.BarcodeResult? raise
    core
    /types.LoadError

    识别 Code128 条形码

    decode_code39

    fn decode_code39(img :
    core
    /types.Image) ->
    codec
    /barcode.BarcodeResult? raise
    core
    /types.LoadError

    识别 Code39 条形码

    decode_ean13

    fn decode_ean13(img :
    core
    /types.Image, config? :
    codec
    /barcode.BarcodeConfig) ->
    codec
    /barcode.BarcodeResult? raise
    core
    /types.LoadError

    识别 EAN-13 条形码

    decode_linear_barcode

    fn decode_linear_barcode(img :
    core
    /types.Image) -> Array[
    codec
    /barcode.BarcodeResult] raise
    core
    /types.LoadError

    通用一维码识别(自动尝试所有类型)

    decode_qrcode

    fn decode_qrcode(img :
    core
    /types.Image, config? :
    codec
    /barcode.BarcodeConfig) ->
    codec
    /barcode.BarcodeResult? raise
    core
    /types.LoadError

    识别 QR Code(基础版:检测定位图案并估算版本)

    decode_qrcode_full

    fn decode_qrcode_full(img :
    core
    /types.Image) ->
    codec
    /barcode.QrDecodeResult? raise
    core
    /types.LoadError

    解码 QR Code(完整版本)

    decode_upca

    fn decode_upca(img :
    core
    /types.Image) ->
    codec
    /barcode.BarcodeResult? raise
    core
    /types.LoadError

    识别 UPC-A 条形码

    decompose_chinese_char

    fn decompose_chinese_char(char : String) ->
    vision
    /ocr.ChineseCharStructure raise
    core
    /types.LoadError

    汉字部件分解(简化版)

    dense_backward

    fn dense_backward(grad_output : Array[Double], weights : Array[Double], in_features : Int, out_features : Int) -> (Array[Double], Array[Double], Array[Double])

    全连接层反向传播

    dense_forward

    fn dense_forward(input : Array[Double], weights : Array[Double], biases : Array[Double], in_features : Int, out_features : Int, activation : String) -> Array[Double]

    全连接层前向传播

    deskew

    fn deskew(img :
    core
    /types.Image) ->
    core
    /types.Image raise
    core
    /types.LoadError

    倾斜校正(自动检测倾斜角度并旋转)

    detect_char_language

    fn detect_char_language(char_img :
    core
    /types.Image) ->
    vision
    /ocr.LanguageType raise
    core
    /types.LoadError

    检测字符语言类型(基于宽高比和尺寸)

    detect_column_boundaries

    fn detect_column_boundaries(text_lines : Array[
    vision
    /ocr.TextLineAttributes], page_width : Int, layout_type :
    vision
    /ocr.LayoutType) -> Array[Int]

    检测列边界

    detect_columns

    fn detect_columns(img :
    core
    /types.Image) -> (Int, Array[(Int, Int)]) raise
    core
    /types.LoadError

    检测多栏布局 返回栏数和每栏的 x 范围

    detect_distortions

    fn detect_distortions(img :
    core
    /types.Image) -> Array[
    vision
    /ocr.DistortionDetectionResult] raise
    core
    /types.LoadError

    检测畸变类型和严重程度

    detect_document_columns

    fn detect_document_columns(img :
    core
    /types.Image) -> Int raise
    core
    /types.LoadError

    检测多栏布局并返回栏数

    detect_document_language

    fn detect_document_language(img :
    core
    /types.Image) ->
    vision
    /ocr.LanguageType raise
    core
    /types.LoadError

    检测文档主要语言

    detect_handwriting_slant

    fn detect_handwriting_slant(img :
    core
    /types.Image) -> Double raise
    core
    /types.LoadError

    检测手写体倾斜角度
    fn detect_header_footer(text_lines : Array[
    vision
    /ocr.TextLineAttributes], page_height : Int) -> (Int, Int) raise
    core
    /types.LoadError

    检测页眉页脚区域

    detect_horizontal_lines

    fn detect_horizontal_lines(img :
    core
    /types.Image, min_length? : Int, max_gap? : Int) -> Array[
    vision
    /ocr.TableLine] raise
    core
    /types.LoadError

    检测水平表格线

    detect_horizontal_table_lines

    fn detect_horizontal_table_lines(binary_img :
    core
    /types.Image, min_length? : Int, max_gap? : Int) -> Array[(Int, Int, Int)] raise
    core
    /types.LoadError

    检测水平表格线(基于形态学操作的简化版)

    detect_image_regions_markdown

    fn detect_image_regions_markdown(binary_img :
    core
    /types.Image, min_area? : Int) -> Array[
    vision
    /ocr.MarkdownImage] raise
    core
    /types.LoadError

    检测图片区域(基于连通域分析的简化版)

    detect_language_enhanced

    fn detect_language_enhanced(char_img :
    core
    /types.Image) ->
    vision
    /ocr.LanguageDetectionResult raise
    core
    /types.LoadError

    增强语言检测(基于多特征的分类器)

    detect_layout_type

    fn detect_layout_type(text_lines : Array[
    vision
    /ocr.TextLineAttributes], page_width : Int, page_height : Int) ->
    vision
    /ocr.LayoutType raise
    core
    /types.LoadError

    检测页面布局类型(单栏/双栏/多栏)

    detect_list_item

    fn detect_list_item(line :
    vision
    /ocr.TextLineAttributes) ->
    vision
    /ocr.ListItemInfo

    检测列表项

    detect_paragraphs

    fn detect_paragraphs(blocks : Array[
    vision
    /ocr.DocumentBlock], max_line_spacing_ratio? : Double) -> Array[Array[Int]]

    段落检测(基于行间距和缩进)

    detect_qr_finder_patterns

    fn detect_qr_finder_patterns(img :
    core
    /types.Image) -> Array[
    codec
    /barcode.QrFinderPattern] raise
    core
    /types.LoadError

    检测 QR Code 定位图案

    detect_skew_angle

    fn detect_skew_angle(img :
    core
    /types.Image) -> Double raise
    core
    /types.LoadError

    检测图像倾斜角度(基于水平投影的方差最大化) 返回角度(度),正值表示顺时针倾斜

    detect_skew_angle_robust

    fn detect_skew_angle_robust(binary_img :
    core
    /types.Image) -> Double raise
    core
    /types.LoadError

    检测倾斜角度(基于霍夫变换的简化版)

    detect_table_enhanced

    fn detect_table_enhanced(binary_img :
    core
    /types.Image, min_table_size? : Int) -> Array[
    vision
    /ocr.EnhancedTableResult] raise
    core
    /types.LoadError

    完整表格检测

    detect_text_lines_projection

    fn detect_text_lines_projection(img :
    core
    /types.Image, min_height? : Int, max_gap? : Int) -> Array[
    vision
    /ocr.TextLineInfo] raise
    core
    /types.LoadError

    检测文本行(基于水平投影)

    detect_text_regions

    fn detect_text_regions(img :
    core
    /types.Image) -> Array[
    vision
    /ocr.TextRegion] raise
    core
    /types.LoadError

    检测文本区域(基于投影分析) 返回文本区域列表

    detect_titles

    fn detect_titles(blocks : Array[
    vision
    /ocr.DocumentBlock], title_font_size_threshold? : Int) -> Array[Int]

    标题检测(基于字体大小、位置、加粗特征)

    detect_touching_chars

    fn detect_touching_chars(img :
    core
    /types.Image, min_char_width? : Int, max_char_width? : Int) -> Array[Int] raise
    core
    /types.LoadError

    检测粘连字符(基于垂直投影的局部最小值分析) 返回粘连位置列表

    detect_vertical_lines

    fn detect_vertical_lines(img :
    core
    /types.Image, min_length? : Int, max_gap? : Int) -> Array[
    vision
    /ocr.TableLine] raise
    core
    /types.LoadError

    检测垂直表格线

    detect_vertical_table_lines

    fn detect_vertical_table_lines(binary_img :
    core
    /types.Image, min_length? : Int, max_gap? : Int) -> Array[(Int, Int, Int)] raise
    core
    /types.LoadError

    检测垂直表格线

    determine_reading_order_markdown

    fn determine_reading_order_markdown(elements : Array[
    vision
    /ocr.MarkdownElement]) -> Array[Int]

    确定阅读顺序

    dictionary_create

    fn dictionary_create(words : Array[String]) ->
    vision
    /ocr.Dictionary raise
    core
    /types.LoadError

    创建词典

    dictionary_create_common_english

    fn dictionary_create_common_english() ->
    vision
    /ocr.Dictionary

    创建常用英文单词词典

    dictionary_match

    fn dictionary_match(word : String, dictionary :
    vision
    /ocr.Dictionary, max_distance? : Int) -> Array[(String, Int)] raise
    core
    /types.LoadError

    词典匹配:查找最相似的单词

    digit_ocr_default_config

    fn digit_ocr_default_config() ->
    vision
    /ocr.DigitOcrConfig

    创建默认数字 OCR 配置

    document_enhance

    fn document_enhance(img :
    core
    /types.Image) ->
    core
    /types.Image raise
    core
    /types.LoadError

    文档图像增强(去噪+对比度+锐化) 适用于扫描文档和照片文档的预处理

    document_statistics_enhanced

    fn document_statistics_enhanced(blocks : Array[
    vision
    /ocr.DocumentBlock]) -> (Int, Int, Int, Int, Int, Int, Int)

    文档统计信息(增强版)

    document_structure_stats

    fn document_structure_stats(structure :
    vision
    /ocr.DocumentStructure) -> (Int, Int, Int, Int, Int)

    文档结构统计

    document_understanding_enhanced_default_config

    fn document_understanding_enhanced_default_config() ->
    vision
    /ocr.DocumentUnderstandingEnhancedConfig

    创建默认增强文档理解配置

    drop_fall_segmentation

    fn drop_fall_segmentation(img :
    core
    /types.Image, start_x? : Int) ->
    vision
    /ocr.DropFallResult raise
    core
    /types.LoadError

    滴水算法(Drop Fall Algorithm) 用于分割粘连字符,模拟水滴从顶部落下的路径

    edit_distance

    fn edit_distance(s1 : String, s2 : String) -> Int raise
    core
    /types.LoadError

    计算编辑距离(Levenshtein距离)

    elastic_match

    fn elastic_match(features : Array[Double], template : Array[Double], elasticity? : Double, grid_size? : Int) -> Double

    弹性匹配(允许形状变形的模板匹配)

    english_ocr_default_config

    fn english_ocr_default_config() ->
    vision
    /ocr.EnglishOcrConfig

    创建默认英文 OCR 配置

    enhanced_chinese_ocr_default_config

    fn enhanced_chinese_ocr_default_config() ->
    vision
    /ocr.EnhancedChineseOcrConfig

    创建默认增强中文 OCR 配置

    enhanced_document_to_markdown

    fn enhanced_document_to_markdown(doc :
    vision
    /ocr.EnhancedDocument, include_header_footer? : Bool) -> String

    增强版文档转 Markdown

    enhanced_element_distribution

    fn enhanced_element_distribution(doc :
    vision
    /ocr.EnhancedDocument) -> Array[(String, Int)]

    统计增强版文档元素分布

    enhanced_table_to_markdown

    fn enhanced_table_to_markdown(table :
    vision
    /ocr.EnhancedTableResult) -> String

    表格转 Markdown(增强版,支持单元格内容)

    ensemble_default_config

    fn ensemble_default_config() ->
    vision
    /ocr.EnsembleConfig

    创建默认集成配置

    ensemble_predict

    fn ensemble_predict(features : Array[Double], knn_classifier :
    vision
    /ocr.KnnClassifier, templates : Array[(String, Array[Double])], config? :
    vision
    /ocr.EnsembleConfig) ->
    vision
    /ocr.ClassificationResult raise
    core
    /types.LoadError

    集成分类器预测(多分类器投票)

    estimate_memory_usage

    fn estimate_memory_usage(image_count : Int, image_width : Int, image_height : Int, channels : Int) ->
    vision
    /ocr.MemoryUsageStats

    估算内存使用(简化版)

    euclidean_distance

    fn euclidean_distance(a : Array[Double], b : Array[Double]) -> Double raise
    core
    /types.LoadError

    计算欧氏距离

    evaluate_cnn_model

    fn evaluate_cnn_model(test_samples : Array[
    vision
    /ocr.DLTrainingSample], config :
    vision
    /ocr.DLCnnModelConfig, labels : Array[String]) -> (Double, Double) raise
    core
    /types.LoadError

    评估 CNN 模型准确率和平均置信度

    evaluate_scan_quality

    fn evaluate_scan_quality(img :
    core
    /types.Image) ->
    vision
    /ocr.ScanQuality raise
    core
    /types.LoadError

    评估扫描图像质量

    extract_all_cells

    fn extract_all_cells(img :
    core
    /types.Image, structure :
    vision
    /ocr.TableStructure, padding? : Int) -> Array[
    core
    /types.Image] raise
    core
    /types.LoadError

    提取所有单元格图像

    extract_cell_image

    fn extract_cell_image(img :
    core
    /types.Image, cell :
    vision
    /ocr.TableCell, padding? : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    提取单元格图像

    extract_char_image

    fn extract_char_image(img :
    core
    /types.Image, char :
    vision
    /ocr.CharSegment, target_size? : Int, padding? : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    提取字符图像

    extract_combined_enhanced_features

    fn extract_combined_enhanced_features(char_img :
    core
    /types.Image, config :
    vision
    /ocr.OcrAccuracyEnhancedConfig) -> Array[Double] raise
    core
    /types.LoadError

    组合多种特征(网格+HOG+LBP+Zernike+Gabor+方向特征)

    extract_combined_ocr_features

    fn extract_combined_ocr_features(img :
    core
    /types.Image) -> Array[Double] raise
    core
    /types.LoadError

    组合多种特征(网格+HOG+LBP+Hu矩)

    extract_directional_features

    fn extract_directional_features(char_img :
    core
    /types.Image) -> Array[Double]

    提取方向特征(8个方向的笔画密度)

    extract_document_text

    fn extract_document_text(blocks : Array[
    vision
    /ocr.DocumentBlock], include_headers? : Bool, include_footers? : Bool) -> String

    提取文档纯文本(按阅读顺序)

    extract_features

    fn extract_features(extractor :
    vision
    /ocr.DLFeatureExtractor, img :
    core
    /types.Image) -> Array[Double]

    提取图像特征

    extract_gabor_ocr_features

    fn extract_gabor_ocr_features(char_img :
    core
    /types.Image, num_orientations? : Int, num_frequencies? : Int) -> Array[Double]

    提取 Gabor 特征(多方向多频率)

    extract_handwriting_features

    fn extract_handwriting_features(img :
    core
    /types.Image, char : String) ->
    vision
    /ocr.HandwritingCharFeature raise
    core
    /types.LoadError

    提取手写字符特征

    extract_handwriting_stroke_features

    fn extract_handwriting_stroke_features(char_img :
    core
    /types.Image) ->
    vision
    /ocr.HandwritingStrokeFeatures raise
    core
    /types.LoadError

    提取手写体笔画特征

    extract_headings

    fn extract_headings(structure :
    vision
    /ocr.DocumentStructure) -> Array[
    vision
    /ocr.DocumentElement]

    提取所有标题

    extract_hw_stroke_features

    fn extract_hw_stroke_features(img :
    core
    /types.Image) -> Array[
    vision
    /ocr.StrokeFeature]

    提取笔画特征

    extract_images_enhanced

    fn extract_images_enhanced(binary_img :
    core
    /types.Image, min_area? : Int) -> Array[
    vision
    /ocr.ExtractedImage]

    提取图片区域(增强版,支持多种图片类型判断)

    extract_paragraphs

    fn extract_paragraphs(structure :
    vision
    /ocr.DocumentStructure) -> Array[
    vision
    /ocr.DocumentElement]

    提取正文段落

    extract_stroke_features

    fn extract_stroke_features(char_img :
    core
    /types.Image) -> Array[Double] raise
    core
    /types.LoadError

    提取笔画特征(端点、交叉点、笔画数估计)

    extract_text_line_image

    fn extract_text_line_image(img :
    core
    /types.Image, line :
    vision
    /ocr.TextLineInfo, padding? : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    提取文本行图像

    extract_text_lines

    fn extract_text_lines(img :
    core
    /types.Image) -> Array[
    core
    /types.Image] raise
    core
    /types.LoadError

    提取文本行图像 返回文本行图像列表

    extract_title

    fn extract_title(structure :
    vision
    /ocr.DocumentStructure) -> String

    提取标题

    extract_zernike_moments

    fn extract_zernike_moments(char_img :
    core
    /types.Image, max_order? : Int) -> Array[Double] raise
    core
    /types.LoadError

    提取 Zernike 矩特征(旋转不变性,前6阶)

    fast_connected_components

    fn fast_connected_components(binary_img :
    core
    /types.Image) -> Array[Int] raise
    core
    /types.LoadError

    快速连通域标记(两遍扫描法优化版)

    fast_downsample_2x

    fn fast_downsample_2x(img :
    core
    /types.Image) ->
    core
    /types.Image raise
    core
    /types.LoadError

    内存优化的图像降采样(2x2 均值采样)

    fast_gaussian_blur_1d

    fn fast_gaussian_blur_1d(img :
    core
    /types.Image, kernel : Array[Double]) ->
    core
    /types.Image raise
    core
    /types.LoadError

    使用预计算核快速高斯模糊(1D 分离卷积)

    fast_threshold_lut

    fn fast_threshold_lut(img :
    core
    /types.Image, lut : Array[Int]) ->
    core
    /types.Image raise
    core
    /types.LoadError

    使用查找表快速二值化

    field_add

    fn field_add(a :
    vision
    /fieldimg.ScalarField, b :
    vision
    /fieldimg.ScalarField) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    场加法:a + b(逐元素)。两场尺寸必须一致。 场加法:a + b(逐元素)。两场须同尺寸 Field addition: a + b (element-wise). Both fields must have the same size.

    field_blend

    fn field_blend(a :
    vision
    /fieldimg.ScalarField, b :
    vision
    /fieldimg.ScalarField, alpha : Float) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    场混合:(1 - alpha) * a + alpha * b。两场尺寸必须一致,alpha 通常在 [0, 1]。 场混合:(1 - alpha) * a + alpha * b。须同尺寸 Field blend: (1 - alpha) * a + alpha * b. Same size required; alpha typically in [0, 1].

    field_clamp

    fn field_clamp(field :
    vision
    /fieldimg.ScalarField, lo : Float, hi : Float) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    阈值裁剪:将场值限制在 [lo, hi] 范围内。 将场值钳位到 [lo, hi] Clamp field values to [lo, hi].

    field_curl

    fn field_curl(field :
    vision
    /fieldimg.VectorField) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    旋度:计算 2D 矢量场(dim=2)的标量旋度,返回标量场。 curl = dv/dx - du/dy(2D 中的标量旋度)。边界使用单侧差分。 二维向量场标量旋度,返回 ScalarField Scalar curl of a 2D vector field (dim=2), returns ScalarField. 旋度 curl = dv/dx - du/dy. Boundary uses one-sided difference.

    field_divergence

    fn field_divergence(field :
    vision
    /fieldimg.VectorField) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    散度:计算 2D 矢量场(dim=2)的散度,返回标量场。 div = du/dx + dv/dy。边界使用单侧差分。 二维向量场散度,返回 ScalarField Divergence of a 2D vector field (dim=2), returns ScalarField. 散度 div = du/dx + dv/dy. Boundary uses one-sided difference.

    field_gradient

    fn field_gradient(field :
    vision
    /fieldimg.ScalarField) ->
    vision
    /fieldimg.VectorField raise
    core
    /types.LoadError

    梯度:中心差分计算标量场梯度,返回矢量场(dim=2,[gx, gy])。 边界使用单侧差分。 梯度:标量场中心差分,返回 VectorField Gradient: central difference of a scalar field, returns VectorField (dim=2, [gx, gy]). 边界使用单侧差分 Boundary uses one-sided difference.

    field_histogram

    fn field_histogram(field :
    vision
    /fieldimg.ScalarField, min_val : Float, max_val : Float, bins : Int) -> Array[Int] raise
    core
    /types.LoadError

    直方图:统计标量场值落在 [min_val, max_val) 分成 bins 个桶的计数。 直方图:统计落入 bins 桶的值 Histogram: count values falling into bins buckets over [min_val, max_val).

    field_integrate

    fn field_integrate(field :
    vision
    /fieldimg.ScalarField) -> Float

    积分:标量场全场求和(离散积分,相当于总量/面积积分)。 积分:求和所有值(离散积分 = 总和 / 面积积分) Integrate: sum all values (discrete integral = total / area integral).

    field_integrate_region

    fn field_integrate_region(field :
    vision
    /fieldimg.ScalarField, x0 : Int, y0 : Int, x1 : Int, y1 : Int) -> Float

    区域积分:对标量场在 [x0,x1)×[y0,y1) 区域求和。 区域积分 Regional integrate: sum values in the region [x0,x1)×[y0,y1).

    field_isosurface

    fn field_isosurface(field :
    vision
    /fieldimg.ScalarField, level : Float, epsilon : Float) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    等值面提取:标记 |value - level| < epsilon 的点为 1.0,否则 0.0。 在 2D 中即等值线提取,可用于分割。 等值面 Isosurface: mark points where |value - level| < epsilon as 1.0, else 0.0. 2D 下为 In 2D this is

    field_laplacian

    fn field_laplacian(field :
    vision
    /fieldimg.ScalarField) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    拉普拉斯:计算标量场拉普拉斯,返回标量场。 拉普拉斯 lap = f[x+1,y] + f[x-1,y] + f[x,y+1] + f[x,y-1] - 4f[x,y]。 边界使用钳制(复制边界值)。 标量场拉普拉斯,返回 ScalarField Laplacian of a scalar field, returns ScalarField. 拉普拉斯 lap = f[x+1,y] + f[x-1,y] + f[x,y+1] + f[x,y-1] - 4f[x,y]. 边界使用钳位(复制边缘)值 Boundary uses clamped (replicate edge) values.

    field_mask

    fn field_mask(field :
    vision
    /fieldimg.ScalarField, threshold : Float) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    掩码:按阈值生成二值掩码场(value >= threshold → 1.0,否则 0.0)。 掩膜:二值掩膜场 Mask: binary mask field (value >= threshold → 1.0, else 0.0).

    field_mul

    fn field_mul(a :
    vision
    /fieldimg.ScalarField, b :
    vision
    /fieldimg.ScalarField) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    场逐元素乘法:a * b(逐元素)。两场尺寸必须一致。 场逐元素乘法:a * b。两场须同尺寸 Field element-wise multiplication: a * b. Both fields must have the same size.

    field_mul_scalar

    fn field_mul_scalar(field :
    vision
    /fieldimg.ScalarField, scalar : Float) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    场标量乘法:field * scalar(逐元素)。 场标量乘法:field * scalar(逐元素) Field scalar multiplication: field * scalar (element-wise).

    field_sub

    fn field_sub(a :
    vision
    /fieldimg.ScalarField, b :
    vision
    /fieldimg.ScalarField) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    场减法:a - b(逐元素)。两场尺寸必须一致。 场减法:a - b(逐元素)。两场须同尺寸 Field subtraction: a - b (element-wise). Both fields must have the same size.

    filter_components_by_area

    fn filter_components_by_area(result :
    vision
    /ocr.OcrConnectedComponentsResult, min_area : Int, max_area : Int) -> Array[
    vision
    /ocr.OcrConnectedComponent] raise
    core
    /types.LoadError

    按面积筛选连通域

    filter_components_by_aspect_ratio

    fn filter_components_by_aspect_ratio(result :
    vision
    /ocr.OcrConnectedComponentsResult, min_ratio : Double, max_ratio : Double) -> Array[
    vision
    /ocr.OcrConnectedComponent] raise
    core
    /types.LoadError

    按宽高比筛选连通域

    filter_components_by_position

    fn filter_components_by_position(result :
    vision
    /ocr.OcrConnectedComponentsResult, x : Int, y : Int, width : Int, height : Int) -> Array[
    vision
    /ocr.OcrConnectedComponent] raise
    core
    /types.LoadError

    按位置筛选连通域(在指定矩形内)

    filter_noise_segments

    fn filter_noise_segments(segments : Array[(Int, Int, Int, Int)], img_width : Int, img_height : Int, min_area_ratio? : Double, max_area_ratio? : Double) -> Array[(Int, Int, Int, Int)] raise
    core
    /types.LoadError

    分割后处理:过滤噪声区域

    find_line_intersections

    fn find_line_intersections(h_lines : Array[(Int, Int, Int)], v_lines : Array[(Int, Int, Int)]) -> Array[(Int, Int)]

    检测表格线交叉点

    find_similar_chinese_chars

    fn find_similar_chinese_chars(dict :
    vision
    /ocr.DictChineseDict, target_char : String, top_n? : Int) -> Array[
    vision
    /ocr.DictCharMatch] raise
    core
    /types.LoadError

    查找最相似的汉字(用于 OCR 纠错)

    full_postprocess_correction

    fn full_postprocess_correction(text : String, context_type? : String) ->
    vision
    /ocr.CorrectionResult raise
    core
    /types.LoadError

    完整的后处理纠错流水线

    generate_3500_chinese_templates

    fn generate_3500_chinese_templates(char_set? : String) -> Array[(String, Array[Double])]

    生成 3500 常用汉字模板

    generate_accuracy_report

    fn generate_accuracy_report(stats :
    vision
    /ocr.AccuracyStats, dataset_name : String) -> String

    生成准确率报告

    generate_api_config_json

    fn generate_api_config_json(config :
    vision
    /ocr.ApiServerConfig) -> String

    生成 API Server 启动配置 JSON

    generate_batch_summary

    fn generate_batch_summary(tasks : Array[
    vision
    /ocr.BatchTask], total_time_ms : Double) ->
    vision
    /ocr.BatchResultSummary raise
    core
    /types.LoadError

    生成批处理结果汇总

    generate_chinese_char_info_db

    fn generate_chinese_char_info_db() -> Array[
    vision
    /ocr.ChineseCharInfo]

    生成汉字结构信息数据库(1000常用字)

    generate_chinese_dictionary_report

    fn generate_chinese_dictionary_report(dict :
    vision
    /ocr.DictChineseDict) -> String

    生成中文字库统计报告

    generate_chinese_templates

    fn generate_chinese_templates(char_set? : String) -> Array[(String, Array[Double])]

    生成常用汉字模板(100个常用汉字)

    generate_cli_help

    fn generate_cli_help() -> String

    生成 CLI 帮助文本

    generate_correction_report

    fn generate_correction_report(results : Array[
    vision
    /ocr.CorrectionResult]) -> String

    生成纠错报告

    generate_deployment_package

    fn generate_deployment_package(docker_config :
    vision
    /ocr.DockerConfig, api_config :
    vision
    /ocr.ApiServerConfig, model_config :
    vision
    /ocr.ModelPackageConfig) -> String

    生成完整部署包

    generate_digit_templates

    fn generate_digit_templates() -> Array[(String, Array[Double])]

    生成数字模板特征(0-9) 使用简单的合成模板

    generate_docker_compose

    fn generate_docker_compose(config :
    vision
    /ocr.DockerConfig) -> String

    生成 docker-compose.yml 内容

    generate_dockerfile

    fn generate_dockerfile(config :
    vision
    /ocr.DockerConfig) -> String

    生成 Dockerfile 内容

    generate_english_templates

    fn generate_english_templates(case_sensitive? : Bool) -> Array[(String, Array[Double])]

    生成英文字符模板(0-9, A-Z) 不区分大小写时只生成大写

    generate_enhanced_chinese_templates

    fn generate_enhanced_chinese_templates(char_set_size? : Int) -> Array[(String, Array[Double])]

    生成优化的汉字模板(1000常用字,改进的哈希算法)

    generate_enhanced_handwriting_templates

    fn generate_enhanced_handwriting_templates(char_set? : String, num_variants? : Int) -> Array[(String, Array[Double])]

    生成增强手写体模板(每字符5种变体)

    generate_env_config

    fn generate_env_config(env :
    vision
    /ocr.DeploymentEnvironment) -> String

    生成环境配置

    generate_handwriting_templates

    fn generate_handwriting_templates(char_set? : String) -> Array[(String, Array[Double])]

    生成手写体数字模板(更灵活的形状)

    generate_health_check_config

    fn generate_health_check_config(config :
    vision
    /ocr.ApiServerConfig) -> String

    生成健康检查端点配置

    generate_image_extraction_report

    fn generate_image_extraction_report(images : Array[
    vision
    /ocr.ExtractedImage]) -> String

    生成图片提取报告

    generate_markdown_image_placeholder

    fn generate_markdown_image_placeholder(image :
    vision
    /ocr.MarkdownImage, index : Int) -> String

    生成 Markdown 图片占位符

    generate_model_manifest

    fn generate_model_manifest(config :
    vision
    /ocr.ModelPackageConfig) -> String

    生成模型打包清单

    generate_performance_report

    fn generate_performance_report(benchmark :
    vision
    /ocr.PerformanceBenchmark, dataset_name : String) -> String

    生成性能基准报告

    generate_punctuation_templates

    fn generate_punctuation_templates() -> Array[
    vision
    /ocr.PunctuationTemplate]

    生成标点符号模板

    generate_robustness_report

    fn generate_robustness_report(quality :
    vision
    /ocr.ScanQuality, distortions : Array[
    vision
    /ocr.DistortionDetectionResult], layout :
    vision
    /ocr.ComplexLayoutAnalysis) ->
    vision
    /ocr.RobustnessReport

    生成鲁棒性评估报告

    generate_training_progress_report

    fn generate_training_progress_report(state :
    vision
    /ocr.TrainingState, config :
    vision
    /ocr.TrainingConfig) -> String

    生成训练进度报告

    generate_training_report

    fn generate_training_report(history : Array[
    vision
    /ocr.DLTrainingHistory], config :
    vision
    /ocr.DLCnnModelConfig) -> String

    生成训练报告

    get_elements_in_reading_order

    fn get_elements_in_reading_order(structure :
    vision
    /ocr.DocumentStructure) -> Array[
    vision
    /ocr.DocumentElement]

    按阅读顺序获取元素

    grid_features

    fn grid_features(img :
    core
    /types.Image, grid_rows? : Int, grid_cols? : Int) ->
    vision
    /ocr.GridFeatures raise
    core
    /types.LoadError

    计算网格特征(将图像分成网格,每个格子计算像素密度)

    handwriting_feature_similarity

    fn handwriting_feature_similarity(feat1 :
    vision
    /ocr.HandwritingCharFeature, feat2 :
    vision
    /ocr.HandwritingCharFeature) -> Double

    计算手写特征相似度

    handwriting_ocr_default_config

    fn handwriting_ocr_default_config() ->
    vision
    /ocr.HandwritingOcrConfig

    创建默认手写体识别配置

    handwriting_ocr_enhanced_default_config

    fn handwriting_ocr_enhanced_default_config() ->
    vision
    /ocr.HandwritingOcrEnhancedConfig

    创建默认增强手写体识别配置

    handwriting_postprocess

    fn handwriting_postprocess(text : String, confidence : Double) -> (String, Double)

    手写体后处理(基于常见手写体混淆的纠错)

    handwriting_report_to_string

    fn handwriting_report_to_string(result :
    vision
    /ocr.HandwritingRecognitionResult) -> String

    生成手写识别报告

    hog_features

    fn hog_features(img :
    core
    /types.Image, cell_size? : Int, num_bins? : Int) ->
    vision
    /ocr.HogFeatures raise
    core
    /types.LoadError

    计算 HOG 特征(方向梯度直方图)

    horizontal_projection

    fn horizontal_projection(img :
    core
    /types.Image) ->
    vision
    /ocr.ProjectionResult raise
    core
    /types.LoadError

    水平投影(按行统计前景像素数)

    hu_moments_features

    fn hu_moments_features(img :
    core
    /types.Image) -> Array[Double] raise
    core
    /types.LoadError

    Hu 矩特征(7个不变矩)

    image16_to_scalar_field

    fn image16_to_scalar_field(img :
    core
    /types.Image16) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    Image16 转标量场:16-bit 图转标量场,归一化到 [0, 1](除以 65535)。 Image16 转 ScalarField;归一化到 [0, 1](除以 65535) Convert Image16 to ScalarField; normalized to [0, 1] (divided by 65535).

    image_to_scalar_field

    fn image_to_scalar_field(img :
    core
    /types.Image) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    Image 转标量场:将灰度图(channels=1)转为标量场,像素值归一化到 [0, 1]。 若 channels > 1,先转灰度(加权平均:0.299R + 0.587G + 0.114B)。 Image 转 ScalarField;灰度归一化到 [0, 1] Convert Image to ScalarField; grayscale (channels=1) normalized to [0, 1]. channels > 1 时 For channels > 1

    image_to_vector_field

    fn image_to_vector_field(img :
    core
    /types.Image) ->
    vision
    /fieldimg.VectorField raise
    core
    /types.LoadError

    Image 转矢量场:将 RGB/RGBA 图转为矢量场(dim=channels),像素值归一化到 [0, 1]。 Image 转 VectorField;像素值归一化到 [0, 1] Convert Image to VectorField (dim=channels); pixel values normalized to [0, 1].

    imagef_to_scalar_field

    fn imagef_to_scalar_field(img :
    core
    /types.ImageF) ->
    vision
    /fieldimg.ScalarField raise
    core
    /types.LoadError

    ImageF 转标量场:HDR float 图转标量场,取第一通道,钳制到 [0, 1]。 ImageF 转 ScalarField;取首通道,钳位到 [0, 1] Convert ImageF to ScalarField; takes first channel, clamped to [0, 1].

    is_code_block_line

    fn is_code_block_line(line :
    vision
    /ocr.TextLineAttributes, avg_indent : Int) -> Bool

    判断是否为代码块(基于缩进和等宽字体特征)

    is_heading_line

    fn is_heading_line(line :
    vision
    /ocr.TextLineAttributes, avg_font_size : Double) -> (Bool, Int)

    判断文本行是否为标题

    is_quote_line

    fn is_quote_line(line :
    vision
    /ocr.TextLineAttributes, avg_x : Int) -> Bool

    判断是否为引用块(基于左边距和竖线)

    knn_add_sample

    fn knn_add_sample(classifier :
    vision
    /ocr.KnnClassifier, features : Array[Double], label : String) ->
    vision
    /ocr.KnnClassifier raise
    core
    /types.LoadError

    添加训练样本

    knn_add_samples

    fn knn_add_samples(classifier :
    vision
    /ocr.KnnClassifier, samples : Array[(Array[Double], String)]) ->
    vision
    /ocr.KnnClassifier raise
    core
    /types.LoadError

    批量添加训练样本

    knn_create

    fn knn_create(k? : Int, distance_metric? : String) ->
    vision
    /ocr.KnnClassifier raise
    core
    /types.LoadError

    创建 KNN 分类器

    knn_predict

    fn knn_predict(classifier :
    vision
    /ocr.KnnClassifier, features : Array[Double]) ->
    vision
    /ocr.ClassificationResult raise
    core
    /types.LoadError

    KNN 预测

    language_model_postprocess

    fn language_model_postprocess(text : String, char_languages : Array[String], confidences : Array[Double]) -> (String, Array[Double])

    语言模型后处理(基于N-gram的混排纠错)

    lbp_features

    fn lbp_features(img :
    core
    /types.Image, radius? : Int, num_points? : Int, num_bins? : Int) ->
    vision
    /ocr.LbpFeatures raise
    core
    /types.LoadError

    计算 LBP 特征(局部二值模式)

    load_model

    fn load_model(path : String) ->
    vision
    /ocr.DLCnnModelConfig?

    模型加载

    lookup_by_pinyin

    fn lookup_by_pinyin(dict :
    vision
    /ocr.DictChineseDict, pinyin : String) -> Array[
    vision
    /ocr.DictCharEntry] raise
    core
    /types.LoadError

    根据拼音查找汉字

    lookup_by_radical

    fn lookup_by_radical(dict :
    vision
    /ocr.DictChineseDict, radical : String) -> Array[
    vision
    /ocr.DictCharEntry] raise
    core
    /types.LoadError

    根据部首查找汉字

    lookup_by_structure

    fn lookup_by_structure(dict :
    vision
    /ocr.DictChineseDict, structure :
    vision
    /ocr.DictCharStructure) -> Array[
    vision
    /ocr.DictCharEntry]

    根据结构类型查找汉字

    lookup_char

    fn lookup_char(dict :
    vision
    /ocr.DictChineseDict, char : String) ->
    vision
    /ocr.DictCharEntry? raise
    core
    /types.LoadError

    查找汉字条目

    manhattan_distance

    fn manhattan_distance(a : Array[Double], b : Array[Double]) -> Double raise
    core
    /types.LoadError

    计算曼哈顿距离

    mark_task_completed

    fn mark_task_completed(task :
    vision
    /ocr.BatchTask, char_count : Int, accuracy : Double, end_time : Double) ->
    vision
    /ocr.BatchTask

    标记任务完成

    mark_task_failed

    fn mark_task_failed(task :
    vision
    /ocr.BatchTask, error_message : String, end_time : Double) ->
    vision
    /ocr.BatchTask

    标记任务失败

    markdown_document_to_string

    fn markdown_document_to_string(doc :
    vision
    /ocr.MarkdownDocument) -> String

    完整文档转 Markdown(1:1 还原)

    markdown_table_to_string

    fn markdown_table_to_string(table :
    vision
    /ocr.MarkdownTable) -> String

    表格数据转 Markdown

    max_pool2d

    fn max_pool2d(input : Array[Double], in_h : Int, in_w : Int, channels : Int, pool_size : Int) -> Array[Double] raise
    core
    /types.LoadError

    2D 最大池化

    max_pool2d_backward

    fn max_pool2d_backward(grad_output : Array[Double], input : Array[Double], in_h : Int, in_w : Int, in_c : Int, pool_size : Int) -> Array[Double]

    MaxPool2D 反向传播:梯度透传到最大值位置

    merge_adjacent_components

    fn merge_adjacent_components(components : Array[
    vision
    /ocr.OcrConnectedComponent], max_gap : Int) -> Array[
    vision
    /ocr.OcrConnectedComponent] raise
    core
    /types.LoadError

    合并相邻连通域(用于字符合并)

    merge_small_segments

    fn merge_small_segments(segments : Array[(Int, Int, Int, Int)], min_width : Int, min_height : Int) -> Array[(Int, Int, Int, Int)] raise
    core
    /types.LoadError

    分割后处理:合并过小的分割区域

    multi_scale_recognize

    fn multi_scale_recognize(char_img :
    core
    /types.Image, templates : Array[(String, Array[Double])], scales : Array[Int], distance_metric? : String) -> (String, Double)

    多尺度识别融合(不同尺寸下的识别结果加权融合)

    multilingual_ocr_default_config

    fn multilingual_ocr_default_config() ->
    vision
    /ocr.MultilingualOcrConfig

    创建默认多语言识别配置

    multilingual_ocr_enhanced_default_config

    fn multilingual_ocr_enhanced_default_config() ->
    vision
    /ocr.MultilingualOcrEnhancedConfig

    创建默认增强多语言识别配置

    next_batch

    fn next_batch(loader :
    vision
    /ocr.DataLoader) -> (Array[
    vision
    /ocr.DLTrainingSample],
    vision
    /ocr.DataLoader) raise
    core
    /types.LoadError

    获取下一批数据

    ngram_create

    fn ngram_create(texts : Array[String], n? : Int) ->
    vision
    /ocr.NgramModel raise
    core
    /types.LoadError

    创建 N-gram 模型(从文本训练)

    ngram_score

    fn ngram_score(text : String, model :
    vision
    /ocr.NgramModel) -> Double raise
    core
    /types.LoadError

    计算文本的 N-gram 概率(简化版)

    niblack_threshold

    fn niblack_threshold(img :
    core
    /types.Image, window_size? : Int, k? : Double) ->
    core
    /types.Image raise
    core
    /types.LoadError

    Niblack 局部阈值二值化 自适应阈值 T(x,y) = mean(x,y) + k * std(x,y) k: 修正系数,通常 -0.2 window_size: 局部窗口大小(奇数)

    normalize_features

    fn normalize_features(features : Array[Double]) -> Array[Double] raise
    core
    /types.LoadError

    特征归一化(Min-Max 归一化到 [0, 1])

    normalize_handwriting_size

    fn normalize_handwriting_size(img :
    core
    /types.Image, target_size : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    手写字符大小归一化(简化版,返回尺寸信息)

    normalize_image

    fn normalize_image(image_data : Array[Double], mean : Double, std : Double) -> Array[Double] raise
    core
    /types.LoadError

    图像归一化

    normalize_punctuation

    fn normalize_punctuation(text : String, char_languages : Array[String]) -> String

    标点符号规范化(中英文标点自动转换)

    ocr_accuracy_enhanced_default_config

    fn ocr_accuracy_enhanced_default_config() ->
    vision
    /ocr.OcrAccuracyEnhancedConfig

    创建默认准确率提升配置

    ocr_pipeline_stats

    fn ocr_pipeline_stats(img :
    core
    /types.Image) -> (Int, Int, Double) raise
    core
    /types.LoadError

    OCR 流水线性能统计

    ocr_postprocess

    fn ocr_postprocess(result :
    vision
    /ocr.OcrResult, config? :
    vision
    /ocr.PostProcessConfig, dictionary? :
    vision
    /ocr.Dictionary, ngram_model? :
    vision
    /ocr.NgramModel) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    完整后处理流水线

    ocr_preprocess

    fn ocr_preprocess(img :
    core
    /types.Image, binarization_method? : String) ->
    core
    /types.Image raise
    core
    /types.LoadError

    OCR 完整预处理流水线 灰度化 -> 去噪 -> 倾斜校正 -> 二值化 -> 输出

    ocr_result_to_hocr

    fn ocr_result_to_hocr(result :
    vision
    /ocr.OCRPageResult) -> String

    OCR 结果导出为 hOCR 格式(简化版)

    ocr_result_to_json

    fn ocr_result_to_json(result :
    vision
    /ocr.OCRPageResult) -> String

    OCR 结果导出为 JSON

    ocr_result_to_text

    fn ocr_result_to_text(result :
    vision
    /ocr.OCRPageResult) -> String

    OCR 结果导出为纯文本

    optimize_reading_order

    fn optimize_reading_order(blocks : Array[
    vision
    /ocr.DocumentBlock], num_columns : Int) -> Array[Int]

    优化阅读顺序(基于列和几何关系)

    otsu_threshold

    fn otsu_threshold(img :
    core
    /types.Image) ->
    core
    /types.Image raise
    core
    /types.LoadError

    Otsu 全局阈值二值化(自动计算最佳阈值)

    parse_cli_args

    fn parse_cli_args(args : Array[String]) ->
    vision
    /ocr.CliConfig raise
    core
    /types.LoadError

    解析 CLI 参数(简化版)

    postprocess_default_config

    fn postprocess_default_config() ->
    vision
    /ocr.PostProcessConfig

    创建默认后处理配置

    progress_bar_to_string

    fn progress_bar_to_string(progress : Double, width? : Int) -> String

    生成进度条字符串

    projection_features

    fn projection_features(img :
    core
    /types.Image) ->
    vision
    /ocr.ProjectionFeatures raise
    core
    /types.LoadError

    计算投影特征

    read_exif_extended_from_bytes

    fn read_exif_extended_from_bytes(data : Bytes) ->
    codec
    /meta.ExifInfoExtended?

    从 JPEG 字节流读取扩展 EXIF 元数据 返回 None 如果不含 EXIF 数据

    read_exif_from_bytes

    fn read_exif_from_bytes(data : Bytes) ->
    codec
    /meta.ExifInfo?

    从 JPEG 字节流读取 EXIF 元数据。 返回 None 如果不含 EXIF 数据。

    read_iptc_from_bytes

    fn read_iptc_from_bytes(data : Bytes) ->
    codec
    /meta.IptcInfo?

    从 JPEG 字节流读取 IPTC IIM 元数据 返回 None 如果不含 IPTC 数据

    read_png_exif_from_bytes

    fn read_png_exif_from_bytes(data : Bytes) -> Bytes?

    从 PNG eXIf chunk 读取 EXIF 数据 返回原始 EXIF 字节(以 "MM" 或 "II" TIFF 头开头),不含 "Exif\0\0" 前缀

    read_png_text_chunks

    fn read_png_text_chunks(data : Bytes) -> Array[
    codec
    /meta.PngTextChunk]

    从 PNG 字节流读取 text chunks(tEXt 和 iTXt)。 返回关键字-文本对数组。不含 EXIF 等其他元数据。

    read_xmp_from_bytes

    fn read_xmp_from_bytes(data : Bytes) ->
    codec
    /meta.XmpInfo?

    从 JPEG 字节流读取 XMP 元数据 返回 None 如果不含 XMP 数据

    recognize_by_components

    fn recognize_by_components(dict :
    vision
    /ocr.DictChineseDict, detected_structure :
    vision
    /ocr.DictCharStructure, detected_components : Array[String], stroke_count_hint? : Int) -> Array[(String, Double)]

    基于部件的汉字识别(简化版)

    recognize_chinese

    fn recognize_chinese(img :
    core
    /types.Image, config? :
    vision
    /ocr.ChineseOcrConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    中文 OCR 识别(完整流水线)

    recognize_chinese_advanced

    fn recognize_chinese_advanced(img :
    core
    /types.Image, config? :
    vision
    /ocr.AdvancedChineseOcrConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    完善中文 OCR 识别(完整流水线)

    recognize_digits

    fn recognize_digits(img :
    core
    /types.Image, config? :
    vision
    /ocr.DigitOcrConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    数字 OCR 识别(完整流水线) 预处理 → 字符分割 → 特征提取 → 模板匹配分类

    recognize_english

    fn recognize_english(img :
    core
    /types.Image, config? :
    vision
    /ocr.EnglishOcrConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    英文 OCR 识别(完整流水线)

    recognize_enhanced_chinese

    fn recognize_enhanced_chinese(img :
    core
    /types.Image, config? :
    vision
    /ocr.EnhancedChineseOcrConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    增强中文 OCR 识别(完整流水线:结构预筛选 + 模板匹配 + 笔画特征)

    recognize_handwriting_char

    fn recognize_handwriting_char(img :
    core
    /types.Image, templates : Array[
    vision
    /ocr.HandwritingTemplate], config :
    vision
    /ocr.HandwritingRecognitionConfig) ->
    vision
    /ocr.HandwritingRecognitionResult raise
    core
    /types.LoadError

    手写字符识别

    recognize_handwriting_enhanced

    fn recognize_handwriting_enhanced(img :
    core
    /types.Image, config? :
    vision
    /ocr.HandwritingOcrEnhancedConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    增强手写体识别(完整流水线)

    recognize_multilingual_enhanced

    fn recognize_multilingual_enhanced(img :
    core
    /types.Image, config? :
    vision
    /ocr.MultilingualOcrEnhancedConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    增强多语言混合识别(完整流水线)

    recognize_ocr_enhanced

    fn recognize_ocr_enhanced(img :
    core
    /types.Image, templates : Array[(String, Array[Double])], config? :
    vision
    /ocr.OcrAccuracyEnhancedConfig) ->
    vision
    /ocr.OcrResult raise
    core
    /types.LoadError

    增强 OCR 识别(完整准确率提升流水线)

    recognize_symbols_markdown

    fn recognize_symbols_markdown(text : String) -> Array[
    vision
    /ocr.MarkdownSymbol]

    识别文本中的符号

    recognize_table

    fn recognize_table(img :
    core
    /types.Image, min_line_length? : Int) ->
    vision
    /ocr.TableStructure raise
    core
    /types.LoadError

    完整表格识别流水线

    record_training_metrics

    fn record_training_metrics(state :
    vision
    /ocr.TrainingState, metrics :
    vision
    /ocr.TrainingMetrics) ->
    vision
    /ocr.TrainingState

    记录训练指标

    reed_solomon_decode

    fn reed_solomon_decode(data : Array[Int], ec_bytes : Int) -> (Array[Int], Int)

    Reed-Solomon 纠错(简化版 GF(256))

    relu

    fn relu(x : Double) -> Double

    ReLU 激活函数

    relu_backward

    fn relu_backward(grad : Array[Double], fwd : Array[Double]) -> Array[Double]

    ReLU 反向传播

    resize_image_for_cnn

    fn resize_image_for_cnn(img :
    core
    /types.Image, target_width : Int, target_height : Int) -> Array[Double] raise
    core
    /types.LoadError

    图像缩放(双线性插值简化版)

    robustness_report_to_string

    fn robustness_report_to_string(report :
    vision
    /ocr.RobustnessReport) -> String

    生成鲁棒性报告文本

    rotate_document

    fn rotate_document(img :
    core
    /types.Image, angle : Double) ->
    core
    /types.Image raise
    core
    /types.LoadError

    文档旋转(带白色背景填充) angle: 旋转角度(度),正值表示逆时针

    sauvola_threshold

    fn sauvola_threshold(img :
    core
    /types.Image, window_size? : Int, k? : Double, r? : Double) ->
    core
    /types.Image raise
    core
    /types.LoadError

    Sauvola 局部阈值二值化(Niblack 的改进版,适合文档图像) 自适应阈值 T(x,y) = mean(x,y) * (1 + k * (std(x,y)/R - 1)) k: 修正系数,通常 0.5 R: 标准差的动态范围,通常 128 window_size: 局部窗口大小(奇数)

    save_model

    fn save_model(config :
    vision
    /ocr.DLCnnModelConfig, weights : Array[Double], path : String) -> Bool

    模型保存(简化版,保存为 JSON)

    scalar_field_to_image

    fn scalar_field_to_image(field :
    vision
    /fieldimg.ScalarField) ->
    core
    /types.Image

    标量场转 Image:将标量场转为单通道灰度图,值钳制到 [0, 1] 后映射到 [0, 255]。 ScalarField 转单通道灰度 Image;值钳位到 [0,1] 再映射到 [0,255] Convert ScalarField to single-channel grayscale Image; values clamped to [0, 1] then mapped to [0, 255].

    scan_document_preprocess

    fn scan_document_preprocess(img :
    core
    /types.Image, config :
    vision
    /ocr.ScanOCRConfig) ->
    core
    /types.Image raise
    core
    /types.LoadError

    扫描文档预处理流水线

    scan_ocr_default_config

    fn scan_ocr_default_config() ->
    vision
    /ocr.ScanOCRConfig

    创建默认扫描 OCR 配置

    scan_ocr_recognize

    fn scan_ocr_recognize(img :
    core
    /types.Image, config :
    vision
    /ocr.ScanOCRConfig) ->
    vision
    /ocr.OCRPageResult raise
    core
    /types.LoadError

    扫描文档 OCR 完整流水线

    segment_by_connected_components

    fn segment_by_connected_components(img :
    core
    /types.Image, min_area? : Int, max_area? : Int) -> Array[(Int, Int, Int, Int)] raise
    core
    /types.LoadError

    基于连通域的字符分割 返回字符区域列表

    segment_chars_projection

    fn segment_chars_projection(img :
    core
    /types.Image, line :
    vision
    /ocr.TextLineInfo, min_width? : Int, max_gap? : Int) -> Array[
    vision
    /ocr.CharSegment] raise
    core
    /types.LoadError

    文本行字符分割(基于垂直投影)

    segment_connected_strokes

    fn segment_connected_strokes(img :
    core
    /types.Image, config :
    vision
    /ocr.HandwritingRecognitionConfig) ->
    vision
    /ocr.StrokeSegmentationResult

    连笔分割

    segment_cursive_chars

    fn segment_cursive_chars(img :
    core
    /types.Image, min_char_width? : Int, max_char_width? : Int) -> Array[(Int, Int, Int, Int)]

    连笔字符分割(基于笔画特征的分割点检测)

    segment_page

    fn segment_page(img :
    core
    /types.Image) -> Array[
    vision
    /ocr.TextRegion] raise
    core
    /types.LoadError

    页面分割(文本/图像/表格区域) 返回区域列表

    segment_paragraphs

    fn segment_paragraphs(lines : Array[
    vision
    /ocr.TextLineAttributes]) -> Array[Array[
    vision
    /ocr.TextLineAttributes]]

    分割段落(基于行间距和首行缩进)

    select_adaptive_config

    fn select_adaptive_config(quality :
    vision
    /ocr.ScanQuality) ->
    vision
    /ocr.AdaptivePreprocessConfig raise
    core
    /types.LoadError

    根据扫描质量自动选择预处理配置

    shadow_removal

    fn shadow_removal(img :
    core
    /types.Image, kernel_size? : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    阴影去除(基于大核高斯模糊的背景估计) 通过估计背景光照并去除,实现阴影去除

    sigmoid

    fn sigmoid(x : Double) -> Double

    Sigmoid 激活函数

    sigmoid_backward

    fn sigmoid_backward(grad : Array[Double], fwd : Array[Double]) -> Array[Double]

    Sigmoid 反向传播:sigmoid'(x) = sigmoid(x) * (1 - sigmoid(x)) = fwd * (1 - fwd)

    smart_reading_order

    fn smart_reading_order(elements : Array[
    vision
    /ocr.EnhancedDocumentElement], layout_type :
    vision
    /ocr.LayoutType, column_boundaries : Array[Int]) -> Array[Int] raise
    core
    /types.LoadError

    智能阅读顺序(支持多栏布局)

    smart_segment_chars

    fn smart_segment_chars(img :
    core
    /types.Image, config :
    vision
    /ocr.MultilingualOcrEnhancedConfig) -> Array[(Int, Int, Int, Int, String)] raise
    core
    /types.LoadError

    智能字符分割(根据语言类型选择分割策略)

    smart_spacing_process

    fn smart_spacing_process(text : String, char_languages : Array[String]) -> String

    softmax

    fn softmax(logits : Array[Double]) -> Array[Double]

    Softmax 函数

    softmax_cross_entropy_backward

    fn softmax_cross_entropy_backward(predicted : Array[Double], target : Int) -> Array[Double] raise
    core
    /types.LoadError

    Softmax + 交叉熵联合反向传播:grad = predicted - one_hot(target)

    split_train_validation

    fn split_train_validation(samples : Array[
    vision
    /ocr.DLTrainingSample], validation_split : Double, shuffle : Bool) -> (Array[
    vision
    /ocr.DLTrainingSample], Array[
    vision
    /ocr.DLTrainingSample])

    划分训练集和验证集

    standardize_features

    fn standardize_features(features : Array[Double]) -> Array[Double] raise
    core
    /types.LoadError

    特征标准化(Z-score 标准化,均值0,标准差1)

    statistical_features

    fn statistical_features(img :
    core
    /types.Image) ->
    vision
    /ocr.StatisticalFeatures raise
    core
    /types.LoadError

    计算统计特征

    structure_based_filter

    fn structure_based_filter(char_img :
    core
    /types.Image, char_db : Array[
    vision
    /ocr.ChineseCharInfo], max_candidates? : Int) -> Array[
    vision
    /ocr.ChineseCharInfo]

    基于结构信息预筛选候选字(减少匹配范围)

    template_matcher_add

    fn template_matcher_add(matcher :
    vision
    /ocr.TemplateMatcher, label : String, template : Array[Double]) ->
    vision
    /ocr.TemplateMatcher raise
    core
    /types.LoadError

    添加模板

    template_matcher_create

    fn template_matcher_create(distance_metric? : String) ->
    vision
    /ocr.TemplateMatcher

    创建模板匹配分类器

    template_matcher_predict

    fn template_matcher_predict(matcher :
    vision
    /ocr.TemplateMatcher, features : Array[Double]) ->
    vision
    /ocr.ClassificationResult raise
    core
    /types.LoadError

    模板匹配预测

    understand_document_enhanced

    fn understand_document_enhanced(img :
    core
    /types.Image, config? :
    vision
    /ocr.DocumentUnderstandingEnhancedConfig) -> (Array[
    vision
    /ocr.DocumentBlock], Array[
    vision
    /ocr.DocumentTreeNode], String) raise
    core
    /types.LoadError

    完整增强文档理解流水线

    unrolled_pixel_sum

    fn unrolled_pixel_sum(img :
    core
    /types.Image) -> Int raise
    core
    /types.LoadError

    循环展开的像素求和(每次处理4个像素)

    update_task_progress

    fn update_task_progress(task :
    vision
    /ocr.BatchTask, progress : Double, current_page : Int, total_pages : Int) ->
    vision
    /ocr.BatchTask

    更新任务进度

    update_weights_sgd

    fn update_weights_sgd(weights : Array[Double], gradients : Array[Double], learning_rate : Double) -> Array[Double] raise
    core
    /types.LoadError

    SGD 权重更新

    vector_field_to_image

    fn vector_field_to_image(field :
    vision
    /fieldimg.VectorField) ->
    core
    /types.Image

    矢量场转 Image:将矢量场转为多通道图,值钳制到 [0, 1] 后映射到 [0, 255]。 VectorField 转多通道 Image;值钳位到 [0,1] 再映射到 [0,255] Convert VectorField to multi-channel Image; values clamped to [0, 1] then mapped to [0, 255].

    vertical_projection

    fn vertical_projection(img :
    core
    /types.Image) ->
    vision
    /ocr.ProjectionResult raise
    core
    /types.LoadError

    垂直投影(按列统计前景像素数)

    weighted_knn_classify

    fn weighted_knn_classify(features : Array[Double], training_data : Array[(String, Array[Double])], k? : Int, distance_metric? : String) -> (String, Double, Array[(String, Double)])

    加权 KNN 分类(距离加权投票)

    write_exif_to_bytes

    fn write_exif_to_bytes(info :
    codec
    /meta.ExifInfo, jpeg_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 EXIF 元数据写入 JPEG 字节流。 在 SOI (FF D8) 之后插入 APP1 segment。 如果已有 APP1 EXIF segment,替换之。

    write_iptc_to_bytes

    fn write_iptc_to_bytes(info :
    codec
    /meta.IptcInfo, jpeg_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 IPTC 写入 JPEG(在 SOI 后插入 APP13,已有则替换)

    write_png_exif_to_bytes

    fn write_png_exif_to_bytes(exif_data : Bytes, png_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 EXIF 数据写入 PNG eXIf chunk(在 IDAT 前插入) exif_data 应以 "MM" 或 "II" TIFF 头开头

    write_png_text_chunks

    fn write_png_text_chunks(chunks : Array[
    codec
    /meta.PngTextChunk], png_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 text chunks 写入 PNG(在 IDAT 前插入 tEXt chunks) 已有同名 keyword 的 tEXt 不做去重,直接追加

    write_xmp_to_bytes

    fn write_xmp_to_bytes(info :
    codec
    /meta.XmpInfo, jpeg_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 XMP 写入 JPEG(在 SOI 后插入 APP1,已有则替换)

    Source Files