-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathframeDoneIPC.m
executable file
·67 lines (51 loc) · 2.15 KB
/
frameDoneIPC.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
classdef frameDoneIPC
properties
hSI
listeners={}
context
publisher
channel
flags
future
end
methods
function obj = frameDoneIPC(zeromq_jar_path, zeromq_protocol, zeromq_host, zeromq_port, channel)
% initalize zeromq for IPC: send images to other processes
javaclasspath(zeromq_jar_path)
import org.zeromq.*
obj.context = ZContext();
% Pull in ScanImage API handle
scanimageObjectName='hSI';
W = evalin('base','whos');
if ~ismember(scanimageObjectName,{W.name})
fprintf('Can not find ScanImage API handle in base workspace. Please start ScanImage\n')
obj.delete
return
end
obj.hSI = evalin('base',scanimageObjectName); % get hSI from the base workspace
obj.channel = channel;
obj.flags = ZMQ.DONTWAIT;
publisher_address = zeromq_protocol + zeromq_host + ":" + string(zeromq_port);
obj.publisher = obj.context.createSocket(SocketType.PUSH);
obj.publisher.bind(publisher_address);
% Add a listener to the the notifier that fires when a frame is acquired.
% This is the same notifier used for user functions.
obj.listeners{1} = addlistener(obj.hSI.hUserFunctions ,'frameAcquired', @obj.fAcq);
% looks like this makes a copy of the object?
end
function delete(obj)
cellfun(@delete,obj.listeners)
end
function fAcq(obj,source,event,varargin)
% get image data
buffer = obj.hSI.hDisplay.stripeDataBuffer{1};
frame = buffer.roiData{1}.imageData{obj.channel}{1};
% rescale image
im_min = obj.hSI.hChannels.channelLUT{obj.channel}(1);
im_max = obj.hSI.hChannels.channelLUT{obj.channel}(2);
frame = (single(frame) - single(im_min))./(single(im_max)-single(im_min));
% send image via ZMQ
obj.publisher.send(serialize(frame'), obj.flags);
end
end
end