如何将透视变换应用于 Android 中的 ImageProxy 或 Bitmap。

huangapple go评论97阅读模式
英文:

how to apply perspective transformation to ImageProxy or Bitmap in android

问题

我的目标是从零开始创建一个扫描器应用程序。为了做到这一点,我在Android中使用了CameraX库,使用Java语言。假设我已经检测到了页面的角落。在捕获图像之后,我如何在图像上执行变换矩阵乘法?(我正在按照此处提到的算法进行操作,只是尝试在Java中实现它)。我需要将图像转换为矩阵,以便可以将每个像素位置(例如[i,j,1])与我的3x3变换矩阵相乘,以获取新位置。然后,我会有另一个矩阵,记录了经过变换的像素的颜色,如果它位于我要显示的区域内。最后,我将最终矩阵转换为图像。

因此,我的问题是:
1)如何在CameraX中使用捕获的图像执行操作(使用Java)?
2)如何将图像转换为矩阵(以执行上述操作),然后再将矩阵转换回图像?

我希望当用户点击捕获按钮时,会记录文档角落的最新坐标,并使用变换矩阵对捕获的图像进行变换。

英文:

My goal is to create a scanner app by scratch. To do this, I am using the CameraX library in android in java. Assume that I have already detected the corners of the page. After the image is captured, how to I perform the transformation matrix multiplication on the image? (I am following the algorithm mentioned here except trying to do it in java) I would need the image in a matrix so that i can multipy each pixel position say [i, j, 1] by my 3x3 transformation matrix to get the new position. Then, i would have another matrix where i record the color of pixel that was transformed if it is inside the area that I want to show. Finally, i would convert the final matrix into an image.

So basically, my question(s) are:

  1. how do I do perform operations with the captured image in camerax in java
  2. how do I convert a image to a matrix (to do the stuff mentioned above) then a matrix back into an image

I want it so that when the user clicks the capture button, the latest coordinates of the corners of the document are recorded and used to transform the captured image using the transformation matrix.

答案1

得分: 1

android.graphics.Matrix 是 Android 中的 3x3 透视变换矩阵。示例:

val matrix = Matrix()
matrix.setPolyToPoly(docVertexes, 0, bitmapVertexes, 0, 4)
Bitmap transformedBitmap = Bitmap.createBitmap(
            sourceBitmap,
            0,
            0,
            sourceBitmap.getWidth(),
            sourceBitmap.getHeight(),
            quadToRect,
            true);
英文:

android.graphics.Matrix is the 3x3 perspective transformation matrix in Android. Example:

val matrix = Matrix()
matrix.setPolyToPoly(docVertexes, 0, bitmapVertexes, 0, 4)
Bitmap transformedBitmap = Bitmap.createBitmap(
            sourceBitmap,
            0,
            0,
            sourceBitmap.getWidth(),
            sourceBitmap.getHeight(),
            quadToRect,
            true);

huangapple
  • 本文由 发表于 2020年7月30日 20:25:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/63173146.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定