{"record":{"id":"2dae704043d2dd0f","repo":"babalae/better-genshin-impact","slug":"modeltype-preheatimagepath","errorCode":null,"errorMessage":"预热图片未找到: {modelType.PreHeatImagePath}","messagePattern":"预热图片未找到: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"critical","filePath":"BetterGenshinImpact/Core/Recognition/OCR/Paddle/PaddleOcrService.cs","lineNumber":257,"sourceCode":"\n                return V4;\n            }\n            else\n            {\n                return v5;\n            }\n        }\n    }\n\n    public PaddleOcrService(BgiOnnxFactory bgiOnnxFactory, PaddleOcrModelType modelType)\n    {\n        var (modelsDet, modelsRec) = modelType.Build(bgiOnnxFactory);\n        _localDetModel = modelsDet;\n        _localRecModel = modelsRec;\n\n        // 预热模型\n        using var preHeatImageMat = Bv.ImRead(modelType.PreHeatImagePath) ??\n                                    throw new FileNotFoundException($\"预热图片未找到: {modelType.PreHeatImagePath}\");\n        // Debug输出结果\n        var preHeatResult = RunAll(preHeatImageMat, 1);\n        Debug.WriteLine(\n            $\"PaddleOcrService 预热完成，使用模型: {modelType.DetectionModel.Name} 和 {modelType.RecognitionModel.Name}，结果: {preHeatResult.Text}\");\n    }\n\n    /// <summary>\n    ///     推荐传入三通道BGR mat，虽然四通道和单通道也做了兼容，但是三通道最快\n    /// </summary>\n    public string Ocr(Mat mat)\n    {\n        return OcrResult(mat).Text;\n    }\n\n    /// <summary>\n    ///     推荐传入三通道BGR mat，虽然四通道和单通道也做了兼容，但是三通道最快\n    /// </summary>\n    public OcrResult OcrResult(Mat mat)","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Recognition/OCR/Paddle/PaddleOcrService.cs#L239-L275","documentation":"The PaddleOcrService constructor warm-starts the detection and recognition pipeline by running OCR on a bundled test PNG (test_pp_ocr.png, or test_pp_ocr_number.png for the V4 English model). Bv.ImRead returns null when the image cannot be read, and the null-coalesce throws FileNotFoundException, aborting construction so OCR is entirely unavailable.","triggerScenarios":"Calling new PaddleOcrService(factory, modelType) when modelType.PreHeatImagePath (default Assets\\Model\\PaddleOCR\\test_pp_ocr.png) does not exist or is not readable as an image.","commonSituations":"Preheat asset trimmed from the build output; image renamed; Global.Absolute resolving against the wrong working directory; file locked or permission denied; corrupt PNG.","solutions":["Restore test_pp_ocr.png (and test_pp_ocr_number.png) under Assets\\Model\\PaddleOCR\\.","Verify Global.Absolute(modelType.PreHeatImagePath) returns the expected absolute path.","Build the model type with Create(..., preHeatImagePath: <valid path>) to point at an existing image.","Check the image is not locked by another process and the build copies it to the output directory."],"exampleFix":"// before: preheat image missing -> constructor throws\nnew PaddleOcrService(factory, modelType);\n\n// after: guard the preheat path\nif (!File.Exists(modelType.PreHeatImagePath))\n    throw new InvalidOperationException($\"Preheat image missing: {modelType.PreHeatImagePath}\");\nnew PaddleOcrService(factory, modelType);","handlingStrategy":"validation","validationCode":"bool IsPreheatImageAvailable(PaddleOcrModelType modelType)\n    => File.Exists(modelType.PreHeatImagePath);\n\nif (!IsPreheatImageAvailable(modelType))\n    throw new InvalidOperationException($\"PaddleOCR preheat image missing: {modelType.PreHeatImagePath}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    _ocr = new PaddleOcrService(factory, modelType);\n}\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"预热图片未找到\"))\n{\n    Logger.LogError(\"Preheat image missing: {Path}\", modelType.PreHeatImagePath);\n    throw;\n}","preventionTips":["Keep test_pp_ocr.png and test_pp_ocr_number.png under Assets\\Model\\PaddleOCR\\ and mark them as copy-to-output.","Pass an explicit preHeatImagePath when building a custom model type.","Verify Global.Absolute resolves correctly in the deployment environment before constructing the service."],"tags":["paddle-ocr","opencv","asset-missing","initialization"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}