How to extract color patches from 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);
. x
Reminds me of swimming.
Do you understand C++? Does Android not support C++?
Yes, I understand C++. I have worked on some C++ projects. I had posted this same question here From the answer someone has suggested, I am thresholding the S channel and finding contours from it. But I am failing to identity the first first 3 patches, which are of almost same color. Could you advice me any other method/steps for finding contours and then identify the patches?
I took a look at it and didn't really find a general solution to your problem. Perhaps you need to be able to make some guarantees, like the strip will be in the same position and orientation all of the time. That way you can pre-define the 10 regions of interest. You have to think like the computer.
You are right. It seems like I have to add some pattern as background.