public static double undistort() { DateTime t1 = DateTime.Now, t2 = t1; ImageShow.cls(); if (ImageShow.nowFile != null) { byte[] data = new byte[ImageShow.source.Width * ImageShow.source.Height * 3]; int channel = 3; t1 = DateTime.Now; runUndistort(ImageShow.nowFile, ImageShow.source.Width * ImageShow.source.Height * 3, data, paraNum, para, ref channel); t2 = DateTime.Now; Rectangle rect = new Rectangle(0, 0, ImageShow.source.Width, ImageShow.source.Height); System.Drawing.Imaging.BitmapData bmpData = ImageShow.source.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, ImageShow.source.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = Math.Abs(bmpData.Stride) * ImageShow.source.Height; byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); channel = Bitmap.GetPixelFormatSize(ImageShow.source.PixelFormat); if (channel == 8) { for (int counter = 0; counter < ImageShow.source.Width * ImageShow.source.Height; counter++) { rgbValues[counter] = data[counter * 3]; } } else { for (int counter = 0; counter < ImageShow.source.Width * ImageShow.source.Height * 3; counter++) { rgbValues[counter] = data[counter]; } } System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); ImageShow.source.UnlockBits(bmpData); } return((t2 - t1).TotalMilliseconds); }
public static double runManualExtract() { DateTime t1 = DateTime.Now, t2 = t1; ImageShow.cls(); if (ImageShow.nowFile != null) { int w = boardWidth; int h = boardHeight; int cornerNum = w * h; float[] cornerX = new float[cornerNum], cornerY = new float[cornerNum]; for (int i = 0; i < 4; i++) { cornerX[i] = manualCorner[i].X; cornerY[i] = manualCorner[i].Y; } t1 = DateTime.Now; CameraCalibrate.manualExtract(ImageShow.nowFile, ref cornerNum, cornerX, cornerY, w, h, manualFixSize, fixSize); t2 = DateTime.Now; CameraCalibrate.nowCornerNum = cornerNum; if (CameraCalibrate.nowCornerX == null) { CameraCalibrate.nowCornerX = new float[cornerNum]; CameraCalibrate.nowCornerY = new float[cornerNum]; } for (int i = 0; i < cornerNum; i++) { //float x = cornerX[i] * ImageShow.position.Width / ImageShow.initPosition.Width + ImageShow.position.X; //float y = cornerY[i] * ImageShow.position.Height / ImageShow.initPosition.Height + ImageShow.position.Y; //float r = 10 * ImageShow.scale; ImageShow.addPoint(new PointF(cornerX[i], cornerY[i])); CameraCalibrate.nowCornerX[i] = cornerX[i]; CameraCalibrate.nowCornerY[i] = cornerY[i]; } CameraCalibrate.isUpdated = true; } return((t2 - t1).TotalMilliseconds); }