我在 Android 上使用 Google Vision 进行人脸检测。目前我的代码:
public void onPreviewFrame(byte[] data, Camera camera) {
// creating Google Vision frame from a camera frame for face recognition
com.google.android.gms.vision.Frame frame = new com.google.android.gms.vision.Frame.Builder()
.setImageData(ByteBuffer.wrap(data), previewWidth,
previewHeight, ImageFormat.NV21)
.setId(frameId++)
.setRotation(com.google.android.gms.vision.Frame.ROTATION_270)
.setTimestampMillis(lastTimestamp).build();
// recognize the face in the frame
SparseArray<Face> faces = detector.detect(frame);
// wrong coordinates
float x = faces.valueAt(0).getPosition().x;
float y = faces.valueAt(0).getPosition().y;
}
问题是,x
有时y
是不正确的,甚至是消极的。我知道要获得正确的坐标,它应该以某种方式旋转,但究竟如何呢?