ente/mobile/lib/face/model/face.dart

59 lines
1.4 KiB
Dart
Raw Normal View History

import "package:photos/face/model/detection.dart";
import 'package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart';
class Face {
final int fileID;
final String faceID;
final List<double> embedding;
Detection detection;
final double score;
final double blur;
bool get isBlurry => blur < kLaplacianThreshold;
2024-03-20 09:12:42 +00:00
bool get hasHighScore => score > kMinHighQualityFaceScore;
bool get isHighQuality => (!isBlurry) && hasHighScore;
Face(
this.faceID,
this.fileID,
this.embedding,
this.score,
this.detection,
this.blur,
);
2024-03-19 12:54:46 +00:00
factory Face.empty(int fileID, {bool error = false}) {
return Face(
"$fileID-0",
fileID,
<double>[],
error ? -1.0 : 0.0,
Detection.empty(),
0.0,
);
}
factory Face.fromJson(Map<String, dynamic> json) {
return Face(
json['faceID'] as String,
json['fileID'] as int,
List<double>.from(json['embeddings'] as List),
json['score'] as double,
Detection.fromJson(json['detection'] as Map<String, dynamic>),
// high value means t
(json['blur'] ?? kLapacianDefault) as double,
);
}
Map<String, dynamic> toJson() => {
'faceID': faceID,
'fileID': fileID,
'embeddings': embedding,
'detection': detection.toJson(),
'score': score,
'blur': blur,
};
}