关于官方消息来源没有找到这些信息......有很多关于如何使用Camera API的例子,但是如何使用Camera2API来处理任何事情......在Stake和所有......上进行的一些讨论......有一个类似的问题,但我有一个问题没有解决。 ..谁有材料如何使用人脸检测相机2 API?
链接到同一quetion: Android camera2 face recognition
我注意到Google's API for Camera 2的例子。
这就是我做什么,但我没有检测到人脸:
我添加的事件
private void createCameraPreviewSession() {
try {
SurfaceTexture texture = mTextureView.getSurfaceTexture();
assert texture != null;
// We configure the size of default buffer to be the size of camera preview we want.
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
// This is the output Surface we need to start preview.
Surface surface = new Surface(texture);
// We set up a CaptureRequest.Builder with the output Surface.
mPreviewRequestBuilder
= mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);
// Here, we create a CameraCaptureSession for camera preview.
mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
if (null == mCameraDevice) {
return;
}
// When the session is ready, we start displaying the preview.
mCaptureSession = cameraCaptureSession;
try {
// ---->> Установка модуля распознания лица
mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE,
CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL);
// Auto focus should be continuous for camera preview.
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
// Flash is automatically enabled when necessary.
setAutoFlash(mPreviewRequestBuilder);
// Finally, we start displaying the camera preview.
mPreviewRequest = mPreviewRequestBuilder.build();
mCaptureSession.setRepeatingRequest(mPreviewRequest,
mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(
@NonNull CameraCaptureSession cameraCaptureSession) {
System.out.println("Failed строка 757");
}
}, null
);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
private CameraCaptureSession.CaptureCallback mCaptureCallback
= new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureProgressed(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull CaptureResult partialResult) {
process(partialResult);
}
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
process(result);
}
private void process(CaptureResult result) {
---> //здесь проверяю получает ли он массив лиц или нет + непонятный мод
Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
if(faces != null && mode != null)
System.out.println("tagDDDDDDDDDDDDDDDDDDDDDDDD" + "faces : " +
faces.length + " , mode : " + mode);
switch (mState) {
case STATE_PREVIEW: {
// We have nothing to do when the camera preview is working normally.
// Here i set Face Detection
mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE,
CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL);
break;
}
我在这里检查面的最大计数该相机可以得到
private void setUpCameraOutputs(int width, int height) {
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);
// We don't use a front facing camera in this sample.
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
continue;
}
max_count = characteristics.get(
CameraCharacteristics.STATISTICS_INFO_MAX_FACE_COUNT);
modes = characteristics.get(
CameraCharacteristics.STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES);
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! max_count " + max_count + " modes " + modes);
**输出为:**
I/System.out: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! max_count 16 modes [[email protected]
**这是一个什么样的打印日志**
03-08 18:34:07.018 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.048 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.078 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.118 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.148 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.178 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.218 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.258 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.288 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.308 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
03-08 18:34:07.348 7405-7438/com.example.android.camera2basic I/System.out: tagDDDDDDDDDDDDDDDDDDDDDDDDfaces : 0 , mode : 1
为什么它不reterning脸?如果有人有正确的工作范例,请给予链接。我如何使用camera2API进行人脸检测。在整个星期内,我无法理解((
你读过这里的android开发者信息:http://developer.android.com/reference/android/hardware/camera2/package-summary.html? –
是的,但它只是一般的描述...它如何在人脸检测相机2 API halp我? –
这些帮助吗? 1)https://developer.qualcomm.com/software/snapdragon-sdk-android/facial-recognition/user-guide(2)http://code.tutsplus.com/tutorials/an-introduction-to-face- detection-on-android - cms-25212(3)http://androidbite.blogspot.in/2012/11/android-face-detection-example.html – Stallion