Skip to content

Improve scan precision and performance

Anton Akhmerov requested to merge feature/scan-precision into master

I now use Hough line detection algorithm together with the explicit knowledge of the corner marker size. Because I only feed the corners of the image to the line transform, and because I avoid processing on the complete image, this also drops the cost of find_corner_marker_keypoints to a negligible value.

Upon further inspection I remove two unnecessary conversions between different color formats, and right now two lines of code take 50% of page processing: image_array = np.array(image_data), and image_data.save(target_image). Because these are unavoidable, I consider that this closes #149 (closed).

I have also introduced a "non-strict" mode, where if we fail to find corner markers we still try to find the barcode and flip the page as necessary. We should always do that because the difference is between producing a low quality scanned page and nothing at all.

Due to refactoring of the corner detection, this also closes #187 (closed).


Now to the downsides.

By inspecting the results when this algorithm succeeds, I see that there is still a few pixels mismatch between the resulting corner positions. I believe this is due to how we apply the rotation and shift: there might be a minor scale change needed as well. The way to address it would be to compute a scale/rotate transformation and apply a single WarpAffine transformation in cv2. After the refactoring of the code, the treatment of corner markers is well-localized, and shouldn't have side-effects.

Additionally, checking on real data I see that the algorithm is sometimes flaky, and will require further exploration, possibly using #188 (closed).

Therefore as this MR stands, it only partially addresses #167 (closed).

Edited by Anton Akhmerov

Merge request reports