Microsoft facial recognition, who is able to make it work?

Can anyone tell where the curl command is given… This is very confusing now. Can anyone who has it working make a step by step for noobs…

yes very confusing

Got it to work.
I created my own scripts that I run on my windows machine. I basically created folder for groups and then folders for persons which each folders containing photo of the person.
my dirty code here
http://pastebin.com/T5MUfjqL

Problem is that we eventually burn the quota of azure api. Is there a way to disable the image_processing component based on rules/conditions (time, motion sensor) ??

The ipcam where I assigned image processing automatically turns off itself without motion, I’m not sure if the image processing stops when this happen.

Welcome to my first real post

Or at least the first one I felt would be useful to at least one other person...

After a bunch of plugging and chugging along with countless rereading of this entire thread, I was able to get MS Face to learn my face, trained the group, and then based off the automation trigger some lights to come on in my house. However, within minutes of the success, I reached the limit for the free MS Face using Azure.

I will post my config and the steps i took below but I believe I identified where one of the major issues is coming into play. And it didn’t become clear to me until the latest update that saw microsoftface_detect added as a separate component.

You need to have both a microsoftface_identify and microsoftface_detect as image processing components. The detect sees if there is a face and then the identify identifys the face if the face is known to your MS Face account as a person in a group.

I could also be wrong and my having both as separate components under image processing was superfluous. But that is how I had it configured when I finally got it to work.

Also, I set confidence down to 40 as well.

