rosenlu / sylon

2 stars 0 forks source link

Implement perspective transform on images #1

Open strassan opened 3 years ago

strassan commented 3 years ago

To be able to extract the actual "paper of interest" from an image, we need to perform a perspective transform. I think there is two possible ways of doing this: using the Android native Matrix class or using OpenCV for Android. Here are a few hints on both of these.

  1. Matrix class The Matrix class has a method called "setPolyToPoly", which is most likely the thing we need: Matrix.setPolyToPoly To apply this Matrix to an ImageView should work something like this:

    Matrix matrix = new Matrix();
    imageView.setScaleType(ImageView.ScaleType.MATRIX);
    matrix.setPolyToPoly(src, srcIndex, dst, dstIndex, pointCount);
    imageView.setImageMatrix(matrix);

    I don't know about anti aliasing in this kind of setup and I don't know how to automatically find the corners of the page. However, I'm sure these things can be handled.

  2. OpenCV OpenCV is a great library for image manipulation and can be used in Android: Android - OpenCV In OpenCV, the thing we look for is the "getPerspectiveTransform". Here's a Tutorial on that.

I guess the preferred option is to go with the Android native stuff, as OpenCV might add a lot of overhead to the project.