public void OnCameraViewStarted(int width, int height) { if (mWidth != width || mHeight != height) { mWidth = width; mHeight = height; mCalibrator = new CameraCalibrator(mWidth, mHeight); if (CalibrationResult.tryLoad(this, mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients())) { mCalibrator.setCalibrated(); } mOnCameraFrameRender = new OnCameraFrameRender(new CalibrationFrameRender(mCalibrator)); } }
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Resource.Id.calibration: mOnCameraFrameRender = new OnCameraFrameRender(new CalibrationFrameRender(mCalibrator)); item.SetChecked(true); return(true); case Resource.Id.undistortion: mOnCameraFrameRender = new OnCameraFrameRender(new UndistortionFrameRender(mCalibrator)); item.SetChecked(true); return(true); case Resource.Id.comparison: mOnCameraFrameRender = new OnCameraFrameRender(new ComparisonFrameRender(mCalibrator, mWidth, mHeight, Resources)); item.SetChecked(true); return(true); case Resource.Id.calibrate: var res = this.Resources; if (mCalibrator.getCornersBufferSize() < 2) { (Toast.MakeText(this, res.GetString(Resource.String.more_samples), ToastLength.Short)).Show(); return(true); } mOnCameraFrameRender = new OnCameraFrameRender(new PreviewFrameRender()); //OnPreExecute var calibrationProgress = new ProgressDialog(this); calibrationProgress.SetTitle(Resources.GetString(Resource.String.calibrating)); calibrationProgress.SetMessage(Resources.GetString(Resource.String.please_wait)); calibrationProgress.SetCancelable(false); calibrationProgress.Indeterminate = true; calibrationProgress.Show(); Task.Run(() => mCalibrator.calibrate()) //OnPostExecute .ContinueWith(t => { calibrationProgress.Dismiss(); mCalibrator.clearCorners(); mOnCameraFrameRender = new OnCameraFrameRender(new CalibrationFrameRender(mCalibrator)); String resultMessage = (mCalibrator.isCalibrated()) ? Resources.GetString(Resource.String.calibration_successful) + " " + mCalibrator.getAvgReprojectionError() : Resources.GetString(Resource.String.calibration_unsuccessful); Toast.MakeText(this, resultMessage, ToastLength.Short).Show(); if (mCalibrator.isCalibrated()) { CalibrationResult.save(this, mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients()); } }, TaskScheduler.FromCurrentSynchronizationContext()); return(true); default: return(base.OnOptionsItemSelected(item)); } }