-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_message.m
48 lines (33 loc) · 1.19 KB
/
process_message.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function process_message(~,e)
%convert json string to struct
message_struct = loadjson(char(e.message));
raw = base64decode(message_struct.imageBase64, '', 'java');
% decode image stream using Java
jImg = javax.imageio.ImageIO.read(java.io.ByteArrayInputStream(raw));
h = jImg.getHeight;
w = jImg.getWidth;
% set dimensions of the current handle
hfig = gcf;
pos = get(hfig, 'Position');
if(pos(1,3) ~= w)
pos(1,3) = w;
pos(1,4) = h;
set(hfig, 'Position', pos);
end
p = typecast(jImg.getData.getDataStorage, 'uint8');
img = permute(reshape(p, [3 w h]), [3 2 1]);
img = img(:,:,[3 2 1]);
image(img)
% Draw bounding boxes
if(~isempty(message_struct.bb))
%disp('Received Bounding Box:')
%disp(message_struct.bb)
hold on
x = abs(str2num(message_struct.bb.xcoord))*w;
y = abs(str2num(message_struct.bb.ycoord))*h;
wbb = abs(str2num(message_struct.bb.width))*w;
hbb = abs(str2num(message_struct.bb.height))*h;
rectangle('Position', [x y wbb hbb], 'LineWidth',2, 'EdgeColor','b')
hold off
end
end