Face Authentication with Google Cloud Vision API in Spring Boot - java

1- I am using Google Cloud Vision API for face authentication in spring boot.
2- I have created an Account on Google Cloud Console and download a Json key file.
3- I use this Json file in my project and get the response of face data from image like this:
google.cloud.vision.v1.EntityAnnotation.mid : /m/025kyy
google.cloud.vision.v1.EntityAnnotation.description : Forehead
google.cloud.vision.v1.EntityAnnotation.score : 0.9846564
google.cloud.vision.v1.EntityAnnotation.topicality : 0.9846564
google.cloud.vision.v1.EntityAnnotation.mid : /m/0jyfg
google.cloud.vision.v1.EntityAnnotation.description : Glasses
google.cloud.vision.v1.EntityAnnotation.score : 0.9844217
google.cloud.vision.v1.EntityAnnotation.topicality : 0.9844217
google.cloud.vision.v1.EntityAnnotation.mid : /m/03q69
google.cloud.vision.v1.EntityAnnotation.description : Hair
google.cloud.vision.v1.EntityAnnotation.score : 0.9835347
google.cloud.vision.v1.EntityAnnotation.topicality : 0.9835347
google.cloud.vision.v1.EntityAnnotation.mid : /m/019nj4
google.cloud.vision.v1.EntityAnnotation.description : Smile
google.cloud.vision.v1.EntityAnnotation.score : 0.9771221
google.cloud.vision.v1.EntityAnnotation.topicality : 0.9771221
google.cloud.vision.v1.EntityAnnotation.mid : /m/0h8jxfl
google.cloud.vision.v1.EntityAnnotation.description : Vision care
google.cloud.vision.v1.EntityAnnotation.score : 0.9488289
google.cloud.vision.v1.EntityAnnotation.topicality : 0.9488289
google.cloud.vision.v1.EntityAnnotation.mid : /m/027n3_
google.cloud.vision.v1.EntityAnnotation.description : Eyebrow
google.cloud.vision.v1.EntityAnnotation.score : 0.93961227
google.cloud.vision.v1.EntityAnnotation.topicality : 0.93961227
google.cloud.vision.v1.EntityAnnotation.mid : /m/015h_t
google.cloud.vision.v1.EntityAnnotation.description : Beard
google.cloud.vision.v1.EntityAnnotation.score : 0.9188007
google.cloud.vision.v1.EntityAnnotation.topicality : 0.9188007
google.cloud.vision.v1.EntityAnnotation.mid : /m/01k9lj
google.cloud.vision.v1.EntityAnnotation.description : Jaw
google.cloud.vision.v1.EntityAnnotation.score : 0.8822703
google.cloud.vision.v1.EntityAnnotation.topicality : 0.8822703
google.cloud.vision.v1.EntityAnnotation.mid : /m/0dzd8
google.cloud.vision.v1.EntityAnnotation.description : Neck
google.cloud.vision.v1.EntityAnnotation.score : 0.87822306
google.cloud.vision.v1.EntityAnnotation.topicality : 0.87822306
google.cloud.vision.v1.EntityAnnotation.mid : /m/0j272k5
google.cloud.vision.v1.EntityAnnotation.description : Eyewear
google.cloud.vision.v1.EntityAnnotation.score : 0.8768612
google.cloud.vision.v1.EntityAnnotation.topicality : 0.8768612
But Now I have save these detail in my database and comparing the face data at the time of face authentication. But it's not work.
I am doing this(GCP) for the first time. So I don't know how to compare two faces here.
Please help me!

I think you are mixing concepts here.
The feature you are using is something called face detection which detects faces and its features (position, mood, etc) on a image - without identifying unique characteristics from each face that could be used to build a database of faces.
To perform something as face authentication, you do need something called face recognition where, in summary, you build a base of known faces embeddings and perform a similarity search of a new face against this database.
Google Vision API doesn't provide face recognition mechanisms as it goes against the Google AI Principles.

Related

Getting java.lang.IllegalArgumentException "Name must not be null!" when updating MongoDB collection

