mirror of
https://github.com/opencv/opencv.git
synced 2024-12-02 07:39:57 +08:00
ColorBlobDetection Sample, ImageManpulations Sample and Tutorial2 updated. Issues with native camera on Nexus 7 (Android 4.1) fixed.
This commit is contained in:
parent
9314e3266c
commit
5acb80a9b1
@ -115,5 +115,5 @@ public class ColorBlobDetector
|
||||
// Color radius for range checking in HSV color space
|
||||
private Scalar mColorRadius = new Scalar(25,50,50,0);
|
||||
private Mat mSpectrum = new Mat();
|
||||
private List<MatOfPoint> mContours = new ArrayList<MatOfPoint>();;
|
||||
private List<MatOfPoint> mContours = new ArrayList<MatOfPoint>();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHol
|
||||
}
|
||||
|
||||
public void setupCamera(int width, int height) {
|
||||
Log.i(TAG, "setupCamera("+width+", "+height+")");
|
||||
Log.i(TAG, "setupCamera("+width+", "+height+")");
|
||||
synchronized (this) {
|
||||
if (mCamera != null && mCamera.isOpened()) {
|
||||
List<Size> sizes = mCamera.getSupportedPreviewSizes();
|
||||
@ -111,11 +111,12 @@ public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHol
|
||||
|
||||
bmp = processFrame(mCamera);
|
||||
}
|
||||
|
||||
|
||||
if (bmp != null) {
|
||||
Canvas canvas = mHolder.lockCanvas();
|
||||
if (canvas != null) {
|
||||
canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()) / 2, null);
|
||||
canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
|
||||
canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()) / 2, null);
|
||||
mHolder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
bmp.recycle();
|
||||
|
@ -127,7 +127,7 @@ class ImageManipulationsView extends SampleCvViewBase {
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_HIST:
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
if (mSizeRgba == null)
|
||||
if ((mSizeRgba == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
int thikness = (int) (mSizeRgba.width / (mHistSizeNum + 10) / 5);
|
||||
if(thikness > 5) thikness = 5;
|
||||
@ -171,7 +171,7 @@ class ImageManipulationsView extends SampleCvViewBase {
|
||||
case ImageManipulationsActivity.VIEW_MODE_CANNY:
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
|
||||
if (mRgbaInnerWindow == null || mGrayInnerWindow == null)
|
||||
if ((mRgbaInnerWindow == null) || (mGrayInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
Imgproc.Canny(mRgbaInnerWindow, mIntermediateMat, 80, 90);
|
||||
Imgproc.cvtColor(mIntermediateMat, mRgbaInnerWindow, Imgproc.COLOR_GRAY2BGRA, 4);
|
||||
@ -181,7 +181,7 @@ class ImageManipulationsView extends SampleCvViewBase {
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
|
||||
|
||||
if (mRgbaInnerWindow == null || mGrayInnerWindow == null)
|
||||
if ((mRgbaInnerWindow == null) || (mGrayInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
|
||||
Imgproc.Sobel(mGrayInnerWindow, mIntermediateMat, CvType.CV_8U, 1, 1);
|
||||
@ -196,7 +196,7 @@ class ImageManipulationsView extends SampleCvViewBase {
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_ZOOM:
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
if (mZoomCorner == null || mZoomWindow == null)
|
||||
if ((mZoomCorner == null) || (mZoomWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
Imgproc.resize(mZoomWindow, mZoomCorner, mZoomCorner.size());
|
||||
|
||||
@ -206,7 +206,7 @@ class ImageManipulationsView extends SampleCvViewBase {
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_PIXELIZE:
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
if (mRgbaInnerWindow == null)
|
||||
if ((mRgbaInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
Imgproc.resize(mRgbaInnerWindow, mIntermediateMat, mSize0, 0.1, 0.1, Imgproc.INTER_NEAREST);
|
||||
Imgproc.resize(mIntermediateMat, mRgbaInnerWindow, mSizeRgbaInner, 0., 0., Imgproc.INTER_NEAREST);
|
||||
@ -214,7 +214,7 @@ class ImageManipulationsView extends SampleCvViewBase {
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_POSTERIZE:
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
if (mRgbaInnerWindow == null)
|
||||
if ((mRgbaInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
/*
|
||||
Imgproc.cvtColor(mRgbaInnerWindow, mIntermediateMat, Imgproc.COLOR_RGBA2RGB);
|
||||
|
@ -10,12 +10,12 @@ import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
|
||||
public class Sample0Base extends Activity {
|
||||
private static final String TAG = "Sample::Activity";
|
||||
|
||||
private static final String TAG = "Sample::Activity";
|
||||
|
||||
private MenuItem mItemPreviewRGBA;
|
||||
private MenuItem mItemPreviewGray;
|
||||
private Sample0View mView;
|
||||
|
||||
private Sample0View mView;
|
||||
|
||||
public Sample0Base() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
|
@ -44,7 +44,7 @@ class Sample2View extends SampleCvViewBase {
|
||||
break;
|
||||
case Sample2NativeCamera.VIEW_MODE_RGBA:
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
Core.putText(mRgba, "OpenCV + Android", new Point(10, 100), 3, 2, new Scalar(255, 0, 0, 255), 3);
|
||||
Core.putText(mRgba, "OpenCV+Android", new Point(10, 50), 3, 1, new Scalar(255, 0, 0, 255), 2);
|
||||
break;
|
||||
case Sample2NativeCamera.VIEW_MODE_CANNY:
|
||||
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
|
||||
|
@ -115,7 +115,8 @@ public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHol
|
||||
if (bmp != null) {
|
||||
Canvas canvas = mHolder.lockCanvas();
|
||||
if (canvas != null) {
|
||||
canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()) / 2, null);
|
||||
canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
|
||||
canvas.drawBitmap(bmp, (canvas.getWidth()-bmp.getWidth()) / 2, (canvas.getHeight()-bmp.getHeight()) / 2, null);
|
||||
mHolder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
bmp.recycle();
|
||||
|
Loading…
Reference in New Issue
Block a user