android - 从实时视频中提取视频帧以在 android 中进行实时面部地标分析
问题描述
我正在使用 android 的 ML Kit 构建一个实时面部地标检测应用程序。目前,我可以使用 android camerax 库捕获视频。为了对捕获的视频启用实时面部标志检测,我需要提取视频帧并将帧传递给 ML Kit 面部标志检测功能,该功能将处理和检测视频中存在的标志。
我附上了下面的代码片段。有人可以帮我提取视频帧吗?如果还有其他方法,请告诉我。
谢谢你。
btnVideo.setOnClickListener(v -> {
if(mCameraView.isRecording()){return;}
SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
File file = new File(getBatchDirectoryName(), mDateFormat.format(new Date()) + ".mp4");
mCameraView.setCaptureMode(CameraView.CaptureMode.VIDEO);
InputImage image = InputImage.fromBitmap(bitmap, rotationDegree);
FaceDetectorOptions highAccuracyOpts =
new FaceDetectorOptions.Builder()
.setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_ACCURATE)
.setLandmarkMode(FaceDetectorOptions.LANDMARK_MODE_ALL)
.setContourMode(FaceDetectorOptions.CONTOUR_MODE_ALL)
.setClassificationMode(FaceDetectorOptions.CLASSIFICATION_MODE_ALL)
.build();
FaceDetector detector = FaceDetection.getClient(highAccuracyOpts);
Task<List<Face>> result =
detector.process(image)
.addOnSuccessListener(
new OnSuccessListener<List<Face>>() {
@Override
public void onSuccess(List<Face> faces) {
for (Face face : faces) {
Rect bounds = face.getBoundingBox();
float rotY = face.getHeadEulerAngleY();
float rotZ = face.getHeadEulerAngleZ();
FaceLandmark leftEar = face.getLandmark(FaceLandmark.LEFT_EAR);
if (leftEar != null) {
PointF leftEarPos = leftEar.getPosition();
}
List<PointF> leftEyeContour =
face.getContour(FaceContour.LEFT_EYE).getPoints();
List<PointF> upperLipBottomContour =
face.getContour(FaceContour.UPPER_LIP_BOTTOM).getPoints();
if (face.getSmilingProbability() != null) {
float smileProb = face.getSmilingProbability();
}
if (face.getRightEyeOpenProbability() != null) {
float rightEyeOpenProb = face.getRightEyeOpenProbability();
}
if (face.getTrackingId() != null) {
int id = face.getTrackingId();
}
}
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
mCameraView.startRecording(file, executor, new VideoCapture.OnVideoSavedCallback() {
@Override
public void onVideoSaved(@NonNull OutputFileResults outputFileResults) {
galleryAddPic(file, 1);
}
@Override
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
//Log.i("TAG",message);
mCameraView.stopRecording();
}
});
});
解决方案
推荐阅读
- outlook - Outlook 加载项自定义命令行开关
- c++ - 如何在 C++ 中格式化 SQL 查询的输出?
- spring-boot - 使用 Keycloak 的服务到服务身份验证
- python - 转换熊猫数据框后将HTML表格插入页面
- javascript - 即使标记的数组为空,谷歌地图标记也不会删除
- node.js - 我应该使用 req.user 还是 req.session.passport
- python - gitpython 修剪本地分支
- sql - INSERT DELETE 后的 SQL 触发器以进行编号
- postgresql - PostgreSql 更新 RAISE_NOTICE 在 UPDATE 之前运行
- r - 考虑到每个东西运行了多长时间;计算随着时间的推移运行的事物的总数?