facerecognition icon indicating copy to clipboard operation
facerecognition copied to clipboard

Feature to assign faces to tags

Open jonno293 opened this issue 5 years ago • 8 comments

Hello, I'm sorry if this is the wrong way to request... I'm interested in a feature for specific faces to become tags, maybe by each persons name in setting I could choose to create a corresponding tag or something or if multiple faces are in one photo to give it a tag. I love this feature so far and would love to one day be able to contribute but I'm still quite the coding noob! Thanks for yall's efforts!

jonno293


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

jonno293 avatar Jul 10 '20 14:07 jonno293

Hi @jonno293

It is something that I consider, in fact there were also experiments, but it is unlikely that we use the current tag interface. :disappointed:

At first I dismissed it for performance reasons.

  • https://github.com/nextcloud/server/issues/17499

However the biggest problem is that the labels are completely independent of the application. If the user adds a tag to an image, I have no way of knowing if they wanted to add a person, or just say it's personal (The NC tags just reports the raw tag, only the tag text).

On the other hand, suppose that our application labels "Matias" to a photo where I am not. if I remove the tag in the file application.

  • Our application should remove the assignment of this photo or all photos that have this tag?
  • ..and if the tag was originally added, from the same file manager? I don't know, to indicate that the photo was edited by Matias.
  • what if i want to rename the tag rather than delete?

In resume, I have no way to tell if the label refers to a person, or a simple label... and this leads to many problems of inconsistencies, user assumptions that we cannot fix, etc. :disappointed:

matiasdelellis avatar Jul 30 '20 14:07 matiasdelellis

p.s: I had forgotten about this. There is also a major problem. The tags are all shared among all users. No one can believe that tagging a person with a name, or nickname, should be shared with other users.

I.e: You label your ex in some photos, and your couple will see that you created the label. :sweat_smile: This is a major privacy error!. :disappointed:

matiasdelellis avatar Aug 05 '20 23:08 matiasdelellis

Just to make the example clear ... This is my account with some personal photos tagged.. imagen

...and this is another account where I do some development tests (I only have photos of The big bang theory..) imagen

matiasdelellis avatar Aug 06 '20 20:08 matiasdelellis

I understand and share @matiasdelellis objections regarding "faces to tags" for large nextcloud instances with many users due to tags are defined globally. However in a small family internal nextcloud instance like I'm using where most of the photos are shared within the family "face to tag" provides very comfortable benefit of face recognition. Therefore I will share the SQL commands I'm using to create "face to tags" capability created via sql.

Assuming you assigned the label "Max" to a face and want to create a tag "Max photos" to all photos of person "Max" identified by face recogintion. To do so you need two sql statements in your nextcloud sql db: (NOTE: tested on NC20. In my config.php dbtableprefix is defined as "oc_". If that is different the SQL statements needed to be adapted. maybe you first need to select your data base instance e.g. if the data base instance is called "nextcloud": use nextcloud; )

  1. create a read only tag "Max photos" using: insert into oc_systemtag(name, visibility, editable) values('Max photos', 1, 0);
  2. assing this tag to all photos identified as person "Max" but not jet tagged with "Max photos" using:
insert into oc_systemtag_object_mapping (objectid, objecttype, systemtagid)
select distinct i.file, 'files' as 'objecttype', t.id from oc_facerecog_persons p 
join oc_facerecog_faces f on f.person = p.id 
join oc_facerecog_images i on i.id = f.image 
join oc_systemtag t on t.name = 'Max photos'
where p.name = 'Max'
and i.file not in (
  select m.objectid from oc_systemtag_object_mapping m 
  join oc_systemtag t on t.id = m.systemtagid
  where t.name = 'Max photos'
  and objecttype = 'files'
);

You can run the 2nd command as often you like to assign the tag "Max photos" to new added photos idenified as person "Max".

wronny avatar Nov 10 '20 22:11 wronny

The queries from @wronny worked, however I had to adjust the second query a bit to be compatible with PostgreSQL:

insert into oc_systemtag_object_mapping (objectid, objecttype, systemtagid)
select distinct i.file, 'files' as objecttype, t.id from oc_facerecog_persons p 
join oc_facerecog_faces f on f.person = p.id 
join oc_facerecog_images i on i.id = f.image 
join oc_systemtag t on t.name = 'Max photos'
where p.name = 'Max'
and i.file::varchar not in (
  select m.objectid from oc_systemtag_object_mapping m 
  join oc_systemtag t on t.id = m.systemtagid
  where t.name = 'Max photos'
  and objecttype = 'files'
);

marcoboers avatar Mar 16 '21 14:03 marcoboers

Why not using workflow for this feature?

Dev docs:
Workflow - https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/flow.html?highlight=workflow
Events based system - https://docs.nextcloud.com/server/latest/developer_manual/basics/events.html?highlight=workflow

User docs: https://nextcloud.com/workflow/

storm1er avatar May 25 '21 09:05 storm1er

I think this could be done using tags, even if there is a privacy issue.

It could be an option "Add tags to my people" from the settings menu.

Using the option above, it should be feasible without too much hassle, right?

storm1er avatar Aug 17 '21 12:08 storm1er

Hi all, It's probably late, I still have some qualms about it, but since NC25 adds albums, add a command to create the albums of persons, since I think it is a better solution than the tags.

[matias@nube nextcloud]$ sudo -u apache php occ face:sync-albums -u user
[sudo] password for matias: 
Synchronizing albums for the user <user>. Done.

imagen

imagen

Edit: p.s: The "People" tab of photos app, It has nothing to do with this application.. 😞
That's why I say it's probably late 😥 , but I'm still working on this app. 😉

matiasdelellis avatar Sep 20 '22 16:09 matiasdelellis