public override Mat Render(CameraBridgeViewBase.ICvCameraViewFrame inputFrame) { Mat undistortedFrame = new Mat(inputFrame.Rgba().Size(), inputFrame.Rgba().Type()); Calib3dNET.Calib3d.Undistort(inputFrame.Rgba(), undistortedFrame, mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients()); Mat comparisonFrame = inputFrame.Rgba(); undistortedFrame.ColRange(new Range(0, mWidth / 2)).CopyTo(comparisonFrame.ColRange(new Range(mWidth / 2, mWidth))); List <MatOfPoint> border = new List <MatOfPoint>(); int shift = (int)(mWidth * 0.005); border.Add(new MatOfPoint(new Point(mWidth / 2 - shift, 0), new Point(mWidth / 2 + shift, 0), new Point(mWidth / 2 + shift, mHeight), new Point(mWidth / 2 - shift, mHeight))); Imgproc.FillPoly(comparisonFrame, border, new Scalar(255, 255, 255)); Imgproc.PutText(comparisonFrame, mResources.GetString(Resource.String.original), new Point(mWidth * 0.1, mHeight * 0.1), Imgproc.FontHersheySimplex, 1.0, new Scalar(255, 255, 0)); Imgproc.PutText(comparisonFrame, mResources.GetString(Resource.String.undistorted), new Point(mWidth * 0.6, mHeight * 0.1), Imgproc.FontHersheySimplex, 1.0, new Scalar(255, 255, 0)); return(comparisonFrame); }
private void renderFrame(Mat rgbaFrame) { drawPoints(rgbaFrame); Imgproc.PutText(rgbaFrame, "Captured: " + mCornersBuffer.Count, new Point(rgbaFrame.Cols() / 3 * 2, rgbaFrame.Rows() * 0.1), Core.Core.FontHersheySimplex, 1.0, new Scalar(255, 255, 0)); }
internal Mat PuzzleFrame(Mat inputPicture) { lock (_lock) { Mat[] cells = new Mat[GridArea]; int rows = inputPicture.Rows(); int cols = inputPicture.Cols(); rows = rows - rows % 4; cols = cols - cols % 4; for (int i = 0; i < GridSize; i++) { for (int j = 0; j < GridSize; j++) { int k = i * GridSize + j; cells[k] = inputPicture.Submat(i * inputPicture.Rows() / GridSize, (i + 1) * inputPicture.Rows() / GridSize, j * inputPicture.Cols() / GridSize, (j + 1) * inputPicture.Cols() / GridSize); } } rows = rows - rows % 4; cols = cols - cols % 4; // copy shuffled tiles for (int i = 0; i < GridArea; i++) { int idx = _indexes[i]; if (idx == GridEmptyIndex) { _cells15[i].SetTo(GridEmptyColor); } else { cells[idx].CopyTo(_cells15[i]); if (_showTileNumbers) { Imgproc.PutText(_cells15[i], (1 + idx).ToString(), new Point((cols / GridSize - _textWidths[idx]) / 2, (rows / GridSize + _textHeights[idx]) / 2), 3 /* CV_FONT_HERSHEY_COMPLEX */, 1, new Scalar(255, 0, 0, 255), 2); } } } for (int i = 0; i < GridArea; i++) { cells[i].Release(); } DrawGrid(cols, rows, _rgba15); return(_rgba15); } }
public Mat OnCameraFrame(CameraBridgeViewBase.ICvCameraViewFrame inputFrame) { Mat rgba = inputFrame.Rgba(); Size sizeRgba = rgba.Size(); Mat rgbaInnerWindow; int rows = (int)sizeRgba.Height; int cols = (int)sizeRgba.Width; int left = cols / 8; int top = rows / 8; int width = cols * 3 / 4; int height = rows * 3 / 4; switch (CameraViewActivity.viewMode) { case CameraViewActivity.VIEW_MODE_RGBA: Point center = new Point(100, 200); int radius = 100; Scalar color = new Scalar(0, 255, 0); // canvas, center, radius, color, linewidth Imgproc.Circle(rgba, center, radius, color, 5); center.X = 400; center.Y = 700; color.Val[0] = 255; // canvas, string, left up, font id, size, color Imgproc.PutText(rgba, "Surprise,\nmotherfucker!", center, 1, 4, color, 16); break; case CameraViewActivity.VIEW_MODE_HIST: Mat hist = new Mat(); int thikness = (int)(sizeRgba.Width / (mHistSizeNum + 10) / 5); if (thikness > 5) { thikness = 5; } int offset = (int)((sizeRgba.Width - (5 * mHistSizeNum + 4 * 10) * thikness) / 2); // RGB for (int c = 0; c < 3; c++) { Imgproc.CalcHist(Arrays.AsList(rgba).Cast <Mat>().ToList(), mChannels[c], mMat0, hist, mHistSize, mRanges); Core.Normalize(hist, hist, sizeRgba.Height / 2, 0, Core.NormInf); hist.Get(0, 0, mBuff); for (int h = 0; h < mHistSizeNum; h++) { mP1.X = mP2.X = offset + (c * (mHistSizeNum + 10) + h) * thikness; mP1.Y = sizeRgba.Height - 1; mP2.Y = mP1.Y - 2 - (int)mBuff[h]; Imgproc.Line(rgba, mP1, mP2, mColorsRGB[c], thikness); } } // Value and Hue Imgproc.CvtColor(rgba, mIntermediateMat, Imgproc.ColorRgb2hsvFull); // Value Imgproc.CalcHist(Arrays.AsList(mIntermediateMat).Cast <Mat>().ToList(), mChannels[2], mMat0, hist, mHistSize, mRanges); Core.Normalize(hist, hist, sizeRgba.Height / 2, 0, Core.NormInf); hist.Get(0, 0, mBuff); for (int h = 0; h < mHistSizeNum; h++) { mP1.X = mP2.X = offset + (3 * (mHistSizeNum + 10) + h) * thikness; mP1.Y = sizeRgba.Height - 1; mP2.Y = mP1.Y - 2 - (int)mBuff[h]; Imgproc.Line(rgba, mP1, mP2, mWhilte, thikness); } // Hue Imgproc.CalcHist(Arrays.AsList(mIntermediateMat).Cast <Mat>().ToList(), mChannels[0], mMat0, hist, mHistSize, mRanges); Core.Normalize(hist, hist, sizeRgba.Height / 2, 0, Core.NormInf); hist.Get(0, 0, mBuff); for (int h = 0; h < mHistSizeNum; h++) { mP1.X = mP2.X = offset + (4 * (mHistSizeNum + 10) + h) * thikness; mP1.Y = sizeRgba.Height - 1; mP2.Y = mP1.Y - 2 - (int)mBuff[h]; Imgproc.Line(rgba, mP1, mP2, mColorsHue[h], thikness); } break; case CameraViewActivity.VIEW_MODE_CANNY: rgbaInnerWindow = rgba.Submat(top, top + height, left, left + width); Imgproc.Canny(rgbaInnerWindow, mIntermediateMat, 80, 90); Imgproc.CvtColor(mIntermediateMat, rgbaInnerWindow, Imgproc.ColorGray2bgra, 4); rgbaInnerWindow.Release(); break; case CameraViewActivity.VIEW_MODE_SOBEL: Mat gray = inputFrame.Gray(); Mat grayInnerWindow = gray.Submat(top, top + height, left, left + width); rgbaInnerWindow = rgba.Submat(top, top + height, left, left + width); Imgproc.Sobel(grayInnerWindow, mIntermediateMat, CvType.Cv8u, 1, 1); Core.ConvertScaleAbs(mIntermediateMat, mIntermediateMat, 10, 0); Imgproc.CvtColor(mIntermediateMat, rgbaInnerWindow, Imgproc.ColorGray2bgra, 4); grayInnerWindow.Release(); rgbaInnerWindow.Release(); break; case CameraViewActivity.VIEW_MODE_SEPIA: rgbaInnerWindow = rgba.Submat(top, top + height, left, left + width); Core.Transform(rgbaInnerWindow, rgbaInnerWindow, mSepiaKernel); rgbaInnerWindow.Release(); break; case CameraViewActivity.VIEW_MODE_ZOOM: Mat zoomCorner = rgba.Submat(0, rows / 2 - rows / 10, 0, cols / 2 - cols / 10); Mat mZoomWindow = rgba.Submat(rows / 2 - 9 * rows / 100, rows / 2 + 9 * rows / 100, cols / 2 - 9 * cols / 100, cols / 2 + 9 * cols / 100); Imgproc.Resize(mZoomWindow, zoomCorner, zoomCorner.Size()); Size wsize = mZoomWindow.Size(); Imgproc.Rectangle(mZoomWindow, new Point(1, 1), new Point(wsize.Width - 2, wsize.Height - 2), new Scalar(255, 0, 0, 255), 2); zoomCorner.Release(); mZoomWindow.Release(); break; case CameraViewActivity.VIEW_MODE_PIXELIZE: rgbaInnerWindow = rgba.Submat(top, top + height, left, left + width); Imgproc.Resize(rgbaInnerWindow, mIntermediateMat, mSize0, 0.1, 0.1, Imgproc.InterNearest); Imgproc.Resize(mIntermediateMat, rgbaInnerWindow, rgbaInnerWindow.Size(), 0.0, 0.0, Imgproc.InterNearest); rgbaInnerWindow.Release(); break; case CameraViewActivity.VIEW_MODE_POSTERIZE: /* * Imgproc.cvtColor(rgbaInnerWindow, mIntermediateMat, Imgproc.COLOR_RGBA2RGB); * Imgproc.pyrMeanShiftFiltering(mIntermediateMat, mIntermediateMat, 5, 50); * Imgproc.cvtColor(mIntermediateMat, rgbaInnerWindow, Imgproc.COLOR_RGB2RGBA); */ rgbaInnerWindow = rgba.Submat(top, top + height, left, left + width); Imgproc.Canny(rgbaInnerWindow, mIntermediateMat, 80, 90); rgbaInnerWindow.SetTo(new Scalar(0, 0, 0, 255), mIntermediateMat); Core.ConvertScaleAbs(rgbaInnerWindow, mIntermediateMat, 1.0 / 16, 0); Core.ConvertScaleAbs(mIntermediateMat, rgbaInnerWindow, 16, 0); rgbaInnerWindow.Release(); break; } return(rgba); }