Skip to content

Commit fa49861

Browse files
author
Ubuntu
committed
TRF
1 parent ffbef9f commit fa49861

File tree

5 files changed

+210
-18
lines changed

5 files changed

+210
-18
lines changed

‎protobufs/messages/ImageInferenceRequest.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package imageInferenceRequest;
22
syntax = "proto3";
33

44
message ImageInferenceRequest {
5-
string Test = 1; // becomes awesomeField
5+
bytes image = 1;
66
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package pacientsAndEmotionsInferenceReply;
2+
syntax = "proto3";
3+
4+
message PacientsAndEmotionsInferenceReply {
5+
repeated PacientAndEmotionsDetected detections = 1;
6+
7+
8+
}
9+
10+
message PacientAndEmotionsDetected {
11+
string uuid = 1;
12+
BodyBoxCenter bodyCenter = 2;
13+
FaceRect faceRect = 3;
14+
EmotionsDetected emotionsDetected = 4;
15+
16+
}
17+
18+
message BodyBoxCenter {
19+
uint32 x = 1;
20+
uint32 y = 2;
21+
22+
}
23+
24+
message FaceRect {
25+
uint32 x1 = 1;
26+
uint32 y1 = 2;
27+
uint32 x2 = 3;
28+
uint32 y2 = 4;
29+
30+
}
31+
32+
message EmotionsDetected {
33+
map<string,float> continuous = 1;
34+
repeated string categorical = 2;
35+
36+
}
37+
38+
39+

‎protobufs/messages/TestingProto.proto

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package testing;
2+
syntax = "proto3";
3+
4+
message Testing {
5+
repeated string nome = 1;
6+
7+
}
8+
9+

‎protobufs/services/ms_imageInference.proto

+34-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,46 @@ syntax = "proto3";
33
package imageInference;
44

55
service ImageInferenceService {
6-
rpc Inference (InferenceRequest) returns (MixedRealityStreamInferenceReply) { }
6+
rpc PacientsAndEmotionsInference (InferenceRequest) returns (PacientsAndEmotionsInferenceReply) { }
77
}
88

99
message InferenceRequest {
10-
string image = 1;
10+
bytes image = 1;
1111

1212
}
1313

14-
message MixedRealityStreamInferenceReply {
15-
uint32 pred = 1;
14+
message PacientsAndEmotionsInferenceReply {
15+
repeated PacientAndEmotionsDetected detections = 1;
1616

1717
}
1818

19+
message PacientAndEmotionsDetected {
20+
string uuid = 1;
21+
BodyBoxCenter bodyCenter = 2;
22+
FaceRect faceRect = 3;
23+
EmotionsDetected emotionsDetected = 4;
24+
25+
}
26+
27+
message BodyBoxCenter {
28+
uint32 x = 1;
29+
uint32 y = 2;
30+
31+
}
32+
33+
message FaceRect {
34+
uint32 x1 = 1;
35+
uint32 y1 = 2;
36+
uint32 x2 = 3;
37+
uint32 y2 = 4;
38+
39+
}
40+
41+
message EmotionsDetected {
42+
map<string,float> continuous = 1;
43+
repeated string categorical = 2;
44+
45+
}
46+
47+
48+

‎server.js

+127-13
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,153 @@ const grpcClient = require('./grpc_client')
1111

1212
var protobuf = require("protobufjs");
1313

14-
1514
wss.on('connection', (ws) => {
1615
console.log("A new client connected")
16+
1717

1818
ws.on('message', function incoming(message) {
1919

20-
ws.binaryType = 'arraybuffer'
20+
//ws.binaryType = 'arraybuffer'
2121

22-
//console.log("Receved: %s", message)
23-
console.log("Message received")
22+
console.log("Receved: %s", message)
23+
//console.log("Message received")
2424

25-
console.log(message.byteLength)
25+
//console.log(message.byteLength)
26+
/*
27+
protobuf.load("protobufs/messages/PacientsAndEmotionsInferenceReply.proto", function(err, root) {
28+
if (err)
29+
throw err;
30+
31+
var reply = root.lookupType("pacientsAndEmotionsInferenceReply.PacientsAndEmotionsInferenceReply");
32+
33+
var payload = { nome : ["dsad", "dsa"] }
34+
var errMsg = reply.verify(payload)
35+
if (errMsg)
36+
throw Error(errMsg)
37+
38+
var message = reply.create(payload)
39+
ws.binaryType = 'arraybuffer'
40+
console.log('2 Message:', message);
41+
var buf = reply.encode(message).finish()
42+
console.log("Check: ", typeof(buf))
43+
var decoded = reply.decode(buf);
44+
var what =buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length)
45+
console.log("Check: ", typeof(what))
46+
ws.send(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length))
47+
ws.send("test")
48+
console.log('Test:', decoded);
49+
console.log("----")
50+
console.log("----")
51+
console.log("----")
52+
console.log("----")
53+
54+
})
55+
56+
*/
57+
//ws.binaryType = 'arraybuffer'
58+
59+
60+
2661

2762
const client = new grpcClient.imageInference.ImageInferenceService(
28-
'5.tcp.eu.ngrok.io:17400',
63+
'7.tcp.eu.ngrok.io:12401',
2964

3065
grpc.credentials.createInsecure()
3166
);
32-
67+
68+
var inferenceResult
69+
var request
3370
protobuf.load("protobufs/messages/ImageInferenceRequest.proto", function(err, root) {
34-
var request = root.lookupType("imageInferenceRequest.ImageInferenceRequest");
71+
request = root.lookupType("imageInferenceRequest.ImageInferenceRequest");
72+
73+
console.log("So it begins...")
3574

36-
var decoded = request.decode(message);
75+
var decoded = request.decode(new Uint8Array(message));
3776

38-
client.Inference({ image: decoded['Test'] }, function (err, response) {
39-
console.log('Message:', response.pred);
40-
ws.send(response.pred)
77+
client.PacientsAndEmotionsInference({ image: decoded['image'] }, function (err, response) {
78+
console.log('0 Message:', response.detections);
79+
console.log('R Message:', response);
80+
console.log('Response in JSON:', JSON.stringify(response))
81+
inferenceResult = response.detections
82+
console.log("----")
83+
console.log(response.detections.length)
84+
if(response.detections.length > 0) {
85+
console.log(response.detections[0]['emotionsDetected']['continuous'])
86+
console.log(response.detections[0]['emotionsDetected']['categorical'])
87+
88+
/*
89+
protobuf.load("protobufs/messages/PacientsAndEmotionsInferenceReply.proto", function(err, root) {
90+
var reply = root.lookupType("pacientsAndEmotionsInferenceReply.PacientsAndEmotionsInferenceReply");
91+
console.log('1 Message:', inferenceResult);
92+
var message = reply.create({ detections : [
93+
{
94+
uuid: 'test',
95+
bodyCenter: { x: 894, y: 407 },
96+
faceRect: { x1: 0, y1: 0, x2: 0, y2: 0 },
97+
emotionsDetected: {
98+
categorical: [],
99+
continuous: {
100+
"Valence": 0.0,
101+
"Arousal": 0.0,
102+
"Dominance": 0.0
103+
}
104+
}
105+
}
106+
] })
107+
console.log('2 Message:', message);
108+
var buf = reply.encode(message).finish()
109+
console.log("Check: ", typeof(buf))
110+
var decoded = reply.decode(buf);
111+
console.log('Mine:', decoded);
112+
console.log('Test 0:', decoded.detections[0])
113+
console.log("----")
114+
ws.send(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length))
115+
console.log("----")
116+
console.log("And now it ends")
117+
console.log("----")
118+
})*/
119+
120+
protobuf.load("protobufs/messages/PacientsAndEmotionsInferenceReply.proto", function(err, root) {
121+
var reply = root.lookupType("pacientsAndEmotionsInferenceReply.PacientsAndEmotionsInferenceReply");
122+
console.log('1 Message:', inferenceResult);
123+
var message = reply.create({ detections : [
124+
{
125+
uuid: 'test',
126+
bodyCenter: { x: 894, y: 407 },
127+
faceRect: { x1: 23, y1: 0, x2: 0, y2: 0 },
128+
emotionsDetected: {
129+
categorical: ["Oidasdasd"],
130+
continuous: {
131+
"Valence": 2.4,
132+
"Arousal": 0.0,
133+
"Dominance": 0.0
134+
}
135+
}
136+
}
137+
] })
138+
console.log('2 Message:', message);
139+
var buf = reply.encode(message).finish()
140+
console.log("Check: ", typeof(buf))
141+
var decoded = reply.decode(buf);
142+
console.log('Mine:', decoded);
143+
console.log('Test 0:', decoded.detections[0])
144+
console.log(JSON.stringify(decoded))
145+
console.log("----")
146+
ws.send(JSON.stringify(response))
147+
console.log("----")
148+
console.log("And now it ends")
149+
console.log("----")
150+
})
151+
152+
}
153+
41154
});
42155

156+
43157
})
44158

159+
45160

46-
ws.send(message.buffer)
47161
})
48162

49163
})

0 commit comments

Comments
 (0)