mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: PaddleOCR CPU crash, content-aware-resize limits, barcode fixtures
- Add enable_mkldnn=False to PaddleOCR constructor to bypass PaddlePaddle 3.3+ OneDNN/PIR crash on CPU-only systems - Add 25MP and 75% max-reduction guard to seam carving with clear error messages instead of silent timeout/crash - Replace barcode/QR AVIF test fixtures with actual scannable codes (old fixtures did not contain real barcodes)
This commit is contained in:
@@ -143,6 +143,7 @@ def run_paddleocr_v5(input_path, language):
|
||||
lang=paddle_lang,
|
||||
device=device,
|
||||
ocr_version="PP-OCRv5",
|
||||
enable_mkldnn=False,
|
||||
)
|
||||
emit_progress(30, "Scanning")
|
||||
results = ocr.predict(input=input_path)
|
||||
|
||||
@@ -67,6 +67,24 @@ export async function seamCarve(
|
||||
const meta = await sharp(inputBuffer).metadata();
|
||||
const width = meta.width ?? 0;
|
||||
const height = meta.height ?? 0;
|
||||
const megapixels = (width * height) / 1_000_000;
|
||||
|
||||
const MAX_MP = 25;
|
||||
if (megapixels > MAX_MP) {
|
||||
throw new Error(
|
||||
`Image is too large for content-aware resize (${megapixels.toFixed(1)} MP, max ${MAX_MP} MP). Resize the image to a smaller size first.`,
|
||||
);
|
||||
}
|
||||
|
||||
const targetW = options.width ?? width;
|
||||
const targetH = options.height ?? height;
|
||||
const wRatio = targetW / width;
|
||||
const hRatio = targetH / height;
|
||||
if (wRatio < 0.25 || hRatio < 0.25) {
|
||||
throw new Error(
|
||||
`Content-aware resize cannot reduce dimensions by more than 75% (requested ${width}→${targetW} width, ${height}→${targetH} height). Use regular resize first to get closer to the target size.`,
|
||||
);
|
||||
}
|
||||
|
||||
const processBuffer = await sharp(inputBuffer).jpeg({ quality: 95 }).toBuffer();
|
||||
|
||||
@@ -90,7 +108,6 @@ export async function seamCarve(
|
||||
if (options.blurRadius !== undefined) args.push("-blur", String(options.blurRadius));
|
||||
if (options.sobelThreshold !== undefined) args.push("-sobel", String(options.sobelThreshold));
|
||||
|
||||
const megapixels = (width * height) / 1_000_000;
|
||||
const timeoutMs = Math.max(120_000, megapixels * 10 * 1000);
|
||||
await execFileAsync(cairePath, args, { timeout: timeoutMs });
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.1 KiB |
Vendored
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 1.5 KiB |
Reference in New Issue
Block a user