我编写了一个代码来在相机取景器中找到最亮的像素(激光点)l,并在该坐标处画一个圆。
理想情况下,圆圈应该在点上。但由于一些问题(可能是屏幕分辨率/编码错误),圆圈有点移位。
我附上截图和代码。
如果您能指出错误或提出宝贵的建议,我将不胜感激。
问题:
- 点被正确跟踪,但坐标不准确(如屏幕截图所示)
- Fireworks 模式不适用于 S2,但适用于 Galaxy Ace。
- 该应用程序在摩托罗拉安卓手机中崩溃
代码+截图 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);
}