Merge branch 'memoriesMetadata' of https://github.com/matiasdelellis/memories into matiasdelellis-memoriesMetadata

pull/783/head
Varun Patil 2023-08-16 08:25:50 -07:00
commit ea11e8d984
5 changed files with 34 additions and 18 deletions

View File

@ -120,18 +120,14 @@ class FaceRecognitionBackend extends Backend
'y' => (float) $row['face_y'] / $row['image_height'], 'y' => (float) $row['face_y'] / $row['image_height'],
]; ];
unset($row['face_x'], $row['face_y'], $row['face_w'], $row['face_h'], $row['image_height'], $row['image_width']); unset($row['face_x'], $row['face_y'], $row['face_width'], $row['face_height'], $row['image_height'], $row['image_width']);
} }
public function getClustersInternal(int $fileid = 0): array public function getClustersInternal(int $fileid = 0): array
{ {
if ($fileid) {
throw new \Exception('FaceRecognitionBackend: fileid filter not implemented');
}
$faces = array_merge( $faces = array_merge(
$this->getFaceRecognitionPersons(), $this->getFaceRecognitionPersons($fileid),
$this->getFaceRecognitionClusters() $this->getFaceRecognitionClusters($fileid)
); );
// Post process // Post process
@ -161,7 +157,6 @@ class FaceRecognitionBackend extends Backend
'frf.height', 'frf.height',
'm.w as image_width', // Scoring 'm.w as image_width', // Scoring
'm.h as image_height', 'm.h as image_height',
'frf.confidence',
'm.fileid', 'm.fileid',
'm.datetaken', // Just in case, for postgres 'm.datetaken', // Just in case, for postgres
)->from('facerecog_faces', 'frf'); )->from('facerecog_faces', 'frf');
@ -225,7 +220,12 @@ class FaceRecognitionBackend extends Backend
return (int) $this->config->getAppValue('facerecognition', 'model', -1); return (int) $this->config->getAppValue('facerecognition', 'model', -1);
} }
private function getFaceRecognitionClusters(bool $show_singles = false, bool $show_hidden = false) private function minFaceInClusters(): int
{
return (int) $this->config->getAppValue('facerecognition', 'min_faces_in_cluster', 5);
}
private function getFaceRecognitionClusters(int $fileid = 0)
{ {
$query = $this->tq->getBuilder(); $query = $this->tq->getBuilder();
@ -255,13 +255,14 @@ class FaceRecognitionBackend extends Backend
$query->addGroupBy('frp.user'); $query->addGroupBy('frp.user');
$query->where($query->expr()->isNull('frp.name')); $query->where($query->expr()->isNull('frp.name'));
// By default hides individual faces when they have no name. // The query change if we want the people in an fileid, or the unnamed clusters
if (!$show_singles) { if ($fileid > 0) {
$query->having($query->expr()->gt($count, $query->expr()->literal(1, \PDO::PARAM_INT))); // WHERE these clusters contain fileid if specified
} $query->andWhere($query->expr()->eq('fri.file', $query->createNamedParameter($fileid)));
} else {
// By default it shows the people who were not hidden // WHERE these clusters has a minimum number of faces
if (!$show_hidden) { $query->having($query->expr()->gte($count, $query->expr()->literal($this->minFaceInClusters(), \PDO::PARAM_INT)));
// WHERE these clusters were not hidden due inconsistencies
$query->andWhere($query->expr()->eq('frp.is_visible', $query->expr()->literal(1))); $query->andWhere($query->expr()->eq('frp.is_visible', $query->expr()->literal(1)));
} }
@ -276,7 +277,7 @@ class FaceRecognitionBackend extends Backend
return $this->tq->executeQueryWithCTEs($query)->fetchAll() ?: []; return $this->tq->executeQueryWithCTEs($query)->fetchAll() ?: [];
} }
private function getFaceRecognitionPersons() private function getFaceRecognitionPersons(int $fileid = 0)
{ {
$query = $this->tq->getBuilder(); $query = $this->tq->getBuilder();
@ -303,6 +304,12 @@ class FaceRecognitionBackend extends Backend
// GROUP by name of face clusters // GROUP by name of face clusters
$query->where($query->expr()->isNotNull('frp.name')); $query->where($query->expr()->isNotNull('frp.name'));
// WHERE these clusters contain fileid if specified
if ($fileid > 0) {
$query->andWhere($query->expr()->eq('fri.file', $query->createNamedParameter($fileid)));
}
$query->groupBy('frp.user'); $query->groupBy('frp.user');
$query->addGroupBy('frp.name'); $query->addGroupBy('frp.name');

View File

@ -352,6 +352,9 @@ export default defineComponent({
}, },
people(): IFace[] { people(): IFace[] {
if (this.routeIsFaceRecognition)
return this.baseInfo?.clusters?.facerecognition ?? [];
else
return this.baseInfo?.clusters?.recognize ?? []; return this.baseInfo?.clusters?.recognize ?? [];
}, },
}, },
@ -367,6 +370,7 @@ export default defineComponent({
const clusters = [ const clusters = [
this.config.albums_enabled ? 'albums' : null, this.config.albums_enabled ? 'albums' : null,
this.config.recognize_enabled ? 'recognize' : null, this.config.recognize_enabled ? 'recognize' : null,
this.config.facerecognition_enabled ? 'facerecognition' : null,
] ]
.filter((c) => c) .filter((c) => c)
.join(','); .join(',');

View File

@ -31,6 +31,9 @@ export default defineComponent({
routeIsRecognizeUnassigned(): boolean { routeIsRecognizeUnassigned(): boolean {
return this.routeIsRecognize && this.$route.params.name === constants.FACE_NULL; return this.routeIsRecognize && this.$route.params.name === constants.FACE_NULL;
}, },
routeIsFaceRecognition(): boolean {
return this.$route.name === 'facerecognition';
},
routeIsArchive(): boolean { routeIsArchive(): boolean {
return this.$route.name === 'archive'; return this.$route.name === 'archive';
}, },

View File

@ -109,6 +109,7 @@ export interface IImageInfo {
clusters?: { clusters?: {
albums?: IAlbum[]; albums?: IAlbum[];
recognize?: IFace[]; recognize?: IFace[];
facerecognition?: IFace[];
}; };
} }

View File

@ -17,6 +17,7 @@ declare module 'vue' {
routeIsPeople: boolean; routeIsPeople: boolean;
routeIsRecognize: boolean; routeIsRecognize: boolean;
routeIsRecognizeUnassigned: boolean; routeIsRecognizeUnassigned: boolean;
routeIsFaceRecognition: boolean;
routeIsArchive: boolean; routeIsArchive: boolean;
routeIsPlaces: boolean; routeIsPlaces: boolean;
routeIsMap: boolean; routeIsMap: boolean;