Steps I Took

  1. Firstly, I did "pip install cognitive_face" on my RPi3 while HA was not running for good measure and while I am not sure if this was absolutely necessary, my gut says it was and hence I have listed it here.
  2. Creating the person and the group can be done relatively easily in the front end dev section. The JSON info needed to send needs to contain the parameters listed for each service call and only those parameters. For those of you (us) newer to this, your data (JSON) should look like this: > {"foo":"bar","derp":"a derpa"}
  3. For teaching the face to the image, you can use either the front end dev similar to creating a person and group like above but by specifying a camera entity id to capture the face from. Note: if there are multiple faces in the camera's view field when you call the service, MS Face will follow its documented protocols to determine which face is to be saved. And that might not be the one you want it to choose.
    See MS Face documentation on that if you want to try to specify which one to save but it would be incredibly tedious to do so through the HA front end. I recommend using the api demo's embedded curl which can be accessed [here](https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b/console).
    1. The persongroupid is the name of the group the person is in. The personID can be found in the dev section of the front end under Microsoft_face.yourgroupname. Then delete the the other query parameters (ie: targetFace). content-type should be unchanged. Add your subscription key to O...
    2. In request body, change the url that is quoted to a url of an image of the person or face you are trying to ad... This can be done by using the URL of a social media profile, an image on a site or even an image on your HA server (if you have an externally accessible URL that correctly points to an image).
    3. Hit SEND at the bottom of the page and if it was successful it will say so under Response Status.
      • If it failed, it will say why. Troubleshoot accordingly.
    4. Once the face has been successfully added, you can verify it in the frontend of HA under dev tools. The image_processing.yourMSFaceIdentify_entityid should now read total_faces: 1 instead of 0.
  4. Next, train the MS Face Group. I was unable to get this to successfully run via HA or curl and therefore in my opinion must be done on the MS Face Train Person Group site [here](https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395249).
  5. Once trained, any automation using the above components (as listed on the HA documentation [here](https://home-assistant.io/components/image_processing/)) should execute without error.
  6. Note: I am trigger happy with HA restarts and do them after every step of this includiing anything done on the MS Face site. Also, to solve the issue with 401 on the camera image pull, you have to make sure your HA is fully accessible from external ip's as the MS Face api has to reach it... and you need to have specified a base URL for your http component if you are using encryption. However, the base URL is not necessary if you run your HA server without any encryption. (I turned off my encryption during the testing and setup process of MS Face because I was trying to isolate the issues I was having. I would not recommend having an HA setup that is exposed externally without encryption normally. So be advised)

    My Configuration

    As promised though , here is my configuration. Mind you, I am still very much a NOOB at this and I want to thank the folks of you who commented above me on this thread. Your failures and success helped me in countless ways.

    Conclusion and My Next Move

    All this being well and good, it felt really f-ing good to finally get this working but due to the almost immediate maxing out of my api calls (and countless other good reasons listed above and in other threads), I cannot continue to use this in my system and will now be tackling the integration of openCV. If I get it working When I get it working, I will post my steps taken (unless someone else has already done so).
4 Likes

Hi,

I test the microsoft component, it works well nevertheless, we need to contact microsoft server… so i began to integrate OpenCV to be able to do facial recognition offline.

Many bugs must be resolved … to work fine…

I hear you. And I actually am currently bringing myself up to speed on your progress as mentioned in the above thread. Was planning on using that as a jump off point anyway. I am skipping installing openCV on one of my RPi’s though and instead opting for a dedicated server that sits next to my main PC doing pretty much nothing. (I think the only always on process it is currently running is a PLEX server. And it’s got plenty of power so I am curious to see how smoothly openCV can maybe run.

I was having similar problems using the Computer Vision API which uses a similar Curl command.

I think I solved the problem and probably it is the same in your case. The manual page in the microsoft web page is misleading for the case where I want to upload a file from my local (from my own laptop). It says that the last option should be --data-ascii “{body}” .However the last option of the curl command should be --data-binary “{body}”.

So, for your case I guess the last option should be --data-binary “@/tmp/saraiyhw.jpg” instead of --data “@/tmp/saraiyhw.jpg”.

The @ sign is necessary because it tells to Curl to find the file at that location and send it solely as binary formated.

I hope this helps!

I think Microsoft end point is incorrect even in their own documentation… Try it here https://westus.api.cognitive.microsoft.com/face/v1.0/

Rob,
Did you get your Google tensorflow face recognition working? Can you share your code and experiences?

Thank you for this great post. What was the reason you ran out of API Calls?
Where you processing images or video?

30 per minute sounds like a LOT of calls. My naive guess at this moment is that once you detect motion , you take 2-3 pics and process them. Most of the day, there is no motion in the house.

how did you get those 30 calls per minute? why do you need to process so many requests?

What are you using now? Did you do another post on OpenCV or other image processing API?
I am about to start on this path, so would be great to get your feedback on where did you wind up.

I think someone needs to check if the Microsoft service works still, if not remove the component.
I am working on Clarifai integration here
Cheers

Took a look at their site. Clarifai does not have face recognition , only face detection. Or are you building a custom model with their API? or you are not actually looking for face recognition?

Custom model - one of the best features of Clarifai. If you just want face recognition the OpenCV component works

I was able to get microsoft face working. It is correctly firing automations when I walk in front of the assigned camera. I’ll need to test it now with the whole family and see how accurate the ID is.

One thing that would be neat would be if I can get an automation to fire when there is a face detected that is not known.

2 Likes

28-3-2018 Component is working, I was probably using incorrect config before.

1 Like

@Ouassimf did you ever get a solution for the quota issue? i have everything working, however with the trial susbscription you can only use the API 30000 times in a month, and i’m spending that amount in a week.

is there any way to only trigger face recognition based on some events??

@peteonus
I realized that anyway I dont want to rely on cloud. Went for dlib instead which does NOT work out of the work on hassio / hassbian.
I installed everything on a rpi3 and modified had to modifiy the dlib component face_recognition requirement from 1.0.0 to 1.2.2 (latest version that DO work with scipy)

I would recommend to use this Face detection with Docker/Machinebox

Works great for me. Thank you @robmarkcole

2 Likes

Just having a go at setting this up… I’ve got the config in for microsoft_face

microsoft_face:
api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
azure_region: westeurope

I’ve restarted hass, but can’t see any of the services available as described in the documentation, as a result I get the following error:

Unable to find service microsoft_face/create_group

Any clues where I’m going wrong?

Cheers

Andy