Nyaato
Nyaato

Reputation: 107

Color Detection Using Android Camera

currently embarking on a project regarding android cameras that would require me to detect certain colours during live preview or after the picture is taken.

I've managed to successfully set up the camera with live preview and all, but I'm currently stuck at detecting the colours. For example, I would like to detect green colour during the camera's live preview and send a feedback to the user. It doesn't necessarily need to be done during live preview, as I've been thinking that snapping a photo, then doing the colour detection could be accomplished in an easier manner.

I'm a complete newbie about android programming, so any kind of direction regarding how to code out the colour detection algorithm would be greatly appreciated!

Upvotes: 8

Views: 14549

Answers (3)

WSS
WSS

Reputation: 513

If you want to go for simple method then get bitmap image from camera and use bitmap.getpixel(int x,int y) to get the color and compare the pixels with the color that you want

Upvotes: 1

Satyavrat
Satyavrat

Reputation: 469

You should try this where x and y is the pixel position

int frameHeight = camera.getParameters().getPreviewSize().height;
int frameWidth = camera.getParameters().getPreviewSize().width;
int rgb[] = new int[frameWidth * frameHeight];
decodeYUV420SP(rgb, data, frameWidth, frameHeight);
Bitmap bmp = Bitmap.createBitmap(rgb, frameWidth, frameHeight, Config.ARGB_8888);
int pixel = bmp.getPixel( x,y );
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
int thiscolor = Color.rgb(redValue, greenValue, blueValue);

Upvotes: 0

Becka Archer
Becka Archer

Reputation: 21

"Color Grab" is an Android application that does what you need. The app has the best color detection/recognition algorithm and it works perfectly.You can check out how it works.

Color Grab on Google Play

Upvotes: 1

Related Questions