I am facing below issue when I am going to update a existing collection entry in mongoDB. I am using Spring boot 2.0.
my existing MongoDB collection entry is like below. I'm going to update the "external_item" of below collection. It has a null key in that json posion.
{
"TestItem" : {
"item1" : "value1"
},
"external_item" : {
"" : "keyIsEmptyOfThisValue",
"key2" : false
},
"links" : [],
"createdDate" : ISODate("2020-05-10T05:24:44.014Z"),
"updatedDate" : ISODate("2020-05-10T05:24:44.014Z")
}
For that I m using below payload with the PUT method with a REST API
{
"external_item" : {
"" : "keyIsEmptyOfThisValue",
"key2" : true
}
}
when updating gives below issue. It says Name must not be null!. How can I get updated the MongoDB content in this way ??
java.lang.IllegalArgumentException: Name must not be null!
at org.springframework.util.Assert.hasText(Assert.java:162)
at org.springframework.data.mongodb.core.convert.QueryMapper$Field.<init>(QueryMapper.java:591)
at org.springframework.data.mongodb.core.convert.QueryMapper.createPropertyField(QueryMapper.java:216)
at org.springframework.data.mongodb.core.convert.UpdateMapper.createPropertyField(UpdateMapper.java:169)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:122)
at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:359)
at org.springframework.data.mongodb.core.convert.UpdateMapper.getMappedObjectForField(UpdateMapper.java:81)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123)
at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:1016)
at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:1007)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:410)
at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:1007)
at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:985)
at com.pearson.socket.core.dao.MongoDriverImpl.updateFirst(MongoDriverImpl.java:127)
at com.pearson.socket.core.dao.AbstractDAOImpl.updateFirst(AbstractDAOImpl.java:92)```
There seems to be a bug somewhere in old versions of spring-data-mongodb that caused this.
Consider updating to newer spring-boot and spring-data-mongodb versions, e.g I know that in spring-boot 2.2 that uses spring-data-mongodb 2.2.6 updating an entity with empty map key works.

Spark Java Aggregation

I'm trying Spark with Java and MongoDB and I want to aggregate some Documents into a single one based on timestamps. For example, I want to aggregate X documents into a single one:
{
"_id" : ObjectId("598c32f455f0353f9e69ebf1"),
"_class" : "...",
"timestamp" : ISODate("2017-08-10T10:17:00.000Z"),
"value" : 10.1
}
...
{
"_id" : ObjectId("598c32f455f0353f9e69ebz2"),
"_class" : "...",
"timestamp" : ISODate("2017-08-10T10:18:00.000Z"),
"value" : 2.1
}
Lets say I have 60 documents like this and their timestamps are in a window of 1 minute (from 10:17:00 to 10:18:00) and I want to obtain one document:
{
"_id" : ObjectId("598c32f455f0353f9e69e231"),
"_class" : "...",
"start_timestamp" : ISODate("2017-08-10T10:17:00.000Z"),
"end_timestamp" : ISODate("2017-08-10T10:18:00.000Z"),
"average_value" : **average value of those documents**
}
Is it possible to perform this kind transformation? Can I retrieve one window of 1 minute of data at a time?
An approach which takes all the documents and compare their timestamps looks slow and inefficient.
Thanks in advance.

appending data to array in MongoDB-Document using Java Driver 3.4

I am using MongoDB Java Driver 3.4 and want to update a document (with id "12") in a Mongo-DB collection. Currently, the document looks as follows:
{"id" : "12", "Data" : [{"Author" : "J.K. Rowling",
"Books" : {"Harry Potter 1" : "$15.99", "Harry Potter 2" : "$16.49", "Harry Potter 3" : "$19.49"}},
{"Author" : "Philip Roth",
"Books" : {"American Pastoral" : "$12.99", "The Human Stain" : "$39.49", "Indignation" : "$29.49"}}
]}
I want to update this document by adding the following object to array "Data":
{"Author" : "Stephen King", "Books" : {"Rose Red" : "$12.69", "Faithful" : "$9.49", "Throttle" : "$8.49"}}
To this end I wrote the following java code:
Document doc = new Document().append("Author", "Stephen King")
.append("Data", new Document("Rose Red", "$12.69")
.append("Faithful" : "$9.49")
.append("Throttle" : "$8.49"));
collection.update({"id", "12"}, {$push: {"Data" : doc.toJson()}});
The IDE indicates there is something wrong with the last statement (collection.update...) by showing me this:
I don't know what this error message is supposed to tell me. There is a semicolon at the end of the statement. Does anybody know what's wrong with the java code?
P.S.: This is not a duplicate to
(MongoDB Java) $push into array
My question relates to Java Driver 3.4. The other question relates to an earlier version with totally different classes.
There are couple of things incorrect here.
field - Change from Data to Books
separator - Change from semicolon to comma
method - Change from update to updateOne and you can pass Document directly.
Document doc = new Document("Author", "Stephen King")
.append("Books", new Document("Rose Red", "$12.69").append("Faithful", "$9.49").append("Throttle", "$8.49"));
collection.updateOne(new Document("id", "12"), Updates.push("Data", doc));

Automatic update of indexes in Elastic Search via JDBC River

Can anyone please post working configuration of elastic search mysql JDBC River, doing automatic ES update when table contents change? Poll every 10 seconds and update if something changed would be fine too.
This one is probably duplicate, but I had no success with auto commit setting, suggested here:
Fetching changes from table with ElasticSearch JDBC river
this worked for me:
curl -XPUT 'localhost:9200/_river/yadda/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"strategy" : "simple",
"driver" : "com.mysql.jdbc.Driver",
"url" : "jdbc:mysql://localhost:3306/yadda",
"user" : "bla",
"password" : "blabla",
"sql" : "select bla from blabla",
"index" : "bla_index",
"type" : "bla_type",
"schedule" : "0/10 * * ? * *",
"max_retries": 3,
"max_retries_wait" : "10s"
}
}'

Modify nest document's value in MongoDB for Java

A very quick question, how am I going to do this below:
> db.blog.posts.findOne()
{
"_id" : ObjectId("4b253b067525f35f94b60a31"),
"title" : "A Blog Post",
"content" : "...",
"author" : {
"name" : "joe",
"email" : "joe#example.com"
}
}
I saw the answer in Javascript is like:
> db.blog.posts.update({"author.name" : "joe"}, {"$set" : {"author.name" : "joe schmoe"}})
But how am I going to do that in Java?
If I have a very deep level value has to be changed, am I supposed to use this way? like: "person.abc.xyz.name.address" ?
Using dot notation to access nested documents will work perfectly well in the Java Driver. Take a look at this StackOverflow answer:
MongoDB nested documents searching
For the Java Driver, the basic idea is to replace the Javascript objects with instances of BasicDBObject.
Here's another good reference for updating:
MongoDb's $set equivalent in its java Driver

Categories