diff --git a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java index 88ade8430f..38f1d5959b 100644 --- a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java +++ b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java @@ -48,17 +48,12 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView private CameraBridgeViewBase mOpenCvCameraView; private Size mSize0; - private Size mSizeRgba; - private Size mSizeRgbaInner; - private Mat mRgba; - private Mat mGray; private Mat mIntermediateMat; - private Mat mHist; private Mat mMat0; private MatOfInt mChannels[]; private MatOfInt mHistSize; - private int mHistSizeNum; + private int mHistSizeNum = 25; private MatOfFloat mRanges; private Scalar mColorsRGB[]; private Scalar mColorsHue[]; @@ -66,10 +61,6 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView private Point mP1; private Point mP2; private float mBuff[]; - private Mat mRgbaInnerWindow; - private Mat mGrayInnerWindow; - private Mat mZoomWindow; - private Mat mZoomCorner; private Mat mSepiaKernel; public static int viewMode = VIEW_MODE_RGBA; @@ -166,13 +157,9 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView } public void onCameraViewStarted(int width, int height) { - mGray = new Mat(); - mRgba = new Mat(); mIntermediateMat = new Mat(); mSize0 = new Size(); - mHist = new Mat(); mChannels = new MatOfInt[] { new MatOfInt(0), new MatOfInt(1), new MatOfInt(2) }; - mHistSizeNum = 25; mBuff = new float[mHistSizeNum]; mHistSize = new MatOfInt(mHistSizeNum); mRanges = new MatOfFloat(0f, 256f); @@ -197,14 +184,22 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView mSepiaKernel.put(3, 0, /* A */0.000f, 0.000f, 0.000f, 1f); } - private void CreateAuxiliaryMats() { - if (mRgba.empty()) - return; + public void onCameraViewStopped() { + // Explicitly deallocate Mats + if (mIntermediateMat != null) + mIntermediateMat.release(); - mSizeRgba = mRgba.size(); + mIntermediateMat = null; + } - int rows = (int) mSizeRgba.height; - int cols = (int) mSizeRgba.width; + public Mat onCameraFrame(CvCameraViewFrame 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; @@ -212,151 +207,107 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView int width = cols * 3 / 4; int height = rows * 3 / 4; - if (mRgbaInnerWindow == null) - mRgbaInnerWindow = mRgba.submat(top, top + height, left, left + width); - mSizeRgbaInner = mRgbaInnerWindow.size(); - - if (mGrayInnerWindow == null && !mGray.empty()) - mGrayInnerWindow = mGray.submat(top, top + height, left, left + width); - - if (mZoomCorner == null) - mZoomCorner = mRgba.submat(0, rows / 2 - rows / 10, 0, cols / 2 - cols / 10); - - if (mZoomWindow == null) - mZoomWindow = mRgba.submat(rows / 2 - 9 * rows / 100, rows / 2 + 9 * rows / 100, cols / 2 - 9 * cols / 100, cols / 2 + 9 * cols / 100); - } - - public void onCameraViewStopped() { - // Explicitly deallocate Mats - if (mZoomWindow != null) - mZoomWindow.release(); - if (mZoomCorner != null) - mZoomCorner.release(); - if (mGrayInnerWindow != null) - mGrayInnerWindow.release(); - if (mRgbaInnerWindow != null) - mRgbaInnerWindow.release(); - if (mRgba != null) - mRgba.release(); - if (mGray != null) - mGray.release(); - if (mIntermediateMat != null) - mIntermediateMat.release(); - - mRgba = null; - mGray = null; - mIntermediateMat = null; - mRgbaInnerWindow = null; - mGrayInnerWindow = null; - mZoomCorner = null; - mZoomWindow = null; - } - - public Mat onCameraFrame(CvCameraViewFrame inputFrame) { - mRgba = inputFrame.rgba(); - switch (ImageManipulationsActivity.viewMode) { case ImageManipulationsActivity.VIEW_MODE_RGBA: break; case ImageManipulationsActivity.VIEW_MODE_HIST: - if ((mSizeRgba == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height)) - CreateAuxiliaryMats(); - int thikness = (int) (mSizeRgba.width / (mHistSizeNum + 10) / 5); + Mat hist = new Mat(); + int thikness = (int) (sizeRgba.width / (mHistSizeNum + 10) / 5); if(thikness > 5) thikness = 5; - int offset = (int) ((mSizeRgba.width - (5*mHistSizeNum + 4*10)*thikness)/2); + int offset = (int) ((sizeRgba.width - (5*mHistSizeNum + 4*10)*thikness)/2); // RGB for(int c=0; c<3; c++) { - Imgproc.calcHist(Arrays.asList(mRgba), mChannels[c], mMat0, mHist, mHistSize, mRanges); - Core.normalize(mHist, mHist, mSizeRgba.height/2, 0, Core.NORM_INF); - mHist.get(0, 0, mBuff); + Imgproc.calcHist(Arrays.asList(rgba), mChannels[c], mMat0, hist, mHistSize, mRanges); + Core.normalize(hist, hist, sizeRgba.height/2, 0, Core.NORM_INF); + hist.get(0, 0, mBuff); for(int h=0; h