From 95071fa118ee36d7365250f10756dce335dc76d9 Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 22 Aug 2024 11:00:14 -0400 Subject: more cleanup for face collections --- .../collectionFreeForm/FaceCollectionBox.tsx | 62 ++++++++++++++-------- 1 file changed, 40 insertions(+), 22 deletions(-) (limited to 'src/client/views/collections') diff --git a/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx b/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx index dd8dea41e..6005da6dd 100644 --- a/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx +++ b/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx @@ -26,18 +26,27 @@ import { FaceRecognitionHandler } from '../../search/FaceRecognitionHandler'; import './FaceCollectionBox.scss'; import { MarqueeOptionsMenu } from './MarqueeOptionsMenu'; -interface FaceDocumentProps { +/** + * This code is used to render the sidebar collection of unique recognized faces, where each + * unique face in turn displays the set of images that correspond to the face. + */ + +interface UniqueFaceProps { faceDoc: Doc; } /** - * A componenent to visually represent a Face Document. + * React component for rendering a unique face and its collection of image Docs. + * + * This both displays a collection of images corresponding tp a unique face, and + * allows for editing the face collection by removing an image, or drag-and-dropping + * an image that was not recognized. */ @observer -export class FaceDocumentItem extends ObservableReactComponent { +export class UniqueFaceView extends ObservableReactComponent { private _dropDisposer?: DragManager.DragDropDisposer; - constructor(props: FaceDocumentProps) { + constructor(props: UniqueFaceProps) { super(props); makeObservable(this); } @@ -54,12 +63,12 @@ export class FaceDocumentItem extends ObservableReactComponent doc.type === DocumentType.IMG) .forEach(imgDoc => { // If the current Face Document has no faces, and the doc has more than one face descriptor, don't let the user add the document first. Or should we just use the first face ? - if (FaceRecognitionHandler.FaceDocDescriptors(this._props.faceDoc).length === 0 && FaceRecognitionHandler.ImageDocFaceDescriptors(imgDoc).length > 1) { + if (FaceRecognitionHandler.UniqueFaceDescriptors(this._props.faceDoc).length === 0 && FaceRecognitionHandler.ImageDocFaceDescriptors(imgDoc).length > 1) { alert('Cannot add a document with multiple faces as the first item!'); } else { // Loop through the documents' face descriptors and choose the face in the iage with the smallest distance (most similar to the face colleciton) - const faceDescriptorsAsFloat32Array = FaceRecognitionHandler.FaceDocDescriptors(this._props.faceDoc).map(fd => new Float32Array(Array.from(fd))); - const labeledFaceDescriptor = new faceapi.LabeledFaceDescriptors(FaceRecognitionHandler.FaceDocLabel(this._props.faceDoc), faceDescriptorsAsFloat32Array); + const faceDescriptorsAsFloat32Array = FaceRecognitionHandler.UniqueFaceDescriptors(this._props.faceDoc).map(fd => new Float32Array(Array.from(fd))); + const labeledFaceDescriptor = new faceapi.LabeledFaceDescriptors(FaceRecognitionHandler.UniqueFaceLabel(this._props.faceDoc), faceDescriptorsAsFloat32Array); const faceMatcher = new FaceMatcher([labeledFaceDescriptor], 1); const { face_match } = FaceRecognitionHandler.ImageDocFaceDescriptors(imgDoc).reduce( (prev, face) => { @@ -71,8 +80,8 @@ export class FaceDocumentItem extends ObservableReactComponent { - FaceRecognitionHandler.DeleteFaceDoc(this._props.faceDoc); + deleteUniqueFace = undoable(() => { + FaceRecognitionHandler.DeleteUniqueFace(this._props.faceDoc); }, 'delete face'); /** - * Deletes a document from a Face Document's associated docs list. - * @param doc + * Removes a face image Doc from a unique face's list of images. + * @param imgDoc - image Doc to remove */ - deleteAssociatedDoc = undoable((imgDoc: Doc) => { - FaceRecognitionHandler.FaceDocRemoveImageDocFace(imgDoc, this._props.faceDoc); + removeFaceImageFromUniqueFace = undoable((imgDoc: Doc) => { + FaceRecognitionHandler.ImageDocDeassociateUniqueFace(imgDoc, this._props.faceDoc); + FaceRecognitionHandler.UniqueFaceRemoveFaceImage(imgDoc, this._props.faceDoc); }, 'remove doc from face'); render() { return (
this.createDropTarget(ele!)}>
- +
-

{FaceRecognitionHandler.FaceDocLabel(this._props.faceDoc)}

+

{FaceRecognitionHandler.UniqueFaceLabel(this._props.faceDoc)}

{this._displayImages ? (
- {FaceRecognitionHandler.FaceDocFaces(this._props.faceDoc).map(doc => { + {FaceRecognitionHandler.UniqueFaceImages(this._props.faceDoc).map(doc => { const [name, type] = ImageCast(doc[Doc.LayoutFieldKey(doc)]).url.href.split('.'); return (
DocumentView.showDocument(doc, { willZoomCentered: true })} style={{ maxWidth: '60px', margin: '10px' }} src={`${name}_o.${type}`} />
- this.deleteAssociatedDoc(doc)} icon={'x'} style={{ width: '4px' }} size={Size.XSMALL} /> + this.removeFaceImageFromUniqueFace(doc)} icon={'x'} style={{ width: '4px' }} size={Size.XSMALL} />
); @@ -152,6 +162,14 @@ export class FaceDocumentItem extends ObservableReactComponent() { public static LayoutString(fieldKey: string) { @@ -166,8 +184,8 @@ export class FaceCollectionBox extends ViewBoxBaseComponent() { render() { return (
- {FaceRecognitionHandler.FaceDocuments().map(doc => ( - + {FaceRecognitionHandler.UniqueFaces().map(doc => ( + ))}
); -- cgit v1.2.3-70-g09d2