Hacker News new | past | comments | ask | show | jobs | submit login
Pico.js – A face-detection library in 200 lines of JavaScript (2018) (nenadmarkus.com)
126 points by fagnerbrack on Oct 11, 2022 | hide | past | favorite | 33 comments



I used this on a raspberry pi for this kinetic sculpture: https://www.youtube.com/watch?v=6xAiKI6XswM I was thankful that it worked on a variety of diverse faces, even masked somewhat.


That's pretty neat, how does it look like from the viewer's perspective?

Also what's the mechanism behind the turning? If I counted this right it would have to be like 48 servos which sounds expensive, but also is an interesting number because that's exactly 3 of those PCA 16 channel servo expansion boards...


You can get hobby R/C servos for $2.50 each these days. So, $120, plus the interface board(s).


That is really cool. I hope you make a post about your work on Hacker News!


For those looking to not only detect, but also vectorize faces (for later comparison against other faces) -- face recognition, try out: face-api.js

https://github.com/justadudewhohacks/face-api.js/


it's a cool library, I've used it in my bachelor's thesis applied to a camera stream


From the demo[0], It seems to do really well, until you turn your head even just a tiny bit. At which point it stops detecting.

[0]: https://nenadmarkus.com/p/picojs-intro/demo/


During the protests two years ago, I built this little app that you can use to obscure faces when sharing pictures. It uses face-api-js as others have mentioned.

https://github.com/xrd/faceoff


Why didn't you cherry pick an image where it covered everyone's face? The example has several people not obscured or have the dot not fully covering their face.


I'd like to understand the motivation behind your question.

Complaining about the unobscured faces would start the conversation about training data and its diminished inclusivity. But, your comment focused on the perception a person looking at the result might have, given the incomplete feature set of this software. I am having trouble imagining the sort of visitor xrd would disappoint with the imperfect image, that he should want to have retained, that wouldn't complain when noticing the gap him or herself during testing.

Could you please elaborate ?


Usually when showing off a project it makes sense to show it working correctly. The first photo shows that the software doesn't work consistently which could give someone a bad first impression. It's not like the photo is in a section that is about its limitation, but in a section introducing the project.


Sometimes doing that is just bullshit though.

If your face detection works 80% or 95% of the time, don't try and deceive me into thinking it's 100% accurate, only to leave me disappointed when I go through the effort of downloading/configuring/testing it and then find out it's worse that the solution I'm trying to replace.


Meaning the two pictures in the readme? The first is an image from Wikipedia, and the second is my face. If there is another image that is concerning, please let me know and I'll remove it and clean the history. I built this because I am uncomfortable sharing images of others without their consent (as happens all the time on social media) and also sharing my own childrens' faces, because I completely distrust the social media companies in particular.


I think the commenter meant why did you choose to show a non-perfect example of your software working? It missed a few faces in the black and white picture.


A face-detection library interface library in 200 lines of JS

FTFY


200 LOC is misleading since it requires you to download a model separately to use it.


Here are the models it downloads (in webcam.html)

    var cascadeurl = 'https://raw.githubusercontent.com/nenadmarkus/pico/c2e81f9d23cc11d1a612fd21e4f9de0921a5d0d9/rnt/cascades/facefinder';
    var puplocurl = 'https://drone.nenadmarkus.com/data/blog-stuff/puploc.bin'
The former is 234 KB, the latter is 1.4 MB


Is the model code? Or just data? Because if it’s just data and the library truly only needs 200 LOC to work with that model then it’s fair to say that it is a 200 LOC only library.

I can write a naive spell checker in a few dozen lines of Python, say 100 lines. I’ll need a dictionary file for it to be useful though. Would you claim my code is 100 lines or 50100 (assuming dict file has 50k words) lines?


The latter, because in this case the bulk of the "what is a face" function is determined by that data.


HAAR Cascading based face detectors are subpar to neural-network based ones. It is better to just use TF.js and related face detector. These are faster and much more accurate.

(I wrote JS-based face detector a decade ago: https://liuliu.me/eyes/javascript-face-detection-explained/)


While reading the post, it didn’t strike me as odd. I worked with small services wrapping ML models and 200 lines looks very slick and I don’t recall anyone considering weights as part of the code, and even the model training code is treated differently that the cliente code. Seems legit


Would be great to have something like this for filtering adult content from uploads.


FYI in case you didn't already know this, filtering adult content is a massively more challenging problem than face detection.


And the philosophical aspect of what "adult content" is more difficult than the implementation


I thought they solved this on that Silicon Valley documentary?


"I'll know it whe I see it."


It’s not very useful to implement a filter on the client, you have to filter somewhere where you have control, i.e. on the server.


Might not be the answer you are looking for, but there are several companies offering APIs to filter content.

E.g. Microsoft has a Vision API. Per https://azure.microsoft.com/en-us/pricing/details/cognitive-..., it's $1 per 1000 requests (with the first 5000 being free). They also have PhotoDNA, which is free but does a subset of SFW.

PixLab is another option (https://pixlab.io/cmdls).

Google has an API too (Cloud Vision).

If you go down this path, you'll have to do your own research on which service works best and what you can afford.


I'm kind of surprised that the big guys who do image detection (like google) won't open source whatever algos they use to separate "moderate" content from "adult" content on their image search. It's not 100% but works pretty well in my experience.


I'm not saying it's correct, but my first thought would be that it would make it much easier for bad actors to come up with ways of getting around the algorithm.


that's a good point and I didn't think about that.






Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: