Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to extract color patches from this image?

Hello I am knew to OpenCV. I have just started developing with Android and OpenCV. I have an image as given below. I need to extract those ten square color patches from it. What method(s)/procedure should I follow? I tried the following code snppet I got from a book. But it is not giving me the desired results.

Mat mRgba = new Mat();;

    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat heirarchy = new Mat();

    Bitmap actualImage32 = actualImage.copy(Bitmap.Config.ARGB_8888, true);
    Utils.bitmapToMat(actualImage32, mRgba);

    List<MatOfPoint> contourList = new ArrayList<MatOfPoint>();//List of all contours

    //image to grayscale
    Imgproc.cvtColor(mRgba,grayMat,Imgproc.COLOR_BGR2GRAY);

    Imgproc.Canny(grayMat,cannyEdges,10,100);

    //find contours
    Imgproc.findContours(cannyEdges,contourList,heirarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);

    //Drawing contours on new Image
    Mat contours = new Mat();
    contours.create(cannyEdges.rows(),cannyEdges.cols(), CvType.CV_8UC3);
    Random r = new Random();

    for(int i = 0;i<contourList.size();i++){
        Imgproc.drawContours(contours,contourList,i,new Scalar(r.nextInt(255),r.nextInt(255),r.nextInt(255),-1));
    }
    //Converting Mat back back to Bitmap
    //Utils.matToBitmap(contours,***************);
    //loadImagetoImageView();
    Utils.matToBitmap(contours, actualImage);
    ImageView imgView = (ImageView) findViewById(R.id.strip_image);
    imgView.setImageBitmap(actualImage);

image description. x

How to extract color patches from this image?

Hello I am knew to OpenCV. I have just started developing with Android and OpenCV. I have an image as given below. I need to extract those ten square color patches from it. What method(s)/procedure should I follow? I tried the following code snppet I got from a book. But it is not giving me the desired results.

Mat mRgba = new Mat();;

    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat heirarchy = new Mat();

    Bitmap actualImage32 = actualImage.copy(Bitmap.Config.ARGB_8888, true);
    Utils.bitmapToMat(actualImage32, mRgba);

    List<MatOfPoint> contourList = new ArrayList<MatOfPoint>();//List of all contours

    //image to grayscale
    Imgproc.cvtColor(mRgba,grayMat,Imgproc.COLOR_BGR2GRAY);

    Imgproc.Canny(grayMat,cannyEdges,10,100);

    //find contours
    Imgproc.findContours(cannyEdges,contourList,heirarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);

    //Drawing contours on new Image
    Mat contours = new Mat();
    contours.create(cannyEdges.rows(),cannyEdges.cols(), CvType.CV_8UC3);
    Random r = new Random();

    for(int i = 0;i<contourList.size();i++){
        Imgproc.drawContours(contours,contourList,i,new Scalar(r.nextInt(255),r.nextInt(255),r.nextInt(255),-1));
    }
    //Converting Mat back back to Bitmap
    //Utils.matToBitmap(contours,***************);
    //loadImagetoImageView();
    Utils.matToBitmap(contours, actualImage);
    ImageView imgView = (ImageView) findViewById(R.id.strip_image);
    imgView.setImageBitmap(actualImage);

image description. x

How to extract color patches from this image?

Hello I am knew to OpenCV. I have just started developing with Android and OpenCV. I have an image as given below. I need to extract those ten square color patches from it. What method(s)/procedure should I follow? I tried the following code snppet I got from a book. But it is not giving me the desired results.

Mat mRgba = new Mat();;

    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat heirarchy = new Mat();

    Bitmap actualImage32 = actualImage.copy(Bitmap.Config.ARGB_8888, true);
    Utils.bitmapToMat(actualImage32, mRgba);

    List<MatOfPoint> contourList = new ArrayList<MatOfPoint>();//List of all contours

    //image to grayscale
    Imgproc.cvtColor(mRgba,grayMat,Imgproc.COLOR_BGR2GRAY);

    Imgproc.Canny(grayMat,cannyEdges,10,100);

    //find contours
    Imgproc.findContours(cannyEdges,contourList,heirarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);

    //Drawing contours on new Image
    Mat contours = new Mat();
    contours.create(cannyEdges.rows(),cannyEdges.cols(), CvType.CV_8UC3);
    Random r = new Random();

    for(int i = 0;i<contourList.size();i++){
        Imgproc.drawContours(contours,contourList,i,new Scalar(r.nextInt(255),r.nextInt(255),r.nextInt(255),-1));
    }
    //Converting Mat back back to Bitmap
    //Utils.matToBitmap(contours,***************);
    //loadImagetoImageView();
    Utils.matToBitmap(contours, actualImage);
    ImageView imgView = (ImageView) findViewById(R.id.strip_image);
    imgView.setImageBitmap(actualImage);

image description. x