Code to detect laser dot in android camera using realtime image processing

0

I have written a code to find brightest pixe(laser dot)l in camera viewfinder and draw a circle at that coordinate.

Ideally the circle should be on dot. but due to some prob(maybe screen resolution/coding error) the circle is a little displaced.

I am attaching the screenshots and code.

I will be highly grateful if you can pinpoint error or give your valuable suggestion.

Problems:

  1. The dot is tracked properly but coordinates arent exact(as seem in screenshots)
  2. The Fireworks mode doesn't work on S2 but works on Galaxy Ace.
  3. The app crashes in motorolla android phone

Code+Screenshot http://wikisend.com/download/553910/re41postqueryregardingdecodeyuv420spmrgbdatamyuvd.zip

 protected void onDraw(Canvas canvas) {
        if (mBitmap != null)
        {
            int canvasWidth = canvas.getWidth();
            int canvasHeight = canvas.getHeight();
            int newImageWidth = canvasWidth;
            int marginWidth = (canvasWidth - newImageWidth)/2;

            // Convert from YUV to RGB
            decodeYUV420SP(mRGBData, mYUVData, mImageWidth, mImageHeight);

                int maxR=255;x=0;y=0; int k=0;
            for (int i = 0; i < mRGBData.length; i++) {
                    if((((mRGBData[i] >> 16) & 0x000000FF)+((mRGBData[i] >> 8) & 0x000000FF)+((mRGBData[i]) & 0x000000FF))>maxR)
                    {
                        maxR=(mRGBData[i] >> 16) & 0x000000FF;
                        maxR+=(mRGBData[i] >> 8) & 0x000000FF;
                        maxR+=(mRGBData[i] ) & 0x000000FF;
                        y=i%mImageWidth;
                        x=i/(mImageWidth);
                    }
                }
                String status= "Laser coords: ("+maxR+", "+y+")";

                canvas.drawText(status, marginWidth+10, 60, mPaintYellow);
                canvas.drawCircle(y, x, 10, mPaintYellow);
                           }
           super.onDraw(canvas);
        }
java
android
image-processing
asked on Stack Overflow Sep 6, 2012 by user1568701 • edited Sep 6, 2012 by user1568701

1 Answer

0

Just taking the brightest pixel you find will most definitely not help you, judging from your screenshot. The laserdot there ist probably 15x15 pixels large, with most of the area being oversaturated, i.e. all of those pixels are maxed out and will be "the brightest pixel".

A better heuristic would probably be, to take the coordinates of all pixels whose brightnessvalue (assuming you can use the HSL colormodel) is above a given threshold and then calculate some form of weighted average (with the weight of each pixel being relative to its brightness). For testingpurposes just calculating the average would probably do.

answered on Stack Overflow Sep 10, 2012 by rincewound

User contributions licensed under CC BY-SA 3.0