OpenCV Samples testing problems fixed:

Memory leak in color-blob-detection sample fixed;
Default face size in face-detection is set to 20%;
Error handling improved;
Some possible mat leak fixed;
Manager verison and engine interface version incremented to fix incompatibilities;
Docs updated;
This commit is contained in:
Alexander Smorkalov
2012-10-31 15:20:49 +04:00
parent 78fd99abdb
commit a1a2cb0aeb
17 changed files with 126 additions and 88 deletions

View File

@@ -78,7 +78,8 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
@Override
public void onPause()
{
mOpenCvCameraView.disableView();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
super.onPause();
}
@@ -91,7 +92,8 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
public void onDestroy() {
super.onDestroy();
mOpenCvCameraView.disableView();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
public void onCameraViewStarted(int width, int height) {
@@ -100,7 +102,7 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
mSpectrum = new Mat();
mBlobColorRgba = new Scalar(255);
mBlobColorHsv = new Scalar(255);
SPECTRUM_SIZE = new Size(200, 32);
SPECTRUM_SIZE = new Size(200, 64);
CONTOUR_COLOR = new Scalar(255,0,0,255);
}
@@ -152,6 +154,9 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
mIsColorSelected = true;
touchedRegionRgba.release();
touchedRegionHsv.release();
return false; // don't need subsequent touch events
}
@@ -164,10 +169,10 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
Log.e(TAG, "Contours count: " + contours.size());
Imgproc.drawContours(mRgba, contours, -1, CONTOUR_COLOR);
Mat colorLabel = mRgba.submat(2, 34, 2, 34);
Mat colorLabel = mRgba.submat(4, 68, 4, 68);
colorLabel.setTo(mBlobColorRgba);
Mat spectrumLabel = mRgba.submat(2, 2 + mSpectrum.rows(), 38, 38 + mSpectrum.cols());
Mat spectrumLabel = mRgba.submat(4, 4 + mSpectrum.rows(), 70, 70 + mSpectrum.cols());
mSpectrum.copyTo(spectrumLabel);
}

View File

@@ -22,6 +22,13 @@ public class ColorBlobDetector {
private Mat mSpectrum = new Mat();
private List<MatOfPoint> mContours = new ArrayList<MatOfPoint>();
// Cache
Mat mPyrDownMat = new Mat();
Mat mHsvMat = new Mat();
Mat mMask = new Mat();
Mat mDilatedMask = new Mat();
Mat mHierarchy = new Mat();
public void setColorRadius(Scalar radius) {
mColorRadius = radius;
}
@@ -61,23 +68,17 @@ public class ColorBlobDetector {
}
public void process(Mat rgbaImage) {
Mat pyrDownMat = new Mat();
Imgproc.pyrDown(rgbaImage, mPyrDownMat);
Imgproc.pyrDown(mPyrDownMat, mPyrDownMat);
Imgproc.pyrDown(rgbaImage, pyrDownMat);
Imgproc.pyrDown(pyrDownMat, pyrDownMat);
Imgproc.cvtColor(mPyrDownMat, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL);
Mat hsvMat = new Mat();
Imgproc.cvtColor(pyrDownMat, hsvMat, Imgproc.COLOR_RGB2HSV_FULL);
Mat Mask = new Mat();
Core.inRange(hsvMat, mLowerBound, mUpperBound, Mask);
Mat dilatedMask = new Mat();
Imgproc.dilate(Mask, dilatedMask, new Mat());
Core.inRange(mHsvMat, mLowerBound, mUpperBound, mMask);
Imgproc.dilate(mMask, mDilatedMask, new Mat());
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(dilatedMask, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
Imgproc.findContours(mDilatedMask, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
// Find max contour area
double maxArea = 0;