{"record":{"id":"b4dbd79e90f31ba3","repo":"SubtitleEdit/subtitleedit","slug":"binaryocr-database-is-empty-dbpath","errorCode":null,"errorMessage":"BinaryOCR database is empty: {dbPath}","messagePattern":"BinaryOCR database is empty: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/BinaryOcrOcrEngine.cs","lineNumber":32,"sourceCode":"    public string Name => \"binaryocr\";\n\n    private readonly BinaryOcrDb _db;\n    private readonly BinaryOcrMatcher _matcher;\n    private const int PixelsAreSpaceDefault = 12;\n    private const double MaxErrorPercent = 0.5;\n\n    public BinaryOcrOcrEngine(string dbPath)\n    {\n        if (!File.Exists(dbPath))\n        {\n            throw new FileNotFoundException(\n                $\"BinaryOCR database not found: {dbPath}. Use --ocr-db to point to a .db file \" +\n                \"(typically %AppData%\\\\Subtitle Edit\\\\OCR\\\\Latin.db or similar).\", dbPath);\n        }\n        _db = new BinaryOcrDb(dbPath, loadCompareImages: true);\n        if (_db.AllCompareImages.Count == 0)\n        {\n            throw new InvalidOperationException($\"BinaryOCR database is empty: {dbPath}\");\n        }\n        _matcher = new BinaryOcrMatcher\n        {\n            IsLatinDb = Path.GetFileNameWithoutExtension(dbPath).Contains(\"Latin\", StringComparison.OrdinalIgnoreCase),\n        };\n    }\n\n    public string Recognize(SKBitmap bitmap)\n    {\n        if (bitmap is null || bitmap.Width == 0 || bitmap.Height == 0)\n        {\n            return string.Empty;\n        }\n\n        var parent = new NikseBitmap2(bitmap);\n        parent.MakeTwoColor(200);\n        parent.CropTop(0, new SKColor(0, 0, 0, 0));\n        var letters = NikseBitmapImageSplitter2.SplitBitmapToLettersNew(","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/BinaryOcrOcrEngine.cs#L14-L50","documentation":"InvalidOperationException from the BinaryOcrOcrEngine constructor: the .db file exists and loaded, but AllCompareImages is empty — i.e. the database has no trained glyph entries, so recognition would always return nothing. This is distinct from 'file not found' (the file is present but useless).","triggerScenarios":"Loading a BinaryOCR .db that was created empty, corrupted, or partially written; loadCompareImages:true returned zero compare images.","commonSituations":"An aborted/cancelled SE GUI training session left a zero-row .db; copied a placeholder .db; format mismatch where the loader skipped all entries silently.","solutions":["Regenerate the .db in the SE GUI by training on actual subtitle images.","Open the .db in the SE Binary/OCR editor and confirm it has compare images; if empty, retrain.","Use a different, known-good .db (e.g. a Latin.db from another install)."],"exampleFix":"// before\nif (_db.AllCompareImages.Count == 0)\n    throw new InvalidOperationException($\"BinaryOCR database is empty: {dbPath}\");\n\n// after\nif (_db.AllCompareImages.Count == 0)\n    throw new InvalidOperationException($\"BinaryOCR database '{dbPath}' loaded but has 0 compare images ({_db.AllCompareImages.Count} entries). Retrain it in the SE GUI.\");","handlingStrategy":"validation","validationCode":"using var probe = new BinaryOcrDb(dbPath, loadCompareImages: true);\nif (probe.AllCompareImages.Count == 0)\n    throw new InvalidOperationException($\"BinaryOCR db '{dbPath}' is empty; retrain in the SE GUI.\");","typeGuard":"static bool OcrDbHasEntries(string path) { using var d = new BinaryOcrDb(path, loadCompareImages: true); return d.AllCompareImages.Count > 0; }","tryCatchPattern":"null","preventionTips":["After generating a db, sanity-check it has compare images before deploying.","Ship or reference a known-good Latin.db so users are not stuck with empty dbs."],"tags":["ocr","binary-ocr","data-validation","configuration"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}