这篇文章主要介绍“如何在android中实现一个广角相机畸变校正算法”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“如何在android中实现一个广角相机畸变校正算法”文章能帮助大家解决问题。
代码
public class LensCorrect2 {
// 镜头校正查找表
private Point[][] CorrInd = null;// new Point[480][640];
private double k1 = 0f;
private double k2 = 0f;
private Bitmap mBm = null;
private int mW = 0;
private int mH = 0;
private int max_x = 0, max_y = 0;
private int min_x = 0, min_y = 0;
// 镜头径向畸变校正初始化
public LensCorrect2(double k1, double k2, Bitmap mBm) {
super();
this.k1 = k1;
this.k2 = k2;
this.mBm = mBm;
this.mW = mBm.getWidth();
this.mH = mBm.getHeight();
int cw = mW >> 1;
int ch = mH >> 1;
CorrInd = new Point[mH][mW];
Log.i("XXXXX", "imgHeight=" + mH);
Log.i("XXXXX", "imgWidth=" + mW);
int it;
int jt;
int it2;
int jt2;
for (int i = 0; i < mH; i++) {
it = (i + 1) - ch; // (i+1) 是其真正的图像坐标
for (int j = 0; j < mW; j++) {
double temp;
jt = (j + 1) - cw; // (j+1) 是其真正的图像坐标
temp = 1 + k1 * it * it + k2 * jt * jt;
it2 = (int) (temp * it);
jt2 = (int) (temp * jt);
it2 = it2 + ch + 1;
jt2 = jt2 + cw + 1;
// Log.i("AAAAA", "imgHeight="+imgHeight);
// Log.i("AAAAA", "imgWidth="+imgWidth);
// Log.i("AAAAA", "i="+i);
// Log.i("AAAAA", "j="+j);
// Log.i("XXXXX", "jt2="+jt2);
// Log.i("XXXXX", "it2="+it2);
if (max_x < jt2) {
max_x = jt2;
}
if (min_x > jt2) {
min_x = jt2;
}
if (max_y < it2) {
max_y = it2;
}
if (min_y > it2) {
min_y = it2;
}
Point p = new Point(jt2, it2);
CorrInd[i][j] = p;
}
}
Log.i("XXXXX", "max_x=" + max_x);
Log.i("XXXXX", "min_x=" + min_x);
Log.i("XXXXX", "max_y=" + max_y);
Log.i("XXXXX", "min_y=" + min_y);
}
public Bitmap getLensCorrect() {
Bitmap bm = Bitmap.createBitmap((max_x - min_x) + 1,
(max_y - min_y) + 1, Bitmap.Config.ARGB_8888);
int it2;
int jt2;
for (int i = 0; i < mH; i++) {
for (int j = 0; j < mW; j++) {
it2 = CorrInd[i][j].y;
jt2 = CorrInd[i][j].x;
bm.setPixel(jt2 - min_x, it2 - min_y, mBm.getPixel(j, i));
}
}
return bm;
}
public Bitmap getLensCorrect0() {
Bitmap bm = Bitmap.createBitmap(mW, mH, Bitmap.Config.ARGB_8888);
int it2;
int jt2;
for (int i = 0; i < mH; i++) {
for (int j = 0; j < mW; j++) {
it2 = CorrInd[i][j].y;
jt2 = CorrInd[i][j].x;
if ((it2 >= 0) && (jt2 >= 0) && (it2 < mH) && (jt2 < mW)) {
// bm.setPixel(j, i, mBm.getPixel(jt2, it2));
bm.setPixel(jt2, it2, mBm.getPixel(j, i));
}
}
}
return bm;
}
}
关于“如何在android中实现一个广角相机畸变校正算法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注天达云行业资讯频道,小编每天都会为大家更新不同的知识点。