android - 使用nexus 4 点leftEye 和rightEye 坐标返回null。Nexus 4 不支持吗?

标签 android null android-camera coordinates nexus-4

我正在尝试获取 leftEye 和 rightEye 的坐标,并从 leftEye 到 rightEye 画一条线,但返回的坐标为空。我正在使用 Nexus 4 来测试应用程序。 Nexus 4 不支持这个功能??我可以毫无问题地在检测到的人脸周围画一个矩形。 作为引用,我附上了用于检测眼睛坐标的代码。

try{
         float x1 = detectedFaces[i].leftEye.x;
         float y1 = detectedFaces[i].leftEye.y;
         float x2 = detectedFaces[i].rightEye.y;
         float y2 = detectedFaces[i].rightEye.y;

         //Converting from driver coordinate to view coordinate
         float Xx1 = (x1+1000) * vWidth/2000;
         float Yy1  = (y1+1000) * vHeight/2000;
         float Xx2 = (x2+1000) * vWidth/2000;
         float Yy2  = (y2+1000) * vHeight/2000;

         canvas.drawLine(Xx1, Yy1, Xx2, Yy2, drawingPaint);
         }
         catch(Exception e){
             Log.e(TAG, "Error: " +e.getMessage());
         }

日志

11-15 16:37:52.895: E/Take_Picture(1304): Error: null
11-15 16:37:53.115: E/Take_Picture(1304): Error: null
11-15 16:37:53.286: E/Take_Picture(1304): Error: null

最佳答案

阅读 Android 引用:“这是一个可选字段,可能并非所有设备都支持。如果不支持,该值将始终设置为空。”

我已经在多种设备(Nexus 4 和 5、Samsung Galaxy S4 和 S5、Sony Experia、HTC One 等)上进行了测试,但从未成功。对于 Google 的 Android 开发团队来说,这可能是个好问题。

您的选择是使用 OpenCv 库(http://opencv.org/platforms/android.html)。

另一种选择是在拍照后进行检测,而不是使用 FaceDetector 类进行实时检测,不确定您是否希望进行实时检测。

看一个例子:

public class TutorialOnFaceDetect1 extends Activity {
private MyImageView mIV;
private Bitmap mFaceBitmap;
private int mFaceWidth = 200;
private int mFaceHeight = 200;   
private static final int MAX_FACES = 10;
private static String TAG = "TutorialOnFaceDetect";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mIV = new MyImageView(this);
    setContentView(mIV, new LayoutParams(LayoutParams.WRAP_CONTENT,    LayoutParams.WRAP_CONTENT));       

    // load the photo
    Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.face3); 
    mFaceBitmap = b.copy(Bitmap.Config.RGB_565, true); 
    b.recycle();

    mFaceWidth = mFaceBitmap.getWidth();
    mFaceHeight = mFaceBitmap.getHeight();  
    mIV.setImageBitmap(mFaceBitmap); 

    // perform face detection and set the feature points
    setFace();

    mIV.invalidate();
}

public void setFace() {
    FaceDetector fd;
    FaceDetector.Face [] faces = new FaceDetector.Face[MAX_FACES];
    PointF midpoint = new PointF();
    int [] fpx = null;
    int [] fpy = null;
    int count = 0;

    try {
        fd = new FaceDetector(mFaceWidth, mFaceHeight, MAX_FACES);        
        count = fd.findFaces(mFaceBitmap, faces);
    } catch (Exception e) {
        Log.e(TAG, "setFace(): " + e.toString());
        return;
    }

    // check if we detect any faces
    if (count > 0) {
        fpx = new int[count];
        fpy = new int[count];

        for (int i = 0; i < count; i++) { 
            try {                 
                faces[i].getMidPoint(midpoint);                  

                fpx[i] = (int)midpoint.x;
                fpy[i] = (int)midpoint.y;
            } catch (Exception e) { 
                Log.e(TAG, "setFace(): face " + i + ": " + e.toString());
            }            
        }      
    }

    mIV.setDisplayPoints(fpx, fpy, count, 0);
} 

关于android - 使用nexus 4 点leftEye 和rightEye 坐标返回null。Nexus 4 不支持吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19997134/

相关文章:

android - 谷歌 Nexus 7 表明它没有摄像头

android - 如何使用 appcompat v21 在独立工具栏上启用 homeAsUp 或调用 setDisplayHomeAsUpEnabled()

android - 是否可以从同一网络上的另一台设备访问部署在 Android 手机上的 HTTP 服务器?

null - Spring 集成 - 究竟是谁 "iterates"来自拆分器的拆分消息?

java - Android 无法捕获图像

android - 保存图片 EXTRA_OUPUT 为空 onActivityResult

java - 如何以编程方式创建图层列表可绘制对象?

android - 在 android 的启动画面中缩小动画?

c++ - 检查数组位置是否为空/空

MySQL COUNT NULL 内容按列,GROUP 按列