您好,登錄后才能下訂單哦!
這篇文章主要介紹“如何在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中實現一個廣角相機畸變校正算法”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。