Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FaceCovers: Don't use pictures with the face at the edge #1240

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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