About module
This is one module in FaceChecker application at: http://plusplus.linkedface.com/facechecker
Module repository: https://github.com/papaiking/faceChecker_services
This module act as: data service and socket io server
Do following tasks:
- Authenticate device
- Distribute Linkedface++ application token to device
-
Receive check event from device and do following:
- Save event into DB
- Emit event to socket io
Installation
Clone project
Clone FaceChecker-Service from repository: https://github.com/papaiking/faceChecker_services.git
Install dependencies
Go to project folder and run command: npm install
Database
As you see in FaceChecker architecture, this service use a relation database. In this version, we use MySQL version: 5.6
You can get reference on how to install MySQL on Ubuntu here: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-14-04
After this step, let’s create database, user and grant access:
$ mysql -u root –p
Enter password
mysql> CREATE DATABASE facechecker
mysql> CREATE USER 'facechecker'@'localhost' IDENTIFIED BY 'lot123';
mysql> GRANT ALL PRIVILEGES ON facechecker.* TO 'facechecker'@'localhost';
Then import database.
Module folder: faceChecker_services/data
and run:
$ mysql -u facechecker -p facechecker < facechecker.sql
enter password
Configurations
Register application in Linkedface++
You have to register Linkedface++ application in order to access Linkedface++ services.
Refer to use Linkedface++ platform at: http://plusplus.linkedface.com
After registering application, save your app_id
and app_secret
Configure parameters
Go to project folder, edit the configuration file: /config/settings.js
, update values for
- port: service port
- DB connection,
- secret: this is the random string working as seed for JWT. After running system, don’t change this value.
- identity information of Linkedface++ third party application (app_id and app_secret)
var settings = {
path : path.normalize(path.join(__dirname, '..')),
port : process.env.NODE_PORT || 9100,
database : {
protocol: "mysql",
query : { pool: true },
host : "127.0.0.1",
database: "facechecker",
user : "facechecker",
password: "lot123"
},
secret : 'ANY_STRING_THERE',
Linkedface_OAUTH : 'https://api.linkedface/app/token',
Linkedface_USER_INFO: 'https://api.linkedface/app/user_info/{0}',
app_identity: {
app_id:"73705ee75cbdf46f7d68539e7523e879",
secret:"RC3VZ53O5DJH3V687WCKOXZ81XQF80RY"
}
};
Run application
Go to project folder and run command: npm start
Following output as successful installation:
osboxes@linkedface:~/faceChecker/facechecker_server$ npm start
> FaceChecker_Server@ start /home/osboxes/faceChecker/facechecker_server
> script/start
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /home/osboxes/faceChecker/facechecker_server/app/**/* /home/osboxes/faceChecker/facechecker_server/config/**/* /home/osboxes/faceChecker/facechecker_server/models/**/* node_modules/sql-query server.js
[nodemon] starting `node server.js`
Listening on port 9100
APIs
APIs for device operations
Device send event
When device search and found user in camera image, it send search information (event of check-in / check-out) to server. Then server will update this event data into database and emit message (use socket.io) to dashboard
- URL:
http://server_root/gateway/add_event
- Method: POST
- Data type: application/json
- Header:
{x-access-token: facechecker_access_token}
facechecker_access_token
: is generated for each device by FaceChecker-service. System administrator use Surveillance dashboard to register device and generate access token
Example:
- URL:
http://118.70.11.36:9100/gateway/add_event
- JSON Payload:
{
"user_id": "PapaiKing",
"name": "Thuc X.Vu",
"picture": "https://img.linkedface.com/ifaces/thumbs/300/2017-05-16/118.70.217.99_1494898191.37005_image201610280001.jpg",
"similarity": 0.1,
"event_picture": "https://img.linkedface.com/search/imgs/2017-05-31/118.70.217.99_1496207329.94350_facechecker_12-08-49-249793.jpg",
"type": 1,
"valid": 1
}
Header:
{x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjOTQyNjc0YzkyZGFlMmY0ZjcwOTk0ZTBkNWQ1ZjU4IiwiYWRkcmVzcyI6Ik5vIDgsIFRyYW5nIFRoaSwgSG9hbiBLaWVtLCBIYW5vaSIsInNlY3JldCI6IjZnZmhnZmhmIiwic3RhdHVzIjowLCJhYm91dCI6IkNhbWVyYSBmb3Igb2ZmaWNlIiwiY3JlYXRlZCI6IjIwMTctMDUtMThUMTU6MjI6MzAuMDAwWiIsImlhdCI6MTQ5NTI3MDcxNX0.41ERZl1CISqPOMx6Kq0zpJ-uT_H}
Content-Type: application/json
Device get LIKEDFACE TOKEN
FaceChecker-service login into Linkedface++ and get application Access Token and then FaceChecker send Linkedface++ access token to device for working with LINKEDFACE++ later.
- URL:
http://server_root/gateway/linkedface_token
- Method: GET
- Header:
{x-access-token: facechecker_access_token}
Example:
- URL:
http://118.70.11.36:9100/gateway/linkedface_token
- Header:
{x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjOTQyNjc0YzkyZGFlMmY0ZjcwOTk0ZTBkNWQ1ZjU4IiwiYWRkcmVzcyI6Ik5vIDgsIFRyYW5nIFRoaSwgSG9hbiBLaWVtLCBIYW5vaSIsInNlY3JldCI6IjZnZmhnZmhmIiwic3RhdHVzIjowLCJhYm91dCI6IkNhbWVyYSBmb3Igb2ZmaWNlIiwiY3JlYXRlZCI6IjIwMTctMDUtMThUMTU6MjI6MzAuMDAwWiIsImlhdCI6MTQ5NTI3MDcxNX0.41ERZl1CISqPOMxT7T6Kq0zpJ-uT_HHt1meHexI}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0OTU1MjY4ODYsInN1YiI6IjczNzA1ZWU3NWNiZGY0NmY3ZDY4NTM5ZTc1MjNlODc5IiwiZXhwIjoxNDk2NzM2NDg2fQ.HLANhfSt-kDreDOjb2bT2mMXSUZ4mWKLVtfg",
"status": 1,
"message": "OK"
}
APIs for event management
These APIs is used by Surveillance dashboard module
Get List of events
- URL:
http://server_root/event/list/:limit
- Method: GET
Parameter:
limit
: is number of events returned into result
Example
- URL:
http://118.70.11.36:9100/event/list/10
Response:
[
{
"id": "1d1da53afcc15d5fd5546e2dd482f37e",
"user_id": "5c942674c92dae2f4f70994e0d5d5f58",
"created": "2017-06-12T16:50:36.000Z",
"name": "Thức Xuân Vũ",
"picture": "https://img.linkedface.com/ifaces/thumbs/300/2017-05-26/118.70.217.99_1495781823.09724_image201610280001.jpg",
"device_id": "5c942674c92dae2f4f70994e0d5d5f58",
"similarity": 0.5355081710927223,
"event_picture": "https://img.linkedface.com/search/imgs/2017-06-12/172.31.6.24_1497286249.44706_facechecker_23-50-34-037283.jpg",
"type": 1,
"valid": 1
},
{
"id": "a8cfeb1dbba02b85f00eaa5067fa98ac",
"user_id": "5c942674c92dae2f4f70994e0d5d5f58",
"created": "2017-06-12T16:50:30.000Z",
"name": "Thức Xuân Vũ",
"picture": "https://img.linkedface.com/ifaces/thumbs/300/2017-05-26/118.70.217.99_1495781823.09724_image201610280001.jpg",
"device_id": "5c942674c92dae2f4f70994e0d5d5f58",
"similarity": 0.5736527827662977,
"event_picture": "https://img.linkedface.com/search/imgs/2017-06-12/172.31.6.24_1497286244.21030_facechecker_23-50-28-793252.jpg",
"type": 1,
"valid": 1
}
]
Get profile information
- If an event occurred and system found a user, you can get user information by this APIs
- URL:
http://server_root/linkedface/profile/user_id
- Method: GET
Parameter: user_id
: id of user that we get information about
Example
- URL:
http://118.70.151.36:9100/linkedface/profile/5c942674c92dae2f4f70994e0d5d5f58
- Response:
{
"username": "vxtrhuc@yahoo.com",
"status": 0,
"first_name": "Papai",
"last_name": "King",
"picture": "https://img.linkedface.com/ifaces/thumbs/300/2017-05-26/118.70.217.99_1495781823.09724_image201610280001.jpg",
"name": "Thức Xuân Vũ",
"social_networks": [
{
"picture": "http://pbs.twimg.com/profile_images/854910758424952832/fq7wJPbc_normal.jpg",
"about": "I'm a software developer, Labs founder in: https://t.co/NPI5TKbSNN",
"last_name": null,
"user_id": "5c942674c92dae2f4f70994e0d5d5f58",
"name": "LeopardVu",
"created": "2017-05-26T11:00:23",
"network_id": 3,
"social_id": "854910172598226944",
"first_name": null,
"link": "https://twitter.com/LeopardVu",
"email": null
}
],
"created": "2017-03-31T16:00:15",
"image_root": "https://img.linkedface.com/ifaces",
"about": "I'm a , Mobile Enterprise Application, Cloud.",
"email": "vxrthuc@yahoo.com",
"images": [
{
"status": 1,
"user_id": "5c942674c92dae2f4f70994e0d5d5f58",
"parent": null,
"fileName": "2017-05-24/118.68.248.44_1495617621.11503_image201610280003.jpg",
"content": null,
"faces": "[{\"position\": \"[384, 241, 705, 562]\", \"id\": \"87240850b751f3ffa1656ed74333107b\"}]",
"date": "2017-05-24T16:20:22.427000",
"next": null,
"type": 1,
"id": "b13ae6c6c7fcd7974301028ae6184a24",
"previous": null
}
],
"id": "5c942674c92dae2f4f70994e0d5d5f58"
}
APIs for device management
These APIs are used by FaceChecker administration application module
Get list of end devices in system
- URL:
http://server_root/device/list/:limit/:offset
- Method: GET
Parameters: - limit: is number of devices returned into result - offset: offset of rows in devices table
Example:
- URL: http://118.70.11.36:9100/device/list/2/0
Sample response:
[
{
"id": "ceb0b97a7acbc0570df1cc7b194258d8",
"address": "Harbor view, Ngoc Thuy, Long Bien",
"secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImNlYjBiOTdhN2FjYmMwNTcwZGYxY2M3YjE5NDI1OGQ4IiwiYWRkcmVzcyI6IkhhcmJvdXIgdmlldywgIE5nb2MgVGh1eSwgTG9uZyBCaWVuIiwic2VjcmV0IjoiZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnBaQ0k2SW1Jd016Y3paRGM1WVdZM05XVTFNVEZpTmpRd05UWTVNR0kxWm1aaU1EZzJJaXdpWVdSa2NtVnpjeUk2SWtoaGNtSnZkWElnZG1sbGR5d2dJRTVuYjJNZ1ZHaDFlU0lzSW5ObFkzSmxkQ0k2Ym5Wc2JDd2ljM1JoZEhWeklqb3dMQ0poWW05MWRDSTZJa0oxYVd4a2FXNW5JR2RoZEdWM1lYa2dZMkZ0WlhKaElpd2lZM0psWVhSbFpDSTZJakl3TVRjdE1EVXRNak5VTVRVNk5EazZOVE11TVRjNVdpSXNJbWxoZENJNk1UUTVOVFUxTkRVNU0zMC5iTExWd3ZtOE1ZbnlrWDVLVnQyM1l2YlFIbGRDeXJObm96Z2RtRFFEOEpRIiwic3RhdHVzIjowLCJhYm91dCI6IkJ1aWxkaW5nIGdhdGV3YXkgY2FtZXJhIC0gZm9yIHNlY3VyaXR5IiwiY3JlYXRlZCI6IjIwMTctMDUtMzFUMTU6Mjc6NDEuOTg1WiIsImlhdCI6MTQ5NjI0NDQ2MX0.xeBA2xTc1kxugapsZquKs",
"status": 0,
"about": "Building gateway camera - for security",
"created": "2017-05-31T15:27:42.000Z"
},
{
"id": "5c942674c92dae2f4f70994e0d5d5f58",
"address": "No 8, Trang Thi, Hoan Kiem, Hanoi",
"secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjOTQyNjc0YzkyZGFlMmY0ZjcwOTk0ZTBkNWQ1ZjU4IiwiYWRkcmVzcyI6Ik5vIDgsIFRyYW5nIFRoaSwgSG9hbiBLaWVtLCBIYW5vaSIsInNlY3JldCI6IjZnZmhnZmhmIiwic3RhdHVzIjowLCJhYm91dCI6IkNhbWVyYSBmb3Igb2ZmaWNlIiwiY3JlYXRlZCI6IjIwMTctMDUtMThUMTU6MjI6MzAuMDAwWiIsImlhdCI6MTQ5NTI3MDcxNX0.41ERZl1C7T6Kq0zpJ-uT_HHt1meHexw_BmI",
"status": 0,
"about": "Camera for office",
"created": "2017-05-18T15:22:30.000Z"
}
]
Create device:
- URL:
http://server_root/device/add
- Method: POST
- Data type:
application/json
Example request:
- URL:
http://118.70.11.36:9100/device/add
- JSON Payload:
{
"address": "Harbour view, Ngoc Thuy",
"about": "Building gateway camera"
}
Response:
{
"status": 1,
"message": "OK",
"device": {
"id": "b0373d79af75e511b6405690b5ffb086",
"address": "Harbour view, Ngoc Thuy",
"secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImIwMzczZDc5YWY3NWU1MTFiNjQwNTY5MGI1ZmZiMDg2IiwiYWRkcmVzcyI6IkhhcmJvdXIgdmlldywgIE5nb2MgVGh1eSIsInNlY3JldCI6bnVsbCwic3RhdHVzIjowLCJhYm91dCI6IkJ1aWxkaW5nIGdhdGV3YXkgY2FtZXJhIiwiY3JlYXRlZCI6IjIwMTctMDUtMjNUMTU6NDk6NTMuMTc5WiIsImlhdCI6MTQ5NTU1NDU5M30.bLLVwvm8MYnykX5KVt23YnozgdmDQD8JQ",
"status": 0,
"about": "Building gateway camera",
"created": "2017-05-23T15:49:53.179Z"
}
}
Get device information
Get all information on device by device id
- URL:
http://server_root/device/info/:id
- Method: GET
- Parameter: id is device id
Example request:
- URL:
http://118.70.11.36:9100/device/info/5c942674c92dae2f4f70994e0d5d5f58
Response:
{
"status": 1,
"message": "OK",
"device": {
"id": "5c942674c92dae2f4f70994e0d5d5f58",
"address": "No 8, Trang Thi, Hoan Kiem, Hanoi",
"secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjOTQyNjc0YzkyZGFlMmY0ZjcwOTk0ZTBkNWQ1ZjU4IiwiYWRkcmVzcyI6Ik5vIDgsIFRyYW5nIFRoaSwgSG9hbiBLaWVtLCBIYW5vaSIsInNlY3JldCI6IjZnZmhnZmhmIiwic3RhdHVzIjowLCJhYm91dCI6IkNhbWVyYSBmb3Igb2ZmaWNlIiwiY3JlYXRlZCI6IjIwMTctMDUtMThUMTU6MjI6MzAuMDAwWiIsImlhdCI6MTQ5NTI3MDcxNX0.41ERZl1CISqPOMxT7T6Kq0zpJ-_BmI",
"status": 0,
"about": "Camera for office",
"created": "2017-05-18T15:22:30.000Z"
}
}
Delete device
- URL:
http://server_root/device/delete/:id
- Method: GET
- Parameter: id is device id
Example request:
- URL:
http://118.70.11.36:9100/device/delete/baf62b0ef6e7c9903b0a3b7ea707061e
- Response:
{
"status": 1,
"message": "Deleted",
"device_id": "baf62b0ef6e7c9903b0a3b7ea707061e"
}
Update device information
- URL:
http://server_root/device/update
- Method: POST
- Data type:
application/json
Example request:
- URL:
http://118.70.11.36:9100/device/update
- JSON payload
{
"id": "b0373d79af75e511b6405690b5ffb086",
"address": "Harbour view, Ngoc Thuy, Long Bien",
"about": "Building gateway camera - for security"
}
Response:
{
"status": 1,
"message": "OK",
"device": {
"id": "ceb0b97a7acbc0570df1cc7b194258d8",
"address": "Harbour view, Ngoc Thuy, Long Bien",
"secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9….xeBA2xTc1kxugapHHPzwxUR0du2ZPmmsZquKs",
"status": 0,
"about": "Building gateway camera - for security",
"created": "2017-05-31T15:27:41.985Z"
}
}
On Socket server
We create socket server in this project in order to send message to Surveillance board on new event occurred in system in real-time manner.
Server send new event to socket client by following format:
- message title: 'New_Message'
- content: JSON object
Example message body of event:
{
"user_id": "PapaiKing",
"name": "Thuc X.Vu",
"picture": "https://img.linkedface.com/ifaces/thumbs/300/2017-05-16/118.70.217.99_1494898191.37005_image201610280001.jpg",
"similarity": 0.1,
"event_picture": "https://img.linkedface.com/search/imgs/2017-05-31/118.70.217.99_1496207329.94350_facechecker_12-08-49-249793.jpg",
"type": 1,
"valid": 1
}
Database
Event table
Table name: event
Index | Name | Type | Description |
---|---|---|---|
1 | id | varchar(50) | Hash value |
2 | user_id | varchar(50) | Id of user appearing in image |
3 | created | timestamp | Time of creating this event |
4 | name | varchar(50) | Name of user appearing in image |
5 | picture | varchar(512) | Avatar image of user in image |
6 | device_id | varchar(50) | Id of device that sent this event |
7 | similarity | double | Similarity between face in captured image (by camera) and face in profile images of regcognized user |
8 | event_picture | varchar(512) | image that's captured by camera |
9 | type | int(11) | Type of event:0: Others1: Check in2: Check out |
10 | valid | int(11) | 1: Valid - accepted the similarity; recognizing result is correct and trusted; 0: Invalid |
Device table
Table Name: device
Index | Name | Type | Description |
---|---|---|---|
1 | id | varchar(50) | hash value |
2 | address | varchar(512) | |
3 | secret | varchar(128) | use JWT |
4 | status | int(11) | 0: newly created; 1: stopped; 2: running; 3: deleted |
5 | about | text | |
6 | created | Timestamp | Time of creating device |