使用实时图像处理在Android摄像头中检测激光点的代码 [英] Code to detect laser dot in android camera using realtime image processing

查看:425
本文介绍了使用实时图像处理在Android摄像头中检测激光点的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个代码,在相机
取景器中找到最亮的像素(激光点)l并在该坐标处绘制一个圆圈。

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 will be highly grateful if you can pinpoint error or give your valuable suggestion.

问题:


  1. 正确跟踪点,但坐标不准确(如截图所示)

  2. Fireworks模式不适用于S2但适用于Galaxy Ace。

  3. 应用程序在motorolla安卓手机崩溃

代码+截图
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);
        }


推荐答案

只拍出最亮的像素你从你的截图判断,发现绝对不会帮助你。激光点的大小可能是15×15像素,大部分区域是过饱和的,即所有这些像素都被最大化并且将是最亮的像素。

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".

一个更好的启发式方法可能是,取所有像素的坐标(其中,您的亮度值(假设您可以使用HSL颜色模型))高于给定的阈值,然后计算某种形式加权平均值(每个像素的权重相对于其亮度)。对于测试目的,只计算平均值可能会。

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.

这篇关于使用实时图像处理在Android摄像头中检测激光点的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