want to know the working of the below code [closed]

asked 2013-02-20 05:32:58 -0500

dinesh gravatar image

updated 2020-10-09 13:25:24 -0500

public class ImageManipulationsActivity extends Activity implements CvCameraViewListener { private static final String TAG = "OCVSample::Activity";

public static final int      VIEW_MODE_RGBA      = 0;
public static final int      VIEW_MODE_HIST      = 1;
public static final int      VIEW_MODE_CANNY     = 2;
public static final int      VIEW_MODE_SEPIA     = 3;
public static final int      VIEW_MODE_SOBEL     = 4;
public static final int      VIEW_MODE_ZOOM      = 5;
public static final int      VIEW_MODE_PIXELIZE  = 6;
public static final int      VIEW_MODE_POSTERIZE = 7;

private MenuItem             mItemPreviewRGBA;
private MenuItem             mItemPreviewHist;
private MenuItem             mItemPreviewCanny;
private MenuItem             mItemPreviewSepia;
private MenuItem             mItemPreviewSobel;
private MenuItem             mItemPreviewZoom;
private MenuItem             mItemPreviewPixelize;
private MenuItem             mItemPreviewPosterize;
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 MatOfFloat           mRanges;
private Scalar               mColorsRGB[];
private Scalar               mColorsHue[];
private Scalar               mWhilte;
private Point                mP1;
private Point                mP2;
private float                mBuff[];
private Mat                  mRgbaInnerWindow;
private Mat                  mGrayInnerWindow;
private Mat                  mBlurWindow;
private Mat                  mZoomWindow;
private Mat                  mZoomCorner;
private Mat                  mSepiaKernel;

public static int           viewMode = VIEW_MODE_RGBA;

private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();
            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};

public ImageManipulationsActivity() {
    Log.i(TAG, "Instantiated new " + this.getClass());
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.image_manipulations_surface_view);

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view);
    mOpenCvCameraView.setCvCameraViewListener(this);
}

@Override
public void onPause()
{
    if (mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
    super.onPause();
}

@Override
public void onResume()
{
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
}

public void onDestroy() {
    super.onDestroy();
    if (mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.i(TAG, "called onCreateOptionsMenu");
    mItemPreviewRGBA  = menu.add("Preview RGBA");
    mItemPreviewHist  = menu.add("Histograms");
    mItemPreviewCanny = menu.add("Canny");
    mItemPreviewSepia = menu.add("Sepia");
    mItemPreviewSobel = menu.add("Sobel");
    mItemPreviewZoom  = menu.add("Zoom");
    mItemPreviewPixelize  = menu.add("Pixelize");
    mItemPreviewPosterize = menu.add("Posterize");
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
    if (item == mItemPreviewRGBA)
        viewMode = VIEW_MODE_RGBA;
    if (item == mItemPreviewHist)
        viewMode = VIEW_MODE_HIST;
    else if (item == mItemPreviewCanny)
        viewMode = VIEW_MODE_CANNY;
    else if (item == mItemPreviewSepia)
        viewMode = VIEW_MODE_SEPIA;
    else if (item == mItemPreviewSobel)
        viewMode = VIEW_MODE_SOBEL;
    else if (item == mItemPreviewZoom)
        viewMode = VIEW_MODE_ZOOM;
    else if (item == mItemPreviewPixelize)
        viewMode = VIEW_MODE_PIXELIZE;
    else if (item == mItemPreviewPosterize)
        viewMode = VIEW_MODE_POSTERIZE;
    return true;
}

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);
    mMat0  = new Mat();
    mColorsRGB = new Scalar[] { new Scalar(200, 0, 0, 255), new Scalar(0, 200, 0, 255), new Scalar(0, 0, 200, 255) };
    mColorsHue = new Scalar[] {
            new Scalar(255, 0, 0, 255),   new Scalar(255, 60, 0, 255),  new Scalar(255, 120, 0, 255), new Scalar(255, 180, 0, 255), new Scalar(255, 240, 0, 255),
            new Scalar(215, 213, 0, 255), new Scalar ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by Andrey Pavlenko
close date 2013-02-20 05:56:49.261974