Skip to content

Commit

Permalink
Merge pull request #1240 from nextcloud/fix/faces-avoid-edge
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelklehr authored Sep 14, 2022
2 parents 535da6c + 1718fbe commit 7cad5e8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-src_views_FaceContent_vue.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-src_views_FaceContent_vue.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-src_views_Faces_vue.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-src_views_Faces_vue.js.map

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions src/mixins/FaceCoverMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,33 @@ export default {

methods: {
getFaceCover(faceName) {
return (this.facesFiles[faceName] || [])
.slice(0, 25)
.map(fileId => this.files[fileId])
.map(file => ({ ...file, faceDetections: JSON.parse(he.decode(file.faceDetections)) }))
// sort larges face first
.sort((a, b) =>
b.faceDetections.find(d => d.title === faceName).width
- a.faceDetections.find(d => d.title === faceName).width
)
// sort fewest face detections first
.sort((a, b) =>
a.faceDetections.length
- b.faceDetections.length
)[0]
// Give high scores for faces that intersect with the edge of the picture (with a margin of half the face size)
const scoreFacePosition = (faceDetection) => {
return Math.max(0, -1 * (faceDetection.x - faceDetection.width * 0.5))
+ Math.max(0, -1 * (faceDetection.y - faceDetection.height * 0.5))
+ Math.max(0, -1 * (1 - (faceDetection.x + faceDetection.width) - faceDetection.width * 0.5))
+ Math.max(0, -1 * (1 - (faceDetection.y + faceDetection.height) - faceDetection.height * 0.5))
}

return (this.facesFiles[faceName] || [])
.slice(0, 25)
.map(fileId => this.files[fileId])
.map(file => ({ ...file, faceDetections: JSON.parse(he.decode(file.faceDetections)) }))
// sort larges face first
.sort((a, b) =>
b.faceDetections.find(d => d.title === faceName).width
- a.faceDetections.find(d => d.title === faceName).width
)
// sort fewest face detections first
.sort((a, b) =>
a.faceDetections.length
- b.faceDetections.length
)
// Sort faces that are at the edge last
.sort((a, b) =>
scoreFacePosition(a.faceDetections.find(d => d.title === faceName))
- scoreFacePosition(b.faceDetections.find(d => d.title === faceName))
)[0]
},

/**
Expand Down

0 comments on commit 7cad5e8

Please sign in to comment.