gpt4 book ai didi

android - 如何在 android 中使用 FaceDetector 的相机资源?

转载 作者:行者123 更新时间:2023-11-29 20:03:16 25 4
gpt4 key购买 nike

我想在 android 中使用 FaceDetector。 我用位图图像尝试了 FaceDetector,它工作正常。

(借助于:http://code.tutsplus.com/tutorials/an-introduction-to-face-detection-on-android--cms-25212)

现在,我想在相机开启时检测人脸。文档写道:

Alternatively, a detector may be used within a pipeline structure, in conjunction with sources (e.g., CameraSource) and processors (e.g., LargestFaceFocusingProcessor), enabling you to construct fairly advanced detection pipelines with minimal coding. For example, the code below creates and starts a pipeline that continuously receives preview frames from a camera source for the front facing camera, runs detection on the frames, manages tracking of the most prominent face, and delivers continuous update notifications over time to a developer-defined "FaceTracker" instance.

https://developers.google.com/android/reference/com/google/android/gms/vision/face/FaceDetector

它提供的代码:

detector.setProcessor(
new LargestFaceFocusingProcessor(
detector,
new FaceTracker()));

CameraSource cameraSource = new CameraSource.Builder(context, detector)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedPreviewSize(320, 240)
.build()
.start();

我想在我的代码中实现它:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FaceDetector detector = new FaceDetector.Builder(this)
.setProminentFaceOnly(true)
.build();
detector.setProcessor(
new LargestFaceFocusingProcessor(
detector,
new FaceTracker()));

try {
CameraSource cameraSource = new CameraSource.Builder(this, detector)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedPreviewSize(320, 240)
.build()
.start();
} catch (IOException e) {
e.printStackTrace();
}
}

class FaceTracker extends Tracker
{
public void onDone ()
{

}


}

}

但是,无法前进。你能帮我进一步编码吗?

最佳答案

查看面部跟踪器示例代码,类似。它还处理获取相机权限和 Activity 暂停/恢复:

https://github.com/googlesamples/android-vision/blob/master/visionSamples/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/FaceTrackerActivity.java

你遇到了什么问题?

请注意,“prominentFaceOnly”选项只会检测在相机预览中显得相对较大的人脸(即,人脸占预览图像宽度的 35% 或更多)。

关于android - 如何在 android 中使用 FaceDetector 的相机资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35972523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com