Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Color changing the object in Android application

Basically my goal is change the color of object in real time for paint application. To achieve this goal i follow the following concepts 1. i use the canny() metod for finding the object. 2. Using contorous for edge detection. 3. using flodfill() for coloring thr object.

If there is any other concept require to achieve the goal please suggest me.

I have tried but not getting exact

controus edge. original input

original  image

image description

my code is here:

package com.example.imageprocess;

import java.util.ArrayList;
import java.util.List;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

public class MainActivity extends Activity implements CvCameraViewListener2{


        private Mat                    mRgba;
        private Mat                    mIntermediateMat;
        private Mat                    mGray;

        private CameraBridgeViewBase   mOpenCvCameraView;

        private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                    case LoaderCallbackInterface.SUCCESS:
                    {
                        Log.i("OPENCVACTIVITY", "OpenCV loaded successfully");

                        // Load native library after(!) OpenCV initialization
                       // System.loadLibrary("mixed_sample");

                        mOpenCvCameraView.enableView();
                    } break;
                    default:
                    {
                        super.onManagerConnected(status);
                    } break;
                }
            }
        };

       /* public MainActivity() {
            Log.i("OPENCVACTIVITY", "Instantiated new " + this.getClass());
        }
*/
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
          getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            setContentView(R.layout.activity_main);

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



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

    @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 void onCameraViewStarted(int width, int height) {
        // TODO Auto-generated method stub
         mRgba = new Mat(height, width, CvType.CV_8UC4);
            mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
            mGray = new Mat(height, width, CvType.CV_8UC1);

    }

    @Override
    public void onCameraViewStopped() {
         mRgba.release();
            mGray.release();
            mIntermediateMat.release();

    }

    @Override
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        Mat gaussian_output = new Mat();
         mRgba = inputFrame.rgba();
         Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100);
         Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
         Imgproc.GaussianBlur(mIntermediateMat, gaussian_output, new Size(5, 5), 5);

         List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
         Log.i("CONTROUS", "Contours");
         Mat gray = new Mat(gaussian_output.size(),CvType.CV_8UC1);
         Imgproc.findContours(gray, contours, new Mat(), Imgproc.RETR_LIST,
                 Imgproc.CHAIN_APPROX_SIMPLE);
         Imgproc.drawContours(gray, contours,1, new Scalar(0,255,0));
         Log.i("Controus done","Contours done");

         //if no contours are detected
         if(contours.size() == 0){
             Log.i("Controus","contour size is 0");
         }
            // return ;

         /// Find contours
         //findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
        return mRgba;
    }


}

Color changing the object in Android application

Basically my goal is change the color of object in real time for paint application. To achieve this goal i follow the following concepts 1. i use the canny() metod for finding the object. 2. Using contorous for edge detection. 3. using flodfill() for coloring thr object.

If there is any other concept require to achieve the goal please suggest me.

I have tried but not getting exact

controus edge. original input

original  image original image

image description

my code is here:

package com.example.imageprocess;

import java.util.ArrayList;
import java.util.List;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

public class MainActivity extends Activity implements CvCameraViewListener2{


        private Mat                    mRgba;
        private Mat                    mIntermediateMat;
        private Mat                    mGray;

        private CameraBridgeViewBase   mOpenCvCameraView;

        private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                    case LoaderCallbackInterface.SUCCESS:
                    {
                        Log.i("OPENCVACTIVITY", "OpenCV loaded successfully");

                        // Load native library after(!) OpenCV initialization
                       // System.loadLibrary("mixed_sample");

                        mOpenCvCameraView.enableView();
                    } break;
                    default:
                    {
                        super.onManagerConnected(status);
                    } break;
                }
            }
        };

       /* public MainActivity() {
            Log.i("OPENCVACTIVITY", "Instantiated new " + this.getClass());
        }
*/
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
          getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            setContentView(R.layout.activity_main);

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



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

    @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 void onCameraViewStarted(int width, int height) {
        // TODO Auto-generated method stub
         mRgba = new Mat(height, width, CvType.CV_8UC4);
            mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
            mGray = new Mat(height, width, CvType.CV_8UC1);

    }

    @Override
    public void onCameraViewStopped() {
         mRgba.release();
            mGray.release();
            mIntermediateMat.release();

    }

    @Override
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        Mat gaussian_output = new Mat();
         mRgba = inputFrame.rgba();
         Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100);
         Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
         Imgproc.GaussianBlur(mIntermediateMat, gaussian_output, new Size(5, 5), 5);

         List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
         Log.i("CONTROUS", "Contours");
         Mat gray = new Mat(gaussian_output.size(),CvType.CV_8UC1);
         Imgproc.findContours(gray, contours, new Mat(), Imgproc.RETR_LIST,
                 Imgproc.CHAIN_APPROX_SIMPLE);
         Imgproc.drawContours(gray, contours,1, new Scalar(0,255,0));
         Log.i("Controus done","Contours done");

         //if no contours are detected
         if(contours.size() == 0){
             Log.i("Controus","contour size is 0");
         }
            // return ;

         /// Find contours
         //findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
        return mRgba;
    }


}