Color Detection Using Android Camera

I’m currently embarking on a project for Android cameras that will require me to detect certain colors during preview or after shooting.

I managed to successfully set up a camera with real-time preview and that’s all, but now I am fixated on detecting colors. For example, I would like to identify the green color while previewing the camera and send feedback to the user. This does not have to be done during the preview, as I thought I clicked the photo, and then it would be easier to make color recognition.

I'm a complete newbie in android programming, so it would be grateful for any directions regarding how to code the color detection algorithm!

+7
source share
3 answers

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

+1
source

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

Color capture on Google Play

0
source

You should try this where x and y are 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); 
0
source

All Articles