first commit
This commit is contained in:
BIN
src/Flowcytometer_matlab _code/flowcytometergui.fig
Normal file
BIN
src/Flowcytometer_matlab _code/flowcytometergui.fig
Normal file
Binary file not shown.
217
src/Flowcytometer_matlab _code/flowcytometergui.m
Normal file
217
src/Flowcytometer_matlab _code/flowcytometergui.m
Normal file
@@ -0,0 +1,217 @@
|
||||
function varargout = flowcytometergui(varargin)
|
||||
% FLOWCYTOMETERGUI MATLAB code for flowcytometergui.fig
|
||||
% FLOWCYTOMETERGUI, by itself, creates a new FLOWCYTOMETERGUI or raises the existing
|
||||
% singleton*.
|
||||
%
|
||||
% H = FLOWCYTOMETERGUI returns the handle to a new FLOWCYTOMETERGUI or the handle to
|
||||
% the existing singleton*.
|
||||
%
|
||||
% FLOWCYTOMETERGUI('CALLBACK',hObject,eventData,handles,...) calls the local
|
||||
% function named CALLBACK in FLOWCYTOMETERGUI.M with the given input arguments.
|
||||
%
|
||||
% FLOWCYTOMETERGUI('Property','Value',...) creates a new FLOWCYTOMETERGUI or raises the
|
||||
% existing singleton*. Starting from the left, property value pairs are
|
||||
% applied to the GUI before flowcytometergui_OpeningFcn gets called. An
|
||||
% unrecognized property name or invalid value makes property application
|
||||
% stop. All inputs are passed to flowcytometergui_OpeningFcn via varargin.
|
||||
%
|
||||
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
|
||||
% instance to run (singleton)".
|
||||
%
|
||||
% See also: GUIDE, GUIDATA, GUIHANDLES
|
||||
|
||||
% Edit the above text to modify the response to help flowcytometergui
|
||||
|
||||
% Last Modified by GUIDE v2.5 09-Jul-2018 11:27:06
|
||||
|
||||
% Begin initialization code - DO NOT EDIT
|
||||
gui_Singleton = 1;
|
||||
gui_State = struct('gui_Name', mfilename, ...
|
||||
'gui_Singleton', gui_Singleton, ...
|
||||
'gui_OpeningFcn', @flowcytometergui_OpeningFcn, ...
|
||||
'gui_OutputFcn', @flowcytometergui_OutputFcn, ...
|
||||
'gui_LayoutFcn', [] , ...
|
||||
'gui_Callback', []);
|
||||
if nargin && ischar(varargin{1})
|
||||
gui_State.gui_Callback = str2func(varargin{1});
|
||||
end
|
||||
|
||||
if nargout
|
||||
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
|
||||
else
|
||||
gui_mainfcn(gui_State, varargin{:});
|
||||
end
|
||||
% End initialization code - DO NOT EDIT
|
||||
|
||||
|
||||
% --- Executes just before flowcytometergui is made visible.
|
||||
function flowcytometergui_OpeningFcn(hObject, eventdata, handles, varargin)
|
||||
% This function has no output args, see OutputFcn.
|
||||
% hObject handle to figure
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
% varargin command line arguments to flowcytometergui (see VARARGIN)
|
||||
|
||||
% Choose default command line output for flowcytometergui
|
||||
handles.output = hObject;
|
||||
s = serial('COM12');
|
||||
set(s,'BaudRate',57600); set(s,'Terminator','#');
|
||||
set(s,'Timeout',30); % s.RecordName = 'CytoSerialTxnLog.txt';
|
||||
fopen(s); % record(s);
|
||||
handles.s = s;
|
||||
|
||||
msg=strcat(datestr(clock,'yyyy-mm-dd-HHMM'),'m',datestr(clock,'ss'),'s');
|
||||
fid = fopen(strcat(msg,'.txt'),'w');
|
||||
handles.fid = fid;
|
||||
if (fid == -1)
|
||||
disp('could not open logging file. You probably need to change working directory to the one where the MATLAB file is located.');
|
||||
return;
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Start cam
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
tic
|
||||
fprintf(fid, '\r\nStarting camera...');
|
||||
% choose which webcam (winvideo-1) and which mode (YUY2_176x144)
|
||||
%vid = videoinput('winvideo', 1, 'RGB32_744x480');
|
||||
vid = videoinput('winvideo', 2, 'RGB24_640x480');
|
||||
% Configure the object for manual trigger mode.
|
||||
triggerconfig(vid, 'manual');
|
||||
% only capture one frame per trigger, we are not recording a video
|
||||
vid.FramesPerTrigger = 1;
|
||||
% output would image in RGB color space
|
||||
vid.ReturnedColorspace = 'rgb';
|
||||
% tell matlab to start the webcam on user request, not automatically
|
||||
triggerconfig(vid, 'manual');
|
||||
% we need this to know the image height and width
|
||||
vidRes = get(vid, 'VideoResolution');
|
||||
% image width
|
||||
imWidth = vidRes(1);
|
||||
% image height
|
||||
imHeight = vidRes(2);
|
||||
% number of bands of our image (should be 3 because it's RGB)
|
||||
nBands = get(vid, 'NumberOfBands');
|
||||
% create an empty image container and show it on axPreview
|
||||
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview);
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% do auto white balance
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
src = getselectedsource(vid);
|
||||
% src.BalanceWhiteAuto = 'Continuous';
|
||||
% begin the webcam preview
|
||||
currzpos = 0;
|
||||
preview(vid, hImage);
|
||||
% expose the objects so we can handle them in other functions
|
||||
handles.vid = vid;
|
||||
handles.src = src;
|
||||
handles.currz = currzpos;
|
||||
guidata(hObject,handles);
|
||||
%start(vid);
|
||||
drawnow;
|
||||
|
||||
% % set and display the exposure
|
||||
% src.ExposureTime = 360;
|
||||
%set(handles.expDisp,'string', src.ExposureTime );
|
||||
Time_to_init_cam = toc
|
||||
|
||||
% Update handles structure
|
||||
guidata(hObject, handles);
|
||||
|
||||
% UIWAIT makes flowcytometergui wait for user response (see UIRESUME)
|
||||
% uiwait(handles.figure1)
|
||||
|
||||
% --- Outputs from this function are returned to the command line.
|
||||
function varargout = flowcytometergui_OutputFcn(hObject, eventdata, handles)
|
||||
% varargout cell array for returning output args (see VARARGOUT);
|
||||
% hObject handle to figure
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
|
||||
% Get default command line output from handles structure
|
||||
varargout{1} = handles.output;
|
||||
|
||||
|
||||
% --- Executes on button press in autofocus.
|
||||
function autofocus_Callback(hObject, eventdata, handles)
|
||||
% hObject handle to autofocus (see GCBO)
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
s = handles.s; vid = handles.vid; currzpos = handles.currz;
|
||||
[~, ~, ~] = focusstack_1(s,vid,currzpos);pause(2)
|
||||
|
||||
|
||||
|
||||
|
||||
% --- Executes on button press in moveleft.
|
||||
function moveleft_Callback(hObject, eventdata, handles)
|
||||
% hObject handle to moveleft (see GCBO)
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
s = handles.s; fprintf(s,'A')
|
||||
|
||||
|
||||
% --- Executes on button press in moveright.
|
||||
function moveright_Callback(hObject, eventdata, handles)
|
||||
% hObject handle to moveright (see GCBO)
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
s = handles.s; fprintf(s,'D')
|
||||
|
||||
|
||||
% --- Executes on button press in snapshot.
|
||||
function snapshot_Callback(hObject, eventdata, handles)
|
||||
% hObject handle to snapshot (see GCBO)
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
vid = handles.vid;
|
||||
snapshot = getsnapshot(vid);
|
||||
imwrite(snapshot,'snap.jpg')
|
||||
|
||||
function figure1_DeleteFcn(hObject, eventdata, handles)
|
||||
% hObject handle to figure1 (see GCBO)
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
|
||||
if ~isempty(instrfind)
|
||||
fclose(instrfind);
|
||||
delete(instrfind);
|
||||
end
|
||||
|
||||
try
|
||||
fid=handles.fid; fclose(fid);
|
||||
vid = handles.vid; stoppreview(vid); delete(vid);
|
||||
catch
|
||||
clear all;
|
||||
clc;
|
||||
end
|
||||
|
||||
%s=handles.s; fclose(s); delete(s);
|
||||
disp('Killed all before exiting');
|
||||
|
||||
|
||||
% --- Executes on button press in startvid.
|
||||
function startvid_Callback(hObject, eventdata, handles)
|
||||
% hObject handle to startvid (see GCBO)
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
vid = handles.vid;
|
||||
vid_trigger = 1; handles.vid_trigger = vid_trigger;
|
||||
for x=1:1000
|
||||
snap = getsnapshot(vid)
|
||||
imwrite(strcat('Image_',num2str(x),'.jpg'),snap)
|
||||
end
|
||||
% aviObject = VideoWriter('newfile.avi','Motion JPEG AVI'); handles.aviObject = aviObject;
|
||||
% open(aviObject);
|
||||
% while(vid_trigger == 1)
|
||||
% snap = getsnapshot(vid);
|
||||
% writeVideo(aviObject,snap);
|
||||
% end
|
||||
|
||||
% --- Executes on button press in stopvid.
|
||||
function stopvid_Callback(hObject, eventdata, handles)
|
||||
% hObject handle to stopvid (see GCBO)
|
||||
% eventdata reserved - to be defined in a future version of MATLAB
|
||||
% handles structure with handles and user data (see GUIDATA)
|
||||
aviObject = handles.aviObject;
|
||||
handles.vid_trigger = 0;
|
||||
close(aviObject);
|
||||
263
src/Flowcytometer_matlab _code/focusplane_4.m
Normal file
263
src/Flowcytometer_matlab _code/focusplane_4.m
Normal file
@@ -0,0 +1,263 @@
|
||||
clear;clc;
|
||||
disp('Scan Inializing........')
|
||||
tic;
|
||||
t1 = toc;
|
||||
s = serial('COM3');
|
||||
set(s,'BaudRate',57600); set(s,'Terminator','#');
|
||||
set(s,'Timeout',30); %s.RecordName = 'CytoSerialTxnLog.txt';
|
||||
fopen(s); %recweblistord(s);
|
||||
msg=strcat(datestr(clock,'yyyy-mm-dd-HHMM'),'m',datestr(clock,'ss'),'s');
|
||||
fid = fopen(strcat(msg,'.txt'),'w');
|
||||
if (fid == -1)
|
||||
disp('could not open logging file. You probably need to change working directory to the one where the MATLAB file is located.');
|
||||
return;
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Start cam
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
tic
|
||||
disp('\r\nStarting camera...')
|
||||
fprintf(fid, '\r\nStarting camera...');
|
||||
% choose which webcam (winvideo-1) and which mode (YUY2_176x144)
|
||||
%vid = videoinput('winvideo', 1, 'RGB32_744x480');
|
||||
vid = videoinput('gentl', 1, 'BGRA8Packed');
|
||||
% Configure the object for manual trigger mode.
|
||||
triggerconfig(vid, 'manual');
|
||||
% only capture one frame per trigger, we are not recording a video
|
||||
vid.FramesPerTrigger = 1;
|
||||
% output would image in RGB color space
|
||||
vid.ReturnedColorspace = 'rgb';
|
||||
% tell matlab to start the webcam on user request, not automatically
|
||||
triggerconfig(vid, 'manual');
|
||||
% we need this to know the image height and width
|
||||
vidRes = get(vid, 'VideoResolution');
|
||||
% image width
|
||||
imWidth = vidRes(1);
|
||||
% image height
|
||||
imHeight = vidRes(2);
|
||||
% number of bands of our image (should be 3 because it's RGB)
|
||||
nBands = get(vid, 'NumberOfBands');
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% do auto white balance
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
src = getselectedsource(vid);
|
||||
src.BalanceWhiteAuto = 'Continuous';
|
||||
|
||||
src.ExposureTime = 800;
|
||||
start(vid);
|
||||
Time_to_init_cam = toc
|
||||
|
||||
% this is the slide name
|
||||
setslidename = 'Slide';
|
||||
|
||||
|
||||
fprintf(s,'J');currxpos = 0;
|
||||
fprintf(s,'K');currypos = 0;
|
||||
fprintf(s,'L');currzpos = 0;
|
||||
pause(0.1);
|
||||
disp('Origin is set');
|
||||
|
||||
xFoV = round(1280*5.3/(34*0.159));yFoV = round(1024*5.3/(34*0.159));
|
||||
xFoV_mm = 0.1995;yFoV_mm = 0.1596;
|
||||
|
||||
XPulseRate = 38400; YPulseRate = 38400 ;
|
||||
Xzadjustdelay = 0.002;
|
||||
autoContrTime = 0.1;
|
||||
XImDelay = (xFoV / XPulseRate) ;
|
||||
YImDelay = (yFoV / YPulseRate) ;
|
||||
%at y = 12.5mm line
|
||||
Ypos = strcat('+',sprintf('%06d',abs(41359)));
|
||||
fprintf(s,'N'); fprintf(s,Ypos);pause(41359/YPulseRate);currypos=41359;
|
||||
param_y0 =[];Zval=[];
|
||||
xpos1 = 0; xpos2 = 200000;
|
||||
[currzpos, temp_var] = focusstack_1(s,vid,currzpos);pause(2)
|
||||
tf1 = toc;
|
||||
for xpos = xpos1:17986:xpos2
|
||||
Xpos = strcat('+',sprintf('%06d',abs(xpos )));
|
||||
fprintf(s,'B'); fprintf(s,Xpos);pause(17986/XPulseRate)
|
||||
[currzpos, temp_var] = focusstack_2(s,vid,currzpos);
|
||||
Zval = [Zval currzpos];
|
||||
snapshot=getsnapshot(vid);
|
||||
disp('saving best focussed snapshot..')
|
||||
imwrite(snapshot,strcat('images/finding_best_region/t7/t7_x_',Xpos,'_',sprintf('%06d',abs(currzpos)),'.bmp'));
|
||||
param_y0 = [param_y0 parameter(snapshot)]; currxpos = xpos;
|
||||
end
|
||||
disp(toc-tf1)
|
||||
xpos = xpos1:17986:xpos2;
|
||||
[max_param_y0, Index] = max(param_y0);
|
||||
xbest1 = abs(xpos(Index));
|
||||
Xbest1 = strcat('+',sprintf('%06d',xbest1));
|
||||
fprintf(s,'B'); fprintf(s,Xpos);pause(abs(currxpos-xbest1)/XPulseRate)
|
||||
Zfoc1 = Zval(Index);gotoZ(s,Zfoc1,currzpos);currzpos=Zfoc1;param_y1 = []; Zval=[];
|
||||
tf2 =toc;
|
||||
if(xbest1 <= 17986)
|
||||
for xpos = (xbest1):7194:(xbest1+17986*2)
|
||||
Xpos = strcat('+',sprintf('%06d',abs(xpos )));
|
||||
fprintf(s,'B'); fprintf(s,Xpos);pause(17986/XPulseRate)
|
||||
[currzpos, temp_var] = focusstack_2(s,vid,currzpos);
|
||||
Zval = [Zval currzpos];
|
||||
snapshot=getsnapshot(vid);
|
||||
disp('saving best focussed snapshot..')
|
||||
imwrite(snapshot,strcat('images/finding_best_region/t7/t7_x_',Xpos,'_',sprintf('%06d',abs(currzpos)),'.bmp'));
|
||||
param_y1 = [param_y1 parameter(snapshot)]; currxpos = xpos;
|
||||
end
|
||||
elseif(xbest1>=200000)
|
||||
for xpos = (xbest1-17986*2):7194:(xbest1)
|
||||
Xpos = strcat('+',sprintf('%06d',abs(xpos )));
|
||||
fprintf(s,'B'); fprintf(s,Xpos);pause(17986/XPulseRate)
|
||||
[currzpos, temp_var] = focusstack_2(s,vid,currzpos);
|
||||
Zval = [Zval currzpos];
|
||||
snapshot=getsnapshot(vid);
|
||||
disp('saving best focussed snapshot..')
|
||||
imwrite(snapshot,strcat('images/finding_best_region/t7/t7_x_',Xpos,'_',sprintf('%06d',abs(currzpos)),'.bmp'));
|
||||
param_y1 = [param_y1 parameter(snapshot)]; currxpos = xpos;
|
||||
end
|
||||
else
|
||||
for xpos = (xbest1-17986):7194:(xbest1+17986)
|
||||
Xpos = strcat('+',sprintf('%06d',abs(xpos )));
|
||||
fprintf(s,'B'); fprintf(s,Xpos);pause(17986/XPulseRate)
|
||||
[currzpos, temp_var] = focusstack_2(s,vid,currzpos);
|
||||
Zval = [Zval currzpos];
|
||||
snapshot=getsnapshot(vid);
|
||||
disp('saving best focussed snapshot..')
|
||||
imwrite(snapshot,strcat('images/finding_best_region/t7/t7_x_',Xpos,'_',sprintf('%06d',abs(currzpos)),'.bmp'));
|
||||
param_y1 = [param_y1 parameter(snapshot)]; currxpos = xpos;
|
||||
end
|
||||
end
|
||||
disp(toc-tf2)
|
||||
xpos = (xbest1-17896):7194:(xbest1+17896);
|
||||
param_y1 = (param_y1>0.0999);disp(param_y1)
|
||||
target1 = sum(param_y1(1:3)); target2 = sum(param_y1(3:5));
|
||||
fprintf(s,'N'); fprintf(s,'0000000');pause(abs(41359)/YPulseRate);
|
||||
tf3=toc;
|
||||
if((sum(param_y1(2:4))==3))
|
||||
xbest2 = xpos(2);xbest1 = xpos(4);
|
||||
Xbest2 = strcat('+',sprintf('%06d',xbest2));
|
||||
Xbest1 = strcat('+',sprintf('%06d',xbest1));
|
||||
fprintf(s,'B'); fprintf(s,Xbest1);pause((abs(currxpos-xbest1))/XPulseRate);gotoZ(s,Zval(4),currzpos);currzpos=Zval(4);fprintf(s,'R');
|
||||
fprintf(s,'B'); fprintf(s,Xbest2);pause((abs(17986))/XPulseRate);gotoZ(s,Zval(2),currzpos);currzpos=Zval(2);fprintf(s,'E');currxpos = xbest2;
|
||||
fprintf(s,'N'); fprintf(s,'0078719');pause(abs(78719)/YPulseRate);currypos = 78719;
|
||||
[currzpos, temp_var] = focusstack_2(s,vid,currzpos);fprintf(s,'Y');
|
||||
fprintf(s,'Z');
|
||||
xA = xbest2; xB = xbest1;
|
||||
yC = 78719; yB =0;
|
||||
numofX = (xB - xA) / xFoV;
|
||||
numofY = (yC - yB) / yFoV;
|
||||
while fscanf(s) ~= 'S'
|
||||
end;
|
||||
% NOW TAKING PICTURES
|
||||
rowcount = 0;
|
||||
filecount = 0;
|
||||
|
||||
msg = '\r\n Starting image capture ...';
|
||||
fprintf(fid, msg);
|
||||
|
||||
% Dircn = false; %We believe we start from top
|
||||
while(rowcount <= numofY)
|
||||
while(filecount <= numofX)
|
||||
%pause(XImDelay*2);
|
||||
snapshot=getsnapshot(vid);
|
||||
%enh_snapshot=autocontrast(snapshot);
|
||||
filename = strcat(setslidename,'_',num2str(rowcount),'-',num2str(filecount), '.bmp');
|
||||
%imwrite(enh_snapshot,filename);
|
||||
imwrite(snapshot,strcat('images/',filename));
|
||||
filecount = filecount + 1;
|
||||
end
|
||||
% wait for shift by one FoV in Y direction
|
||||
filecount = 0;
|
||||
%pause(YImDelay*2);
|
||||
rowcount = rowcount + 1;
|
||||
end
|
||||
elseif(target1>target2)
|
||||
xbest2 = xpos(1);xbest1 = xpos(3);
|
||||
Xbest2 = strcat('+',sprintf('%06d',xbest2));
|
||||
Xbest1 = strcat('+',sprintf('%06d',xbest1));
|
||||
fprintf(s,'B'); fprintf(s,Xbest1);pause((abs(currxpos-xbest1))/XPulseRate);gotoZ(s,Zval(3),currzpos);currzpos=Zval(3);fprintf(s,'R');
|
||||
fprintf(s,'B'); fprintf(s,Xbest2);pause((abs(17986))/XPulseRate);gotoZ(s,Zval(1),currzpos);currzpos=Zval(1);fprintf(s,'E');currxpos = xbest2;
|
||||
fprintf(s,'N'); fprintf(s,'0078719');pause(abs(78719)/YPulseRate);currypos = 78719;
|
||||
[currzpos, temp_var] = focusstack_2(s,vid,currzpos);fprintf(s,'Y');
|
||||
fprintf(s,'Z');
|
||||
xA = xbest2; xB = xbest1;
|
||||
yC = 78719; yB =0;
|
||||
numofX = (xB - xA) / xFoV;
|
||||
numofY = (yC - yB) / yFoV;
|
||||
while fscanf(s) ~= 'S'
|
||||
end;
|
||||
% NOW TAKING PICTURES
|
||||
rowcount = 0;
|
||||
filecount = 0;
|
||||
|
||||
msg = '\r\n Starting image capture ...';
|
||||
fprintf(fid, msg);
|
||||
|
||||
% Dircn = false; %We believe we start from top
|
||||
while(rowcount <= numofY)
|
||||
while(filecount <= numofX)
|
||||
%pause(XImDelay*2);
|
||||
snapshot=getsnapshot(vid);
|
||||
%enh_snapshot=autocontrast(snapshot);
|
||||
filename = strcat(setslidename,'_',num2str(rowcount),'-',num2str(filecount), '.bmp');
|
||||
%imwrite(enh_snapshot,filename);
|
||||
imwrite(snapshot,strcat('images/',filename));
|
||||
filecount = filecount + 1;
|
||||
end
|
||||
% wait for shift by one FoV in Y direction
|
||||
filecount = 0;
|
||||
%pause(YImDelay*2);
|
||||
rowcount = rowcount + 1;
|
||||
end
|
||||
elseif(target1<target2)
|
||||
xbest2 = xpos(5);xbest1 = xpos(3);
|
||||
Xbest2 = strcat('+',sprintf('%06d',xbest2));
|
||||
Xbest1 = strcat('+',sprintf('%06d',xbest1));
|
||||
fprintf(s,'B'); fprintf(s,Xbest1);pause((abs(currxpos-xbest1))/XPulseRate);gotoZ(s,Zval(3),currzpos);currzpos=Zval(3);fprintf(s,'E');
|
||||
fprintf(s,'B'); fprintf(s,Xbest2);pause((abs(17986))/XPulseRate);gotoZ(s,Zval(5),currzpos);currzpos=Zval(5);fprintf(s,'R');currxpos = xbest2;
|
||||
fprintf(s,'N'); fprintf(s,'0078719');pause(abs(78719)/YPulseRate);currypos = 78719;
|
||||
[currzpos, temp_var] = focusstack_2(s,vid,currzpos);fprintf(s,'Y');
|
||||
fprintf(s,'Z');
|
||||
xA = xbest1; xB = xbest2;
|
||||
yC = 78719; yB =0;
|
||||
numofX = (xB - xA) / xFoV;
|
||||
numofY = (yC - yB) / yFoV;
|
||||
while fscanf(s) ~= 'S'
|
||||
end;
|
||||
% NOW TAKING PICTURES
|
||||
rowcount = 0;
|
||||
filecount = 0;
|
||||
|
||||
msg = '\r\n Starting image capture ...';
|
||||
fprintf(fid, msg);
|
||||
|
||||
% Dircn = false; %We believe we start from top
|
||||
while(rowcount <= numofY)
|
||||
while(filecount <= numofX)
|
||||
%pause(XImDelay*2);
|
||||
snapshot=getsnapshot(vid);
|
||||
%enh_snapshot=autocontrast(snapshot);
|
||||
filename = strcat(setslidename,'_',num2str(rowcount),'-',num2str(filecount), '.bmp');
|
||||
%imwrite(enh_snapshot,filename);
|
||||
imwrite(snapshot,strcat('images/t7/',filename));
|
||||
filecount = filecount + 1;
|
||||
end
|
||||
% wait for shift by one FoV in Y direction
|
||||
filecount = 0;
|
||||
%pause(YImDelay*2);
|
||||
rowcount = rowcount + 1;
|
||||
end
|
||||
else
|
||||
disp('Slide is not prepared well!!! Please make a good slide..!')
|
||||
end
|
||||
disp(toc-tf3)
|
||||
|
||||
stop(vid);
|
||||
fprintf(s,'N'); fprintf(s,'0000000');
|
||||
fprintf(s,'B'); fprintf(s,'0000000');
|
||||
fprintf(s,'M'); fprintf(s,'0000000');
|
||||
pause(0.1)
|
||||
|
||||
if ~isempty(instrfind)
|
||||
fclose(instrfind);
|
||||
delete(instrfind);
|
||||
end
|
||||
t2 = toc;
|
||||
disp((t2-t1)/60)
|
||||
58
src/Flowcytometer_matlab _code/focusstack_1.m
Normal file
58
src/Flowcytometer_matlab _code/focusstack_1.m
Normal file
@@ -0,0 +1,58 @@
|
||||
function [Zval, Variance, currzpos] = focusstack_1(s,vid,z)
|
||||
t1 = toc;currzpos=z;
|
||||
snap = getsnapshot(vid);
|
||||
imwrite(snap,strcat('images/withouthc/snap_at_start','.bmp'))
|
||||
%fprintf(s,'L');
|
||||
% CRUDE AF.
|
||||
Z_travel_for_crude = 16000; crude_step_count = 200;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
crude_pulse_count = Z_travel_for_crude / crude_step_count;
|
||||
crude_max_var=0; crude_loc_max_var=0;
|
||||
crude_start_loc = z-(Z_travel_for_crude/2);
|
||||
% gotoZ(s,crude_start_loc,currzpos);pause(1) ;
|
||||
fprintf(s,'M');pause(3)
|
||||
% for i=1: crude_pulse_count/2
|
||||
% fprintf(s,'T');pause(0.35)
|
||||
% end
|
||||
currzpos=crude_start_loc;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% now keep going up and taking var
|
||||
crude_curr_loc = crude_start_loc;
|
||||
Variance = []; Zval = [];
|
||||
for i=1: crude_pulse_count
|
||||
% variance
|
||||
snap = getsnapshot(vid);
|
||||
imwrite(snap,strcat('images/snap_at_',num2str(crude_curr_loc),'.bmp'))
|
||||
crude_img = double(snap); crude_curr_var=var(crude_img(:));
|
||||
%display(strcat('Variance',num2str(crude_curr_var),'Iter:',num2str(i)))
|
||||
%pause(0.5)
|
||||
Variance = [Variance crude_curr_var];
|
||||
Zval = [Zval crude_curr_loc];
|
||||
if (crude_curr_var > crude_max_var)
|
||||
crude_max_var = crude_curr_var;
|
||||
crude_loc_max_var = crude_curr_loc;
|
||||
end
|
||||
% update loc
|
||||
crude_curr_loc = crude_curr_loc + crude_step_count ;
|
||||
fprintf(s,'G');pause(0.1)
|
||||
%gotoZ(s,crude_curr_loc,currzpos);
|
||||
currzpos=crude_curr_loc;
|
||||
end
|
||||
disp(currzpos)
|
||||
disp(crude_loc_max_var)
|
||||
crude_pulse_count = round(abs(crude_loc_max_var - currzpos)/200);
|
||||
for i=1: crude_pulse_count
|
||||
if(currzpos>crude_loc_max_var)
|
||||
fprintf(s,'T');pause(0.1)
|
||||
currzpos = currzpos - 200;
|
||||
elseif(currzpos<crude_loc_max_var)
|
||||
fprintf(s,'G');pause(0.1)
|
||||
currzpos = currzpos + 200;
|
||||
end
|
||||
end
|
||||
pause(1)
|
||||
snap = getsnapshot(vid);
|
||||
imwrite(snap,strcat('images/withouthc/snap_at_end_crude','.bmp'))
|
||||
t2 = toc;
|
||||
disp(t2-t1)
|
||||
end
|
||||
88
src/Flowcytometer_matlab _code/focusstack_2.m
Normal file
88
src/Flowcytometer_matlab _code/focusstack_2.m
Normal file
@@ -0,0 +1,88 @@
|
||||
function [Zval, Variance] = focusstack_2(s,vid,z)
|
||||
t1 = toc;currzpos=z;
|
||||
% fINECRUDE AF.
|
||||
Z_travel_for_crude = 6000; crude_step_count = 200;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
crude_pulse_count = Z_travel_for_crude / crude_step_count;
|
||||
crude_max_var=0;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% go to starting Z loc (we've hit limit switch via arduino already so its z=0)
|
||||
crude_start_loc = z- (Z_travel_for_crude/2);
|
||||
gotoZ(s,crude_start_loc,currzpos); currzpos=crude_start_loc;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% now keep going up and taking var
|
||||
crude_curr_loc = crude_start_loc;
|
||||
|
||||
for i=1: crude_pulse_count
|
||||
% variance
|
||||
crude_img = double(getsnapshot(vid)); crude_curr_var=var(crude_img(:));
|
||||
|
||||
if (crude_curr_var > crude_max_var)
|
||||
crude_max_var = crude_curr_var;
|
||||
crude_loc_max_var = crude_curr_loc;
|
||||
end
|
||||
% update loc
|
||||
crude_curr_loc = crude_curr_loc + crude_step_count ;
|
||||
gotoZ(s,crude_curr_loc,currzpos); currzpos=crude_curr_loc;
|
||||
end
|
||||
gotoZ(s,crude_loc_max_var,currzpos);currzpos=crude_loc_max_var;
|
||||
|
||||
% fINECRUDE AF.
|
||||
Z_travel_for_crude = 500; crude_step_count = 50;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
crude_pulse_count = Z_travel_for_crude / crude_step_count;
|
||||
crude_max_var=0;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% go to starting Z loc (we've hit limit switch via arduino already so its z=0)
|
||||
crude_start_loc = currzpos- (Z_travel_for_crude/2);
|
||||
gotoZ(s,crude_start_loc,currzpos);currzpos=crude_start_loc;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% now keep going up and taking var
|
||||
crude_curr_loc = crude_start_loc;
|
||||
|
||||
for i=1: crude_pulse_count
|
||||
% variance
|
||||
crude_img = double(getsnapshot(vid)); crude_curr_var=var(crude_img(:));
|
||||
|
||||
if (crude_curr_var > crude_max_var)
|
||||
crude_max_var = crude_curr_var;
|
||||
crude_loc_max_var = crude_curr_loc;
|
||||
end
|
||||
% update loc
|
||||
crude_curr_loc = crude_curr_loc + crude_step_count ;
|
||||
gotoZ(s,crude_curr_loc,currzpos);currzpos=crude_curr_loc;
|
||||
end
|
||||
gotoZ(s,crude_loc_max_var,currzpos);currzpos=crude_loc_max_var;
|
||||
|
||||
% The fine AF begins here
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
Ztotaltravel = 100; final_go_backpulses = 0 ;
|
||||
currZ = crude_loc_max_var;
|
||||
|
||||
% first go above
|
||||
start_above_loc = currZ- (Ztotaltravel/2);
|
||||
gotoZ(s,start_above_loc,currzpos);currzpos=start_above_loc;
|
||||
|
||||
% now build the var array
|
||||
localAF_loc_array = zeros(1,Ztotaltravel); localAF_var_array = zeros(1,Ztotaltravel);
|
||||
localAF_curr_loc = start_above_loc;
|
||||
for q=1:(Ztotaltravel/5)
|
||||
% location
|
||||
localAF_loc_array(q) = localAF_curr_loc;
|
||||
% variance
|
||||
localAF_img = double(getsnapshot(vid)); localAF_var_array(q)=var(localAF_img(:));
|
||||
|
||||
% move and update loc
|
||||
localAF_curr_loc = localAF_curr_loc + 5; gotoZ(s,localAF_curr_loc,currzpos);
|
||||
currzpos=localAF_curr_loc;
|
||||
end
|
||||
|
||||
% Finally go to the max var location
|
||||
index_of_max_var = localAF_var_array == max(localAF_var_array);
|
||||
loc_of_max_var = localAF_loc_array(index_of_max_var) - final_go_backpulses ;
|
||||
gotoZ(s,loc_of_max_var,currzpos); currzpos=loc_of_max_var;
|
||||
Zval = loc_of_max_var;
|
||||
Variance = max(localAF_var_array);
|
||||
t2 = toc;
|
||||
disp(t2-t1)
|
||||
end
|
||||
60
src/Flowcytometer_matlab _code/focusstack_3.m
Normal file
60
src/Flowcytometer_matlab _code/focusstack_3.m
Normal file
@@ -0,0 +1,60 @@
|
||||
function [Zval, Variance] = focusstack_3(s,vid,z)
|
||||
t1 = toc;currzpos=z;
|
||||
% fINECRUDE AF.
|
||||
Z_travel_for_crude = 1000; crude_step_count = 50;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
crude_pulse_count = Z_travel_for_crude / crude_step_count;
|
||||
crude_max_var=0;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% go to starting Z loc (we've hit limit switch via arduino already so its z=0)
|
||||
crude_start_loc = z - (Z_travel_for_crude/2);
|
||||
gotoZ(s,crude_start_loc,currzpos); currzpos=crude_start_loc;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% now keep going up and taking var
|
||||
crude_curr_loc = crude_start_loc;
|
||||
|
||||
for i=1: crude_pulse_count
|
||||
% variance
|
||||
crude_img = double(getsnapshot(vid)); crude_curr_var=var(crude_img(:));
|
||||
|
||||
if (crude_curr_var > crude_max_var)
|
||||
crude_max_var = crude_curr_var;
|
||||
crude_loc_max_var = crude_curr_loc;
|
||||
end
|
||||
% update loc
|
||||
crude_curr_loc = crude_curr_loc + crude_step_count ;
|
||||
gotoZ(s,crude_curr_loc,currzpos); currzpos=crude_curr_loc;
|
||||
end
|
||||
gotoZ(s,crude_loc_max_var,currzpos);currzpos=crude_loc_max_var;
|
||||
|
||||
% The fine AF begins here
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
Ztotaltravel = 100; final_go_backpulses = 0 ;
|
||||
currZ = crude_loc_max_var;
|
||||
|
||||
% first go above
|
||||
start_above_loc = currZ - (Ztotaltravel/2);
|
||||
gotoZ(s,start_above_loc,currzpos);currzpos=start_above_loc;
|
||||
% now build the var array
|
||||
localAF_loc_array = zeros(1,Ztotaltravel); localAF_var_array = zeros(1,Ztotaltravel);
|
||||
localAF_curr_loc = start_above_loc;
|
||||
for q=1:(Ztotaltravel/5)
|
||||
% location
|
||||
localAF_loc_array(q) = localAF_curr_loc;
|
||||
% variance
|
||||
localAF_img = double(getsnapshot(vid)); localAF_var_array(q)=var(localAF_img(:));
|
||||
|
||||
% move and update loc
|
||||
localAF_curr_loc = localAF_curr_loc + 5; gotoZ(s,localAF_curr_loc,currzpos);
|
||||
currzpos=localAF_curr_loc;
|
||||
end
|
||||
|
||||
% Finally go to the max var location
|
||||
index_of_max_var = localAF_var_array == max(localAF_var_array);
|
||||
loc_of_max_var = localAF_loc_array(index_of_max_var) - final_go_backpulses ;
|
||||
gotoZ(s,loc_of_max_var,currzpos);currzpos=loc_of_max_var;
|
||||
Zval = loc_of_max_var;
|
||||
Variance = max(localAF_var_array);
|
||||
t2 = toc;
|
||||
disp(t2-t1)
|
||||
end
|
||||
14
src/Flowcytometer_matlab _code/gotoZ.m
Normal file
14
src/Flowcytometer_matlab _code/gotoZ.m
Normal file
@@ -0,0 +1,14 @@
|
||||
function gotoZ(s,check,currzpos)
|
||||
ZPulseRate = 38400;
|
||||
if(check<200000 && check>-200000)
|
||||
str = sprintf('%06d',abs(round(check))); % abs needed so that no +&- in neg numbers
|
||||
if((check) < 0)
|
||||
newstr = strcat('-',str);
|
||||
else
|
||||
newstr = strcat('+',str);
|
||||
end
|
||||
disp(strcat('moving to position:',newstr))
|
||||
% end formatting ---------- --------------------------------------------
|
||||
fprintf(s,'M'); fprintf(s, newstr ); pause(0.035);
|
||||
end
|
||||
end
|
||||
21
src/Flowcytometer_matlab _code/parameter.m
Normal file
21
src/Flowcytometer_matlab _code/parameter.m
Normal file
@@ -0,0 +1,21 @@
|
||||
function param = parameter(image)
|
||||
t1 = toc;
|
||||
bw = rgb2gray(image);
|
||||
[Gx, Gy] = imgradientxy(bw);
|
||||
%[Gmag, Gdir] = imgradient(Gx, Gy);
|
||||
gradImage = rgb2gray(imfuse(Gx,Gy));
|
||||
%temp = histeq(gradImage);
|
||||
threshImage = im2bw(gradImage,graythresh(gradImage));
|
||||
[~, radii] = imfindcircles(threshImage,[10 60]);
|
||||
cell_area = round(sum(3.14*(radii.^2)));
|
||||
bg = rgb2gray(imread('bg.jpg'));
|
||||
a = histeq(bw)-bg;
|
||||
level2 = graythresh(a);
|
||||
bgImg = bwareaopen(im2bw(a,level2),800);
|
||||
bg_pixels = sum(sum(bgImg == 1));
|
||||
fg_pixels = (1280 * 1024) - bg_pixels;
|
||||
fg_pixels = fg_pixels - round(0.1*fg_pixels);
|
||||
param = cell_area/fg_pixels;
|
||||
t2 = toc;
|
||||
disp(t2-t1)
|
||||
end
|
||||
BIN
src/Time chart .xlsx
Normal file
BIN
src/Time chart .xlsx
Normal file
Binary file not shown.
BIN
src/cloud_codeorganization.pptx
Normal file
BIN
src/cloud_codeorganization.pptx
Normal file
Binary file not shown.
744
src/current_GUIcode.py
Normal file
744
src/current_GUIcode.py
Normal file
@@ -0,0 +1,744 @@
|
||||
# 1. Name of the test is always Malaria
|
||||
# 2. Close button to be checked as abort button
|
||||
# 3. Exceptions for network connection, camera.
|
||||
|
||||
|
||||
|
||||
|
||||
#Things to be worked on:
|
||||
# 1. On window closed by clicking x at top right corner, the application should terminate
|
||||
|
||||
# 2. On abort button Clicked, the C++ API should be killed
|
||||
|
||||
# 1. Progressbar speed increased with iterations
|
||||
|
||||
# (SOLVED) 5. Setting user defined resolutions for image capture in pylon programs
|
||||
|
||||
# (SOLVED) 9. Auto focus code for variance calculation
|
||||
|
||||
# (SOLVED)2. Stopping/killing threads on abort
|
||||
|
||||
# (SOLVED)8. Adjust time for sending data through FTP that should be by stopping or killing threads while they are sleeping .... (Same as 2)
|
||||
|
||||
# (SOLVED)3. Focusing window pulse
|
||||
|
||||
# (SOLVED)4. sending data for analysis in progress bar
|
||||
|
||||
# (SOLVED)6. On abort, stop progress bar.
|
||||
|
||||
# (SOLVED)7. Run focussing only on start up.. Ask jayesh about it..
|
||||
|
||||
# (SOLVED)1.Command line executions in os.system for basler camera acquisition
|
||||
global ip1
|
||||
global ip2
|
||||
global ip3
|
||||
global batches
|
||||
global numframes
|
||||
batches=2
|
||||
numframes=5000
|
||||
ip1="54.191.132.121"
|
||||
ip2="54.191.13.206"
|
||||
ip3="52.38.126.238"
|
||||
#!/usr/bin/python
|
||||
import numpy
|
||||
#import cv2
|
||||
#from pyfirmata import Arduino, util
|
||||
from gi.repository import Gtk, GObject
|
||||
import time
|
||||
from time import sleep
|
||||
import os
|
||||
import threading
|
||||
import sys
|
||||
import thread
|
||||
from time import sleep
|
||||
global count
|
||||
global x
|
||||
from threading import Thread
|
||||
from locale import gettext as _
|
||||
import subprocess
|
||||
import ftplib
|
||||
from ftplib import FTP
|
||||
#import gpio
|
||||
import datetime
|
||||
#global Thread1
|
||||
#global Thread2
|
||||
global Acquire
|
||||
Acquire = False
|
||||
global ExitVLCThread
|
||||
ExitVLCThread = False
|
||||
global Kill
|
||||
Kill=False
|
||||
global SendCellDataThread
|
||||
SendCellDataThread = False
|
||||
import Queue
|
||||
global error1
|
||||
global error2
|
||||
global error3
|
||||
global test
|
||||
global f
|
||||
global filename
|
||||
global compress
|
||||
global st
|
||||
error1=0
|
||||
error2=0
|
||||
error3=0
|
||||
q=Queue.Queue(1)
|
||||
|
||||
#Create a directory to acquire images.
|
||||
#os.mkdir('/home/odroid/BloodAnalyser/AcquiredData/PatientInformation')
|
||||
if os.path.isdir("/home/odroid/BloodAnalyser/AcquiredData/"):
|
||||
os.system("rm -r /home/odroid/BloodAnalyser/AcquiredData/")
|
||||
os.mkdir('/home/odroid/BloodAnalyser/AcquiredData/')
|
||||
os.mkdir('/home/odroid/BloodAnalyser/AcquiredData/PatientInformation')
|
||||
|
||||
|
||||
class patientID(Gtk.Window):
|
||||
def __init__(self):
|
||||
self.builder = Gtk.Builder()
|
||||
global name
|
||||
global age
|
||||
#Get objects from patient ID Glade file
|
||||
self.builder.add_from_file('./patientID.glade')
|
||||
self.window = self.builder.get_object('entrywindow')
|
||||
self.nextbutton = self.builder.get_object('button1')
|
||||
self.okbutton=self.builder.get_object('okbutton')
|
||||
self.name = self.builder.get_object('name')
|
||||
self.age = self.builder.get_object('age')
|
||||
self.entryname=self.builder.get_object('entryname')
|
||||
self.entryage=self.builder.get_object('entryage')
|
||||
self.entrypatientID=self.builder.get_object('entrypatientID')
|
||||
#self.check_editable = Gtk.CheckButton("entryname")
|
||||
|
||||
#self.entryname = Gtk.Entry()
|
||||
|
||||
self.patientID = self.builder.get_object('patientID')
|
||||
self.builder.connect_signals(self)
|
||||
#self.entryname = Gtk.Entry()
|
||||
#self.entryage = Gtk.Entry()
|
||||
#self.entrypatientID = Gtk.Entry()
|
||||
|
||||
#print(self.entryname.get_text())
|
||||
print('rashmi')
|
||||
|
||||
self.window.show()
|
||||
def on_okbutton_clicked(self,button):
|
||||
global name
|
||||
global age
|
||||
global patientID
|
||||
global st
|
||||
ts=time.time()
|
||||
#blood=BloodAnalyser()
|
||||
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H_%M_%S')
|
||||
name=self.entryname.get_text()
|
||||
age=self.entryage.get_text()
|
||||
patientID=self.entrypatientID.get_text()
|
||||
self.window.hide()
|
||||
#filename=folder.append(st)
|
||||
#filename=filename.append(".txt")
|
||||
global test
|
||||
test="malaria"
|
||||
global filename
|
||||
filename=folder+st+".txt"
|
||||
|
||||
#return
|
||||
|
||||
|
||||
class splashScreen(Gtk.Window):
|
||||
def __init__(self):
|
||||
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file('./splash.glade')
|
||||
self.builder.connect_signals(self)
|
||||
self.window = self.builder.get_object('applicationwindow1')
|
||||
self.image1=self.builder.get_object("image1")
|
||||
self.window.show()
|
||||
#self.done=True
|
||||
#GObject.timeout_add(5000,)
|
||||
|
||||
self.window.show
|
||||
class AutoFocus(Gtk.Window):
|
||||
def __init__(self):
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file('./AutoFocus.glade')
|
||||
self.builder.connect_signals(self)
|
||||
self.window = self.builder.get_object('AutoFocus_window')
|
||||
self.image1=self.builder.get_object("image1")
|
||||
self.autofocus_pulse=self.builder.get_object("autofocus_pulse")
|
||||
|
||||
self.autofocus_start=False
|
||||
#threading.Thread(target=self.UpdateImages).start()
|
||||
|
||||
def pulse_invoke(self):
|
||||
#self.window.show()
|
||||
|
||||
try:
|
||||
os.system('v4l2-ctl -c exposure_absolute=1')
|
||||
os.system('mplayer tv:// driver=v4l2:device=/dev/video0')
|
||||
|
||||
|
||||
blood_analyser.vlc_invoke()
|
||||
#return
|
||||
except:
|
||||
error2=True
|
||||
return error2
|
||||
|
||||
def variance(self):
|
||||
try:
|
||||
os.chdir('/home/odroid/BloodAnalyser/AutoFocus')
|
||||
#os.system("make clean")
|
||||
#os.system("source /opt/pylon4/bin/pylon-setup-env.sh /opt/pylon4")
|
||||
#os.system("make")
|
||||
#os.system("chmod 777 autofocus")
|
||||
#os.system("ls")
|
||||
|
||||
#itime=time.time()
|
||||
board=Arduino('/dev/ttyACM0')
|
||||
|
||||
#cap = cv2.VideoCapture(0)
|
||||
n=1
|
||||
mylistForward=[]
|
||||
while(n < 50):
|
||||
board.digital[5].write(1)
|
||||
board.digital[6].write(1)
|
||||
# Capture frame-by-frame
|
||||
os.system("mplayer tv:// -tv driver=v4l2:device=/dev/video0:fps=20 --frames=2 -vo png")
|
||||
|
||||
# Our operations on the frame come here
|
||||
|
||||
frame=cv2.imread('/home/odroid/BloodAnalyser/AutoFocus/00000002.png')
|
||||
#image_file = '/home/rbccps/BloodAnalyser/AutoFocus/focus%d.png'%n
|
||||
self.window.show()
|
||||
|
||||
self.image1.set_from_file('/home/odroid/BloodAnalyser/AutoFocus/00000002.png')
|
||||
a=numpy.var(frame)
|
||||
print(a)
|
||||
mylistForward.append(a)
|
||||
sleep(0.1)
|
||||
n=n+1
|
||||
maxMeasure=max(mylistForward)
|
||||
maxMeasure = maxMeasure - 40
|
||||
cMeas=0
|
||||
n=0
|
||||
print '**************Motor Moving Backwards*******************'
|
||||
while(n<50):
|
||||
print("While loop entered")
|
||||
if cMeas > maxMeasure:
|
||||
board.digital[5].write(0)
|
||||
break
|
||||
board.digital[5].write(1)
|
||||
board.digital[6].write(0)
|
||||
|
||||
os.system("mplayer tv:// -tv driver=v4l2:device=/dev/video0:fps=20 --frames=2 -vo png")
|
||||
self.image1.set_from_file('/home/odroid/BloodAnalyser/AutoFocus/00000002.png')
|
||||
frame1=cv2.imread('/home/odroid/BloodAnalyser/AutoFocus/00000002.png')
|
||||
cMeas=numpy.var(frame1)
|
||||
print(cMeas)
|
||||
n=n+1
|
||||
sleep(0.1)
|
||||
board.digital[5].write(0)
|
||||
|
||||
|
||||
#cv2.destroyAllWindows()
|
||||
|
||||
#n=cap.release()
|
||||
self.window.hide()
|
||||
print(n)
|
||||
# When everything done, release the capture
|
||||
print("Capture released")
|
||||
maxMeasure= max(mylistForward)
|
||||
blood_analyser.vlc_invoke()
|
||||
|
||||
#cv2.destroyAllWindows()
|
||||
|
||||
except:
|
||||
global error1
|
||||
print("HARDWARE MISSING")
|
||||
error1=1
|
||||
return error1
|
||||
|
||||
|
||||
|
||||
def on_timeout(self, user_data):
|
||||
|
||||
if self.activity_mode:
|
||||
self.autofocus_pulse.pulse()
|
||||
else:
|
||||
new_value = self.autofocus_pulse.get_fraction() + 0.01
|
||||
|
||||
if new_value > 1:
|
||||
new_value = 0
|
||||
|
||||
self.progressbar.set_fraction(new_value)
|
||||
|
||||
# As this is a timeout function, return True so that it
|
||||
# continues to get called
|
||||
return True
|
||||
|
||||
|
||||
class quit_window(Gtk.Window):
|
||||
def __init__(self):
|
||||
self.builder = Gtk.Builder()
|
||||
os.chdir('/home/odroid/BloodAnalyser')
|
||||
self.builder.add_from_file('./quit_window.glade')
|
||||
self.builder.connect_signals(self)
|
||||
self.window = self.builder.get_object('quit_window')
|
||||
self.finishbutton = self.builder.get_object('finishbutton')
|
||||
self.another_testbutton = self.builder.get_object('another_testbutton')
|
||||
|
||||
|
||||
|
||||
def show_screen(self):
|
||||
self.window.show()
|
||||
|
||||
|
||||
def on_finishbutton_activate(self, widget):
|
||||
os.system('rm ./celldata.zip')
|
||||
os.system('rm -r ./AcquiredData')
|
||||
os.system('mkdir ./AcquiredData')
|
||||
Gtk.main_quit()
|
||||
|
||||
|
||||
def on_another_testbutton_activate(self,widget):
|
||||
#os.system('rm ./celldata.zip')
|
||||
#os.system('rm -r ./AcquiredData')
|
||||
#os.system('mkdir ./AcquiredData')
|
||||
print "ANother test selected"
|
||||
self.progressbar.set_fraction(0.0)
|
||||
self.timeout_id = GObject.timeout_add(False, self.on_timeout,None)
|
||||
|
||||
blood_analyser.start.set_label("START TEST")
|
||||
blood_analyser = BloodAnalyser()
|
||||
#splScr = splashScreen()
|
||||
patient_ID=patientID()
|
||||
Gtk.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class BloodAnalyser(Gtk.Window):
|
||||
|
||||
def __init__(self):
|
||||
global count
|
||||
count=0
|
||||
global x
|
||||
x=0
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file('./bloodAnalyser.glade')
|
||||
self.builder.connect_signals(self)
|
||||
self.window = self.builder.get_object('window1')
|
||||
self.window.show()
|
||||
|
||||
|
||||
self.infectious_disease = self.builder.get_object("infectious_disease")
|
||||
self.hamatological_disorder =self.builder.get_object("hematological")
|
||||
self.completebloodcount = self.builder.get_object("completebloodcount")
|
||||
self.malaria = self.builder.get_object("malaria")
|
||||
self.dengue = self.builder.get_object("dengue")
|
||||
self.tuberculosis = self.builder.get_object("tuberculosis")
|
||||
self.spherocytosis = self.builder.get_object("spherocytosis")
|
||||
self.sicklecellanemia=self.builder.get_object("sicklecellanemia")
|
||||
self.hereditaryelliptocytosis=self.builder.get_object("hereditaryelliptocytosis")
|
||||
self.start = self.builder.get_object("start")
|
||||
self.progressbar = self.builder.get_object("progressbar")
|
||||
self.image1=self.builder.get_object("image1")
|
||||
self.image2=self.builder.get_object("image2")
|
||||
|
||||
self.malaria.set_sensitive(True)
|
||||
self.dengue.set_sensitive(True)
|
||||
self.tuberculosis.set_sensitive(True)
|
||||
self.spherocytosis.set_sensitive(False)
|
||||
self.sicklecellanemia.set_sensitive(False)
|
||||
self.hereditaryelliptocytosis.set_sensitive(False)
|
||||
|
||||
|
||||
def on_infectiousdisease_toggled(self, button):
|
||||
if button.get_active():
|
||||
print "infectious"
|
||||
self.malaria.set_sensitive(True)
|
||||
self.dengue.set_sensitive(True)
|
||||
self.tuberculosis.set_sensitive(True)
|
||||
self.spherocytosis.set_sensitive(False)
|
||||
self.sicklecellanemia.set_sensitive(False)
|
||||
self.hereditaryelliptocytosis.set_sensitive(False)
|
||||
|
||||
|
||||
#print "infectious"
|
||||
|
||||
def on_hematological_toggled(self, button):
|
||||
if button.get_active():
|
||||
print "hematology"
|
||||
self.spherocytosis.set_sensitive(True)
|
||||
self.sicklecellanemia.set_sensitive(True)
|
||||
self.hereditaryelliptocytosis.set_sensitive(True)
|
||||
self.malaria.set_sensitive(False)
|
||||
self.dengue.set_sensitive(False)
|
||||
self.tuberculosis.set_sensitive(False)
|
||||
|
||||
|
||||
def on_completebloodcount_toggled(self, button):
|
||||
global test
|
||||
test="Complete Blood Count"
|
||||
print "blood count"
|
||||
self.spherocytosis.set_sensitive(False)
|
||||
self.sicklecellanemia.set_sensitive(False)
|
||||
self.hereditaryelliptocytosis.set_sensitive(False)
|
||||
self.malaria.set_sensitive(False)
|
||||
self.dengue.set_sensitive(False)
|
||||
self.tuberculosis.set_sensitive(False)
|
||||
self.hereditaryelliptocytosis.set_sensitive(False)
|
||||
|
||||
def on_malaria_toggled(self, widget):
|
||||
|
||||
if malaria.get_active():
|
||||
global test
|
||||
test="Malaria"
|
||||
print "on"
|
||||
#else:
|
||||
# print "off"
|
||||
def on_hereditaryelliptocytosis_toggled(self, widget):
|
||||
if hereditaryelliptocytosis.get_active():
|
||||
print "hereditaryelliptocytosis"
|
||||
global test
|
||||
test="hereditaryelliptocytosis"
|
||||
|
||||
def on_timeout_thread_end(self, user_data):
|
||||
global error1
|
||||
global error2
|
||||
global error3
|
||||
global filename
|
||||
# Error handling if the Motor pulse giving Arduino board is missing
|
||||
if error1==1:
|
||||
dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "Error!")
|
||||
dialog.format_secondary_text("Required hardware missing!.. Cannot run application")
|
||||
response = dialog.run()
|
||||
|
||||
self.progressbar.set_fraction(0.0)
|
||||
self.timeout_id = GObject.timeout_add(False, self.on_timeout,None)
|
||||
if response == Gtk.ResponseType.OK:
|
||||
self.window.close()
|
||||
dialog.destroy()
|
||||
self.window.hide()
|
||||
Gtk.main_quit()
|
||||
# Error handling if the camera is not operating properly
|
||||
elif error2==1:
|
||||
dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "Error!")
|
||||
dialog.format_secondary_text("Camera interface not found!.. Cannot run application")
|
||||
response = dialog.run()
|
||||
|
||||
self.progressbar.set_fraction(0.0)
|
||||
self.timeout_id = GObject.timeout_add(False, self.on_timeout,None)
|
||||
if response == Gtk.ResponseType.OK:
|
||||
self.window.close()
|
||||
dialog.destroy()
|
||||
self.window.hide()
|
||||
Gtk.main_quit()
|
||||
|
||||
elif error3==1:
|
||||
dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "Sending Data Error!")
|
||||
dialog.format_secondary_text("Cannot send data.")
|
||||
response = dialog.run()
|
||||
|
||||
self.progressbar.set_fraction(0.0)
|
||||
self.timeout_id = GObject.timeout_add(False, self.on_timeout,None)
|
||||
if response == Gtk.ResponseType.OK:
|
||||
self.window.close()
|
||||
dialog.destroy()
|
||||
self.window.hide()
|
||||
Gtk.main_quit()
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
if self.Thread1.is_alive():
|
||||
test_ended = False
|
||||
|
||||
else:
|
||||
test_ended = True
|
||||
text="Finished Sending Data !"
|
||||
|
||||
# text="Data Sent for Analysis"
|
||||
self.progressbar.set_text(text)
|
||||
self.activity=False
|
||||
#print("send_data status=%s",SendCellDataThread)
|
||||
self.progressbar.set_fraction(0.0)
|
||||
self.timeout_id = GObject.timeout_add(1, self.on_timeout,None)
|
||||
|
||||
|
||||
|
||||
#self.progressbar.set_fraction(0.0)
|
||||
GObject.source_remove(self.timeout_id)
|
||||
dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, "Test Complete !")
|
||||
dialog.format_secondary_text("Do you want to run another test?")
|
||||
response = dialog.run()
|
||||
if response == Gtk.ResponseType.YES:
|
||||
dialog.destroy()
|
||||
self.window.hide()
|
||||
Gtk.main_quit()
|
||||
|
||||
|
||||
|
||||
dialog.destroy()
|
||||
if response == Gtk.ResponseType.NO:
|
||||
dialog.destroy()
|
||||
#os.system('rm ./celldata.zip')
|
||||
|
||||
dialog.destroy()
|
||||
self.window.hide()
|
||||
Gtk.main_quit()
|
||||
sys.exit()
|
||||
|
||||
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
#print("Button", "was turned", state)
|
||||
def on_start_clicked(self, widget):
|
||||
global count
|
||||
global ExitVLCThread
|
||||
global Acquire
|
||||
global Kill
|
||||
global SendCellDataThread
|
||||
global test
|
||||
global st
|
||||
global name
|
||||
global age
|
||||
global patientID
|
||||
global filename
|
||||
folder=("/home/odroid/BloodAnalyser/AcquiredData/")
|
||||
#filename=folder.append(st)
|
||||
#filename=filename.append(".txt")
|
||||
filename=folder+'PatientInformation'+".txt"
|
||||
f = open(filename,"w") #opens file with name of "test.txt"
|
||||
|
||||
|
||||
#f.write("Name:\t")
|
||||
f.write(name)
|
||||
f.write("\n")
|
||||
print(f)
|
||||
|
||||
#f.write("Age:\t")
|
||||
f.write(age)
|
||||
f.write("\n")
|
||||
|
||||
#f.write("PatientID:\t")
|
||||
f.write(patientID)
|
||||
f.write("\n")
|
||||
|
||||
#f.write("Test Selected:\t")
|
||||
f.write(test)
|
||||
f.write("\n")
|
||||
f.close()
|
||||
#os.system('7z a /home/odroid/BloodAnalyser/AcquiredData/celldata.7z /home/odroid/BloodAnalyser/AcquiredData/PatientInformation')
|
||||
#self.activity= False
|
||||
#self.ftp_invoke()
|
||||
|
||||
count=count+1
|
||||
print(count)
|
||||
if (count ==1):
|
||||
|
||||
print("Hello World!")
|
||||
dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, "Reminder! Suitable Cartridge had to be loaded before starting the test.")
|
||||
dialog.format_secondary_text("Do you want to continue?")
|
||||
response = dialog.run()
|
||||
if response == Gtk.ResponseType.YES:
|
||||
dialog.destroy()
|
||||
self.start.set_label("ABORT TEST")
|
||||
print("WARN dialog closed by clicking OK button")
|
||||
|
||||
Acquire = True
|
||||
print (Acquire)
|
||||
#Kill = True
|
||||
#print(Kill)
|
||||
#global Thread1
|
||||
#global Thread2
|
||||
|
||||
|
||||
auto_focus=AutoFocus()
|
||||
|
||||
#auto_focus.window.show()
|
||||
#blood_analyser = BloodAnalyser()
|
||||
|
||||
self.timeout_id_thread_end = GObject.timeout_add(500, self.on_timeout_thread_end, None)
|
||||
|
||||
self.Thread1=threading.Thread(target=auto_focus.pulse_invoke)
|
||||
#self.Thread1.start()
|
||||
|
||||
#self.Thread1=threading.Thread(target=self.vlc_invoke)
|
||||
self.Thread1.daemon=True
|
||||
self.Thread1.start()
|
||||
|
||||
|
||||
|
||||
elif response == Gtk.ResponseType.NO:
|
||||
dialog.destroy()
|
||||
print("WARN dialog closed by clicking CANCEL button")
|
||||
count=0
|
||||
|
||||
else:
|
||||
print(count)
|
||||
dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING,Gtk.ButtonsType.YES_NO, "Test in progress!.. Do you still want to abort test?")
|
||||
dialog.format_secondary_text("Click Yes to continue")
|
||||
response = dialog.run()
|
||||
if response == Gtk.ResponseType.YES:
|
||||
|
||||
dialog.destroy()
|
||||
self.window.hide()
|
||||
Gtk.main_quit()
|
||||
os.system('exit()')
|
||||
print("Thread2=")
|
||||
print(SendCellDataThread)
|
||||
os.system("killall vlc")
|
||||
|
||||
self.start.set_label("START TEST")
|
||||
text2 = " "
|
||||
count = 0
|
||||
self.progressbar.set_text(text2)
|
||||
|
||||
self.progressbar.set_show_text(text2)
|
||||
|
||||
self.progressbar.set_fraction(0.0)
|
||||
self.activity= False
|
||||
# self.timeout_id = GObject.timeout_add(0, self.on_timeout,None)
|
||||
|
||||
|
||||
self.start.set_label("START TEST")
|
||||
#os.system('rm ./celldata.zip')
|
||||
os.system('rm -r ./AcquiredData')
|
||||
os.system('mkdir ./AcquiredData')
|
||||
print("WARN dialog closed by clicking OK button")
|
||||
elif response == Gtk.ResponseType.NO:
|
||||
count = 0
|
||||
dialog.destroy()
|
||||
|
||||
def on_timeout(self, user_data):
|
||||
if self.activity:
|
||||
|
||||
new_value = self.progressbar.get_fraction() + 0.01
|
||||
|
||||
if new_value > 1:
|
||||
new_value = 0
|
||||
|
||||
self.progressbar.set_fraction(new_value)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def vlc_invoke(self):
|
||||
#gobject.threads_init()
|
||||
#os.system("v4l2-ctl -c exposure_absolute=1")
|
||||
print ("Vlc invoked")
|
||||
#similar to time.sleep()
|
||||
#sleep(10)
|
||||
n = 0
|
||||
global error2
|
||||
start_time=time.time()
|
||||
|
||||
while (True):
|
||||
|
||||
sleep(0.5)
|
||||
print Acquire
|
||||
if Acquire:
|
||||
#print ('while acquire')
|
||||
self.activity= 1
|
||||
|
||||
self.timeout_id = GObject.timeout_add(400, self.on_timeout,None)
|
||||
|
||||
os.chdir('/home/odroid/BloodAnalyser/AcquiredData')
|
||||
|
||||
|
||||
itime=time.time()
|
||||
i=1
|
||||
|
||||
print("Time taken to capture =")
|
||||
print(time.time()-itime)
|
||||
|
||||
|
||||
|
||||
os.chdir('/home/odroid/BloodAnalyser/AcquiredData')
|
||||
while(i<batches+1):
|
||||
text2 = "Acquiring Dataset %d"%i
|
||||
|
||||
self.progressbar.set_text(text2)
|
||||
self.progressbar.set_show_text(text2)
|
||||
|
||||
|
||||
os.mkdir('/home/odroid/BloodAnalyser/AcquiredData/%d'%i)
|
||||
os.chdir('/home/odroid/BloodAnalyser/AcquiredData/%d'%i)
|
||||
|
||||
os.system("mplayer tv:// -tv driver=v4l2:device=/dev/video0:fps=60 --frames=%d -vo jpeg"%numframes)
|
||||
if i==1:
|
||||
ip=ip1
|
||||
|
||||
elif i==batches:
|
||||
ip=ip2
|
||||
os.system('7z a /home/odroid/BloodAnalyser/AcquiredData/celldata%d.7z /home/odroid/BloodAnalyser/AcquiredData/%d'%(i,i))
|
||||
self.sizewrite(i,ip)
|
||||
os.system("echo odroid | sudo -S scp -i /home/odroid/jayesh1.pem /home/odroid/BloodAnalyser/AcquiredData/celldata%d.7z ubuntu@%s:"%(i,ip2))
|
||||
print('File Uploaded to %s'%ip)
|
||||
return
|
||||
|
||||
a=thread.start_new_thread(self.compress,(i,ip))
|
||||
i=i+1
|
||||
print 'Updating queue'
|
||||
|
||||
self.start.set_sensitive(False)
|
||||
|
||||
|
||||
|
||||
def compress(self,i,ip):
|
||||
text='Compessing and Sending Dataset %d'%i
|
||||
|
||||
self.progressbar.set_text(text)
|
||||
print ('Entered Compression=%d'%i)
|
||||
|
||||
self.progressbar.set_show_text(text)
|
||||
os.chdir('/home/odroid/BloodAnalyser/AcquiredData/')
|
||||
print(name)
|
||||
|
||||
|
||||
start_time=time.time()
|
||||
|
||||
#if i==1:
|
||||
|
||||
os.system('7z a /home/odroid/BloodAnalyser/AcquiredData/celldata%d.7z /home/odroid/BloodAnalyser/AcquiredData/%d'%(i,i))
|
||||
self.sizewrite(i,ip)
|
||||
os.system("echo odroid | sudo -S scp -i /home/odroid/jayesh1.pem /home/odroid/BloodAnalyser/AcquiredData/PatientInformation.txt /home/odroid/BloodAnalyser/AcquiredData/celldata%d.7z ubuntu@%s:"%(i,ip))
|
||||
print('File Uploaded to %s'%ip)
|
||||
|
||||
|
||||
|
||||
print("--- %s seconds ---" % (time.time() - start_time))
|
||||
|
||||
|
||||
|
||||
|
||||
def sizewrite(self,i,ip):
|
||||
print "entered write size"
|
||||
size=str(os.path.getsize('/home/odroid/BloodAnalyser/AcquiredData/celldata%d.7z'%i))
|
||||
print ("size of %d file is:%s"%(i,size))
|
||||
f=open('/home/odroid/BloodAnalyser/AcquiredData/sizefile.txt','w')
|
||||
f.write(size)
|
||||
f.close()
|
||||
os.system("echo odroid | sudo -S scp -i /home/odroid/jayesh1.pem /home/odroid/BloodAnalyser/AcquiredData/sizefile.txt ubuntu@%s:"%ip)
|
||||
return
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#patient_ID=patientID()
|
||||
blood_analyser = BloodAnalyser()
|
||||
splScr = splashScreen()
|
||||
patient_ID=patientID()
|
||||
#quitwindow=quit_window()
|
||||
|
||||
#If you don't do this, the splash screen will show, but wont render it's contents
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
GObject.timeout_add(5000, splScr.window.hide)
|
||||
|
||||
|
||||
Gtk.main()
|
||||
BIN
src/server_computation.pptx
Normal file
BIN
src/server_computation.pptx
Normal file
Binary file not shown.
175
src/server_script_master.py
Normal file
175
src/server_script_master.py
Normal file
@@ -0,0 +1,175 @@
|
||||
import sys
|
||||
import os, time
|
||||
import os.path
|
||||
global folder
|
||||
import threading
|
||||
global it
|
||||
#from gi.repository import Gtk, GObject
|
||||
global Thread1
|
||||
global process
|
||||
import numpy
|
||||
global num_batches
|
||||
if len(sys.argv) < 3:
|
||||
print "Invalid arguments"
|
||||
print "Usage : python server_script_threads.py <instance_id>"
|
||||
print "Example: python server_script_threads.py 3"
|
||||
sys.exit()
|
||||
|
||||
instance_id = int(sys.argv[1])
|
||||
num_instances = int(sys.argv[2])
|
||||
print 'Starting instance id: %d, num_batches:%d'%(instance_id, num_instances)
|
||||
|
||||
|
||||
class servercheck():
|
||||
|
||||
i=0
|
||||
path=("/home/ubuntu/")
|
||||
print(path)
|
||||
path_to_watch =os.path.join("/home/ubuntu/")
|
||||
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
|
||||
dir=os.chdir(os.path.join("/home/ubuntu/"))
|
||||
it=time.time()
|
||||
|
||||
while 1:
|
||||
print "Checking for zip file..."
|
||||
time.sleep (1)
|
||||
after = dict ([(f, None) for f in os.listdir (path_to_watch)])
|
||||
added = [f for f in after if not f in before]
|
||||
removed = [f for f in before if not f in after]
|
||||
#print(removed)
|
||||
if removed:
|
||||
print "removed: ", ", ".join (removed)
|
||||
|
||||
if added:
|
||||
|
||||
added_file=", ".join (added)
|
||||
print "added: ", ", ".join (added)
|
||||
i=i+1
|
||||
if i<4:
|
||||
file_name=("celldata.7z")
|
||||
added_file=", ".join (added)
|
||||
if added_file == file_name:
|
||||
|
||||
time.sleep(130)
|
||||
print "Removing celldata folder"
|
||||
os.system("rm -rf celldata")
|
||||
|
||||
print "Unzipping celldata.7z"
|
||||
os.system("7z x celldata.7z")
|
||||
|
||||
print "Removing zip file - celldata.7z"
|
||||
os.system("rm celldata.7z")
|
||||
|
||||
if os.path.isdir("./images"):
|
||||
os.system("cp -r celldata/* images/")
|
||||
else:
|
||||
os.mkdir("./images/")
|
||||
os.system("cp -r celldata/* images/")
|
||||
|
||||
global ProcessThreads
|
||||
ProcessThreads = []
|
||||
print os.getcwd() + '/celldata'
|
||||
numImages = len(os.listdir(os.getcwd() + '/celldata'))
|
||||
print "Number of images in the folder: %d"%numImages
|
||||
numThreads = 5
|
||||
numImagesPerThread = numImages/numThreads
|
||||
print "Starting %d threads- Total images: %d, Images per thread:%d"%(numThreads, numImages, numImagesPerThread)
|
||||
|
||||
image_num_min = 2 # Starting from image 2 as image 1 is always black!
|
||||
39,5 28%
|
||||
image_num_max = 0
|
||||
|
||||
for i in range (1, numThreads+1):
|
||||
|
||||
image_num_max = image_num_min + numImagesPerThread
|
||||
if image_num_max > 10000:
|
||||
image_num_max=10000
|
||||
t = threading.Thread(target=process,args=(i, image_num_min, image_num_max))
|
||||
t.start()
|
||||
ProcessThreads.append(t)
|
||||
print 'Started thread %d for images %d to %d'%(i, image_num_min, image_num_max)
|
||||
image_num_min = image_num_max + 1
|
||||
|
||||
for t in ProcessThreads:
|
||||
t.join()
|
||||
|
||||
totalCount = 0
|
||||
|
||||
for i in range (1, numThreads+1):
|
||||
result_file = 'count' + str(i) + '.txt'
|
||||
f = open(result_file, 'r')
|
||||
count_str = f.readline()
|
||||
count = int(count_str.split("=")[1])
|
||||
totalCount = totalCount + count
|
||||
print "Thread:%d, Count:%d, Total Count:%d"%(i, count, totalCount)
|
||||
os.system("rm -f " + result_file)
|
||||
|
||||
print totalCount
|
||||
|
||||
print totalCount
|
||||
|
||||
writefile(totalCount)
|
||||
#checkcountfiles()
|
||||
|
||||
before=after
|
||||
|
||||
def process(threadId, frame_no_min, frame_no_max):
|
||||
result_file = 'count' + str(threadId) + '.txt'
|
||||
cmd = 'sudo ./run_malariaExecutableArgs.sh /usr/local/MATLAB/MATLAB_Compiler_Runtime/v83/ %d %d %s'%(frame_no_min, frame_no_max, result_file)
|
||||
print "ThreadId: %d, cmd =%s"%(threadId, cmd)
|
||||
os.system(cmd)
|
||||
return
|
||||
|
||||
|
||||
def writefile(count):
|
||||
#testsite_array = []
|
||||
#with open('PatientInformation.txt','r') as my_file:
|
||||
# testsite_array = my_file.readlines()
|
||||
#count=numpy.sum(testsite_array)
|
||||
file_name = 'Instance' + str(instance_id) + '.txt'
|
||||
f = open(file_name,'w')
|
||||
f.write('%d'%count)
|
||||
f.flush()
|
||||
f.close()
|
||||
cmd = 'sudo scp -i "jayesh1.pem" ' + file_name + ' ubuntu@ec2-54-200-214-228.us-west-2.compute.amazonaws.com:'
|
||||
print cmd
|
||||
os.system(cmd)
|
||||
def checkcountfiles():
|
||||
path = '/home/ubuntu/'
|
||||
files = []
|
||||
countFiles=1
|
||||
iteration=0
|
||||
totalCount=0
|
||||
cellcount=0
|
||||
textf1='Instance'+str(countFiles)+'.txt'
|
||||
textf2='Instance'+str(countFiles+1)+'.txt'
|
||||
textf3='Instance'+str(countFiles+2)+'.txt'
|
||||
while True:
|
||||
print "Checking for count files from Instances"
|
||||
time.sleep(1)
|
||||
if os.path.isfile(textf1) and os.path.isfile(textf2) and os.path.isfile(textf3):
|
||||
|
||||
#print i
|
||||
iteration=iteration+1
|
||||
print countFiles
|
||||
textf='Instance'+str(iteration)+'.txt'
|
||||
|
||||
f = open(textf,'r')
|
||||
count_str = f.readline()
|
||||
cellcount = int(count_str)
|
||||
print 'The count of instance %d =%d'%(iteration,cellcount)
|
||||
totalCount = totalCount + cellcount
|
||||
|
||||
if iteration == num_instances:
|
||||
print 'condition met'
|
||||
print 'total count =%d'%totalCount
|
||||
file_name="totalCount.txt"
|
||||
f = open(file_name,'w')
|
||||
f.write('%d'%totalCount)
|
||||
f.flush()
|
||||
f.close()
|
||||
return
|
||||
else:
|
||||
print "Count files have not arrived"
|
||||
85%
|
||||
|
||||
Reference in New Issue
Block a user