và tọa độ của mỗi mắt và miệng:
camera.setFaceDetectionListener (FaceDetectionListener mới () {public void onFaceDetection (Face [] khuôn mặt, máy ảnh Camera) {if (faces.length> 0) {
Log.d ( "FaceDetection", " khuôn mặt được phát hiện: "+ faces.length +
" Face 1 Địa X: "+ khuôn mặt [0] .rect.centerX () +
" Y: "+ khuôn mặt [0] .rect.centerY ());
}
}
});
để bắt đầu phát hiện và theo dõi khuôn mặt, gọi phương thức startFaceDetection của camera. . Điều này phải được gọi mỗi khi bạn bắt đầu (hoặc khởi động lại) xem trước máy ảnh, vì nó sẽ tự động dừng lại bất cứ khi nào xem trước kết thúc
public void surfaceCreated (chủ SurfaceHolder) {try {
camera.setPreviewDisplay (chủ);
camera.startPreview ();
camera.startFaceDetection ();
// TODO Vẽ qua bản xem trước nếu có yêu cầu.
} catch (IOException e) {
Log.d (TAG, "IO ngoại lệ", e);
}
}
Bạn có thể ngừng nhận diện khuôn mặt bằng cách gọi stopFaceDetection:
public void surfaceDestroyed (chủ SurfaceHolder) {camera.stopFaceDetection ();
camera.stopPreview ();
}
Hít một hình
Sau khi bạn đã cấu hình các cài đặt máy ảnh, và một bản xem trước đang hoạt động, bạn có thể chụp ảnh bằng cách gọi takePicture vào đối tượng máy ảnh và đi qua trong một ShutterCallback và hai triển khai PictureCallback (một cho RAW và một cho hình ảnh JPEG-mã hóa). Mỗi cuộc gọi lại hình ảnh sẽ nhận được một mảng byte đại diện cho hình ảnh trong các định dạng thích hợp, trong khi gọi lại chụp được kích hoạt ngay lập tức sau khi chụp được đóng lại.
Liệt kê 15-27 cho thấy mã bộ xương cho chụp ảnh và lưu lại hình ảnh JPEG với một thẻ SD .
đang được dịch, vui lòng đợi..