Reputation: 10353
I use the camera functionality of android and capture the image in the form of a bitmap. I tried to extract an area of a certain color(RED, PINK, BLUE, YELLOW) from the captured image using the following method but was not successful:
for(int i=0;i<bitmap.getWidth();i++){
for(int j=0;j<bitmap.getHeigth();j++){
int pixel = bitmap.getPixel(i,j);
if(pixel == Color.RED){
//create new image
}
}
}
I got to know openCV can be used in this matter. If someone can show me the way it would be greatly appreciated.
Upvotes: 0
Views: 4440
Reputation: 1774
To detect a region in in a specific color you should use the Core.inRange function of opencv.
You can see a code sample here: ANDROID - color detection using openCV - how to?
Upvotes: 1
Reputation: 10852
I think, this task can be solved with some blob library e.g. cvBlob there is android version too cvBlobAndroid.
And when you trying to do it from scratch, it's better to covert image to some more convenient color space e.g. HSV, CIELab, etc.
Also, do not use precise color component values comparsion in condition (A==colorValue)
, use values range comparsion instead (A>minColorValue && A<maxColorValue)
.
Upvotes: 1