Cleanup
This commit is contained in:
parent
05f188080b
commit
cdd8929bc6
1 changed files with 56 additions and 53 deletions
|
@ -1,11 +1,12 @@
|
|||
import "dart:typed_data";
|
||||
// import "dart:io" show File;
|
||||
// import "dart:typed_data" show Uint8List;
|
||||
|
||||
import "package:logging/logging.dart";
|
||||
import "package:photos/db/files_db.dart";
|
||||
import "package:photos/db/ml_data_db.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import 'package:photos/utils/image_ml_isolate.dart';
|
||||
import "package:photos/utils/thumbnail_util.dart";
|
||||
// import 'package:photos/utils/image_ml_isolate.dart';
|
||||
// import "package:photos/utils/thumbnail_util.dart";
|
||||
|
||||
class FaceSearchService {
|
||||
final _logger = Logger("FaceSearchService");
|
||||
|
@ -24,61 +25,63 @@ class FaceSearchService {
|
|||
return peopleIds;
|
||||
}
|
||||
|
||||
/// Returns the thumbnail associated with a given personId.
|
||||
Future<Uint8List?> getPersonThumbnail(int personID) async {
|
||||
// get the cluster associated with the personID
|
||||
final cluster = await _mlDatabase.getClusterResult(personID);
|
||||
if (cluster == null) {
|
||||
_logger.warning(
|
||||
"No cluster found for personID $personID, unable to get thumbnail.",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
// /// Returns the thumbnail associated with a given personId.
|
||||
// Future<Uint8List?> getPersonThumbnail(int personID) async {
|
||||
// // get the cluster associated with the personID
|
||||
// final cluster = await _mlDatabase.getClusterResult(personID);
|
||||
// if (cluster == null) {
|
||||
// _logger.warning(
|
||||
// "No cluster found for personID $personID, unable to get thumbnail.",
|
||||
// );
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// get the faceID and fileID you want to use to generate the thumbnail
|
||||
final String thumbnailFaceID = cluster.thumbnailFaceId;
|
||||
final int thumbnailFileID = cluster.thumbnailFileId;
|
||||
// // get the faceID and fileID you want to use to generate the thumbnail
|
||||
// final String thumbnailFaceID = cluster.thumbnailFaceId;
|
||||
// final int thumbnailFileID = cluster.thumbnailFileId;
|
||||
|
||||
// get the full file thumbnail
|
||||
final EnteFile enteFile = await _filesDatabase
|
||||
.getFilesFromIDs([thumbnailFileID]).then((value) => value.values.first);
|
||||
final Uint8List? fileThumbnail = await getThumbnail(enteFile);
|
||||
if (fileThumbnail == null) {
|
||||
_logger.warning(
|
||||
"No full file thumbnail found for thumbnail faceID $thumbnailFaceID, unable to get thumbnail.",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
// // get the full file thumbnail
|
||||
// final EnteFile enteFile = await _filesDatabase
|
||||
// .getFilesFromIDs([thumbnailFileID]).then((value) => value.values.first);
|
||||
// final File? fileThumbnail = await getThumbnailForUploadedFile(enteFile);
|
||||
// if (fileThumbnail == null) {
|
||||
// _logger.warning(
|
||||
// "No full file thumbnail found for thumbnail faceID $thumbnailFaceID, unable to get thumbnail.",
|
||||
// );
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// get the face detection for the thumbnail
|
||||
final thumbnailMlResult =
|
||||
await _mlDatabase.getFaceMlResult(thumbnailFileID);
|
||||
if (thumbnailMlResult == null) {
|
||||
_logger.warning(
|
||||
"No face ml result found for thumbnail faceID $thumbnailFaceID, unable to get thumbnail.",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
final detection = thumbnailMlResult.getDetectionForFaceId(thumbnailFaceID);
|
||||
// // get the face detection for the thumbnail
|
||||
// final thumbnailMlResult =
|
||||
// await _mlDatabase.getFaceMlResult(thumbnailFileID);
|
||||
// if (thumbnailMlResult == null) {
|
||||
// _logger.warning(
|
||||
// "No face ml result found for thumbnail faceID $thumbnailFaceID, unable to get thumbnail.",
|
||||
// );
|
||||
// return null;
|
||||
// }
|
||||
// final detection = thumbnailMlResult.getDetectionForFaceId(thumbnailFaceID);
|
||||
|
||||
// create the thumbnail from the full file thumbnail and the face detection
|
||||
Uint8List faceThumbnail;
|
||||
try {
|
||||
faceThumbnail = await ImageMlIsolate.instance.generateFaceThumbnail(
|
||||
fileThumbnail,
|
||||
detection,
|
||||
);
|
||||
} catch (e, s) {
|
||||
_logger.warning(
|
||||
"Unable to generate face thumbnail for thumbnail faceID $thumbnailFaceID, unable to get thumbnail.",
|
||||
e,
|
||||
s,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
// // create the thumbnail from the full file thumbnail and the face detection
|
||||
// Uint8List faceThumbnail;
|
||||
// try {
|
||||
// faceThumbnail = await ImageMlIsolate.instance
|
||||
// .generateFaceThumbnailsForImage(
|
||||
// fileThumbnail.path,
|
||||
// detection,
|
||||
// )
|
||||
// .then((value) => value[0]);
|
||||
// } catch (e, s) {
|
||||
// _logger.warning(
|
||||
// "Unable to generate face thumbnail for thumbnail faceID $thumbnailFaceID, unable to get thumbnail.",
|
||||
// e,
|
||||
// s,
|
||||
// );
|
||||
// return null;
|
||||
// }
|
||||
|
||||
return faceThumbnail;
|
||||
}
|
||||
// return faceThumbnail;
|
||||
// }
|
||||
|
||||
/// Returns all files associated with a given personId.
|
||||
Future<List<EnteFile>> getFilesForPerson(int personID) async {
|
||||
|
|
Loading…
Add table
Reference in a new issue