How to implement a wide-angle camera distortion correction algorithm in android
This article mainly introduces the relevant knowledge of "how to achieve a wide-angle camera distortion correction algorithm in android". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to achieve a wide-angle camera distortion correction algorithm in android" can help you solve the problem.
Code
Public class LensCorrect2 {/ / Lens correction lookup table 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 / / initialize 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;}} about "how to implement a wide-angle camera distortion correction algorithm in android", thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.