DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.74k stars 387 forks source link

Dewarping issue #694

Open kraw-ios opened 1 year ago

kraw-ios commented 1 year ago
Screenshot 2023-05-16 at 16 35 38 Screenshot 2023-05-16 at 16 35 38

Hey, I have an issue with dewarping this image example. I get the following logs:

Info in dewarpGetTextlineCenters: finding text line centers Warning in dewarpBuildPageModel: linecount 2 < min req'd number of lines (10) for model Info in dewarpaSetValidModels: page 35: no model successfully built Info in dewarpaApplyInit: no valid dew model for page 35 Error in dewarpaApplyDisparity: no model available Error in getFilenamesInDirectory: pdir not opened Error in getSortedPathnamesInDirectory: sa not made Error in convertFilesToPdf: sa not made

I tried to deskew but without any success. Do you think it might be because it's to curved? Because I'm able to get the lines drawn on the document. Here's my code, do you have any suggestions?

var pixn = pixBackgroundNormSimple(pixs, nil, nil);
        var pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2);
        var pixb = pixThresholdToBinary(pixg, 130);
        let dewa = dewarpaCreate(2, 30, 1, 10, 90);
       dewarpaUseBothArrays(dewa, 1);
let dew1 = dewarpCreate(pixb, 35);
        dewarpaInsertDewarp(dewa, dew1);
        dewarpBuildPageModel(dew1, modelPath.relativePath);
        dewarpaApplyDisparity(dewa, 35, pixg, 200, 0, 0, &pixd, disparityPath.relativePath);

Maybe it's worth mentioning that it also fails for the "1555-3.jpg" example and I tried using versions 1.72 and 1.79.

kraw-ios commented 1 year ago

I was able to fix it by changing the input image and also the curvature values allowed. Now I'm facing another issue that I can't really find any documentation or solution for it. The dewarped results become way worse than the original ones as you can see in the following examples. I get the following debug info:

Info in dewarpFindVertDisparity: Pass 1: Curvature: medval = 0.000075, meddev = 0.000023 Info in dewarpFindVertDisparity: Pass 2: Min/max curvature = (13, 123) Info in dewarpFindHorizDisparity: Left quad LSF median error = 0.73 Info in dewarpFindHorizDisparity: Left edge slope = 10 Info in dewarpFindHorizDisparity: Left edge curvature = -3 Info in dewarpFindHorizDisparity: Right quad LSF median error = 11.27 Info in dewarpFindHorizDisparity: Right edge slope = 4 Info in dewarpFindHorizDisparity: Right edge curvature = 3 Info in dewarpBuildPageModel: hsuccess = 1

Is it possible to somehow only apply the disparity to one side of the image without reducing the curvature line curv maximum value?

Original

original

Dewarped

dewarped