Pan*_* C. 3 android image-processing
我正在开发一款需要对手机相机拍摄的照片进行透视失真校正的应用.拍摄照片后,想法是在图像视图上显示它并让用户标记文档的四个角(卡片,纸张等),然后根据这些点应用校正.这是我想要实现的一个例子:
http://1.bp.blogspot.com/-ro9hniPj52E/TkoM0kTlEnI/AAAAAAAAAbQ/c2R5VrgmC_w/s640/s4.jpg
有关如何在Android上执行此操作的任何想法?
Att*_*nyi 11
您不必为此使用库.您也可以使用类的一个drawBitmap函数Canvas和一个使用类setPolyToPoly函数初始化的矩阵Matrix.
public static Bitmap cornerPin(Bitmap b, float[] srcPoints, float[] dstPoints) {
int w = b.getWidth(), h = b.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
Canvas c = new Canvas(result);
Matrix m = new Matrix();
m.setPolyToPoly(srcPoints, 0, dstPoints, 0, 4);
c.drawBitmap(b, m, p);
return result;
}
Run Code Online (Sandbox Code Playgroud)
(仅在启用消除锯齿时才需要Paint对象.)
用法:
int w = bitmap.getWidth(), h = bitmap.getHeight();
float[] src = {
0, 0, // Coordinate of top left point
0, h, // Coordinate of bottom left point
w, h, // Coordinate of bottom right point
w, 0 // Coordinate of top right point
};
float[] dst = {
0, 0, // Desired coordinate of top left point
0, h, // Desired coordinate of bottom left point
w, 0.8f * h, // Desired coordinate of bottom right point
w, 0.2f * h // Desired coordinate of top right point
};
Bitmap transformed = cornerPin(bitmap, src, dst);
Run Code Online (Sandbox Code Playgroud)
src源点的坐标在哪里,dst是目标点的坐标.结果: