-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_pipette_new.py
323 lines (303 loc) · 19.6 KB
/
new_pipette_new.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 7 16:44:03 2021
@author: User
"""
from XYZ_Stage.XYZ_Position import XYZ_Location
from Delta_XY_FOV_1_lin import Delta_XY_FOV_1_lin
from Delta_XY_FOV_2_lin import Delta_XY_FOV_2_lin
import cv2
from ML.ml_injection_point_estimation_new import ml_injection_point_estimation_new
import time
# from point_and_click import point_and_click
from stream_image import stream_image
from move_embryo_fov_new_new_thresh_pressure import move_embryo_fov_new_new_thresh_pressure
import numpy as np
from Pressure_Control.Continuous_Pressure import continuous_pressure
def new_pipette_new(time_wait,view_1_x,view_1_y,view_2_x,view_2_y,X_pos,Y_pos,Z_pos,dx_final,dy_final,footage_socket_1,footage_socket_2,footage_socket_3,inj_num,graph,sess,ser,pip_num,Z_inj,inj_depth,inj_speed,back_pressure_value,pressure_value,pressure_time,arduino,post_z,Z_initial,current_z_centroid,pic,sum_image_thresh_min,target_pixel):
new_pipette_start_time=time.time()
X_est=X_pos
Y_est=Y_pos
Z_est=Z_pos
X_est_old=X_pos
Y_est_old=Y_pos
Z_est_old=Z_pos
next_z=Z_est
current_z_new=0
move_num=0
x_coord_emb_1=0
y_coord_emb_1=0
x_coord_emb_2=0
y_coord_emb_2=0
thresh_1=.01
thresh_2=.01
print('Current X = ',X_est)
print('Current Y = ',Y_est)
print('Current Z = ',Z_est)
end=0
print('New Pipette')
print('TURN VALVES!')
# XYZ_Location(20000,20000,8000,X_est,Y_est,5000,ser)
XYZ_Location(20000,20000,8000,59430,58000,5000,ser)
time.sleep(10)
print('Focus first time')
pressure_value=30
# pressure_value=25
correct=0
o=0
while correct==0:
print('Try ',o+1)
signal=continuous_pressure(0,pressure_value,'inj')
arduino.write(signal.encode())
arduino.flush()
q_=arduino.readline()
q_=q_.decode()
s=q_.find('Received')
if q_[s+9]=='P' and q_[s+10:s+12]==str(int((pressure_value + 43.6279)/0.9535)) and q_[s+12]=='p' and q_[s+13]=='\r':
correct=1
else:
o+=1
# signal=continuous_pressure(0,30,'inj')
# # signal=continuous_pressure(0,40,'inj')
# arduino.write(signal.encode())
# time.sleep(5)
# in_focus=int(input('Is image in focus and pipette open? '))
# if in_focus==1:
# correct=0
# o=0
# while correct==0:
# print('Try ',o+1)
# signal=continuous_pressure(0,pressure_value,'inj')
# arduino.write("P0p".encode())
# arduino.flush()
# q_=arduino.readline()
# q_=q_.decode()
# s=q_.find('Received')
# if q_[s+9]=='P' and q_[s+10]=='0' and q_[s+11]=='p' and q_[s+12]=='\r':
# correct=1
# else:
# o+=1
# # time.sleep(1)
# # arduino.write("P0p".encode())
# print('In focus and open')
# else:
# print('Not in focus')
print('OPEN PIPETTE')
time.sleep(20)
correct=0
o=0
while correct==0:
print('Try ',o+1)
signal=continuous_pressure(0,pressure_value,'inj')
arduino.write("P0p".encode())
arduino.flush()
q_=arduino.readline()
q_=q_.decode()
s=q_.find('Received')
if q_[s+9]=='P' and q_[s+10]=='0' and q_[s+11]=='p' and q_[s+12]=='\r':
correct=1
else:
o+=1
view_1_x_old=view_1_x
view_2_x_old=view_2_x
im_height_1=720
im_width_1=1280
im_height_2=720
im_width_2=1280
# tip_x_1=[]
# tip_y_1=[]
# tip_x_2=[]
# tip_y_2=[]
# for tip_d in range(5):
# img1,img2=stream_image(footage_socket_1,footage_socket_2,pic,0)
# output_dict_detection_boxes_stored_pipette_1,output_dict_detection_classes_stored_pipette_1,output_dict_detection_scores_stored_pipette_1,y1a_rc_pipette_1,y2a_rc_pipette_1,x1a_rc_pipette_1,x2a_pipette_1,xc_rc_pipette_1,yc_rc_pipette_1=ml_injection_point_estimation_new([img1],.01,im_height_1,im_width_1,graph,sess,1)
# list_classes_pipette_1=output_dict_detection_classes_stored_pipette_1[0].tolist()
# if 5 not in list_classes_pipette_1:
# list_classes_index_pipette_1=list_classes_pipette_1.index(6)
# else:
# list_classes_index_pipette_1=list_classes_pipette_1.index(5)
# view_1_x=int(xc_rc_pipette_1[0][list_classes_index_pipette_1])
# view_1_y=int(y2a_rc_pipette_1[0][list_classes_index_pipette_1])
# tip_x_1.append(view_1_x)
# tip_y_1.append(view_1_y)
# output_dict_detection_boxes_stored_pipette_2,output_dict_detection_classes_stored_pipette_2,output_dict_detection_scores_stored_pipette_2,y1a_rc_pipette_2,y2a_rc_pipette_2,x1a_rc_pipette_2,x2a_rc_pipette_2,xc_rc_pipette_2,yc_rc_pipette_2=ml_injection_point_estimation_new([img2],.01,im_height_2,im_width_2,graph,sess,1)
# list_classes_pipette_2=output_dict_detection_classes_stored_pipette_2[0].tolist()
# if 5 not in list_classes_pipette_2:
# list_classes_index_pipette_2=list_classes_pipette_2.index(6)
# else:
# list_classes_index_pipette_2=list_classes_pipette_2.index(5)
# view_2_x=int(xc_rc_pipette_2[0][list_classes_index_pipette_2])
# view_2_y=int(y2a_rc_pipette_2[0][list_classes_index_pipette_2])
# tip_x_2.append(view_2_x)
# tip_y_2.append(view_2_y)
# view_1_x=int(np.mean(tip_x_1))
# view_1_y=int(np.mean(tip_y_1))
# view_2_x=int(np.mean(tip_x_2))
# view_2_y=int(np.mean(tip_y_2))
img1,img2=stream_image(footage_socket_1,footage_socket_2,footage_socket_3,pic,0)
lower_blue = np.array([52,30,35])
upper_blue = np.array([255,255,255])
output_dict_detection_boxes_stored_pipette_1,output_dict_detection_classes_stored_pipette_1,output_dict_detection_scores_stored_pipette_1,y1a_rc_pipette_1,y2a_rc_pipette_1,x1a_rc_pipette_1,x2a_rc_pipette_1,xc_rc_pipette_1,yc_rc_pipette_1=ml_injection_point_estimation_new([img1],.01,720,1280,graph,sess,1)
output_dict_detection_boxes_stored_pipette_2,output_dict_detection_classes_stored_pipette_2,output_dict_detection_scores_stored_pipette_2,y1a_rc_pipette_2,y2a_rc_pipette_2,x1a_rc_pipette_2,x2a_rc_pipette_2,xc_rc_pipette_2,yc_rc_pipette_2=ml_injection_point_estimation_new([img2],.01,720,1280,graph,sess,1)
list_classes_pipette_1=output_dict_detection_classes_stored_pipette_1[0].tolist()
if 5 in list_classes_pipette_1:
list_classes_index_pipette_1=list_classes_pipette_1.index(5)
crop_1=img1[y1a_rc_pipette_1[0][list_classes_index_pipette_1]:y2a_rc_pipette_1[0][list_classes_index_pipette_1],x1a_rc_pipette_1[0][list_classes_index_pipette_1]:x2a_rc_pipette_1[0][list_classes_index_pipette_1]]
hsv_1 = cv2.cvtColor(crop_1, cv2.COLOR_BGR2HSV)
mask_1 = cv2.inRange(hsv_1, lower_blue, upper_blue)
mask_1_list=mask_1.tolist()
x_list=[]
y_list=[]
for j in range(len(mask_1)):
indices = [i for i, x in enumerate(mask_1_list[j]) if x==255]
if indices!=[]:
x_list.append(np.median(indices))
y_list.append(j)
if x_list==[] or y_list==[] or x1a_rc_pipette_1==[] or y1a_rc_pipette_1==[]:
view_1_x=int(xc_rc_pipette_1[0][list_classes_index_pipette_1])
view_1_y=int(yc_rc_pipette_1[0][list_classes_index_pipette_1])
print('CV tip x = ',view_1_x)
print('CV tip y = ',view_1_y)
else:
view_1_x=int(x_list[len(x_list)-1]+x1a_rc_pipette_1[0][list_classes_index_pipette_1])
view_1_y=int(y_list[len(y_list)-1]+y1a_rc_pipette_1[0][list_classes_index_pipette_1])
print('CV tip x = ',int(x_list[len(x_list)-1]+x1a_rc_pipette_1[0][list_classes_index_pipette_1]))
print('CV tip y = ',int(y_list[len(y_list)-1]+y1a_rc_pipette_1[0][list_classes_index_pipette_1]))
list_classes_pipette_2=output_dict_detection_classes_stored_pipette_2[0].tolist()
if 5 in list_classes_pipette_2:
list_classes_index_pipette_2=list_classes_pipette_2.index(5)
crop_2=img2[y1a_rc_pipette_2[0][list_classes_index_pipette_2]:y2a_rc_pipette_2[0][list_classes_index_pipette_2],x1a_rc_pipette_2[0][list_classes_index_pipette_2]:x2a_rc_pipette_2[0][list_classes_index_pipette_2]]
hsv_2 = cv2.cvtColor(crop_2, cv2.COLOR_BGR2HSV)
mask_2 = cv2.inRange(hsv_2, lower_blue, upper_blue)
mask_2_list=mask_2.tolist()
x_list=[]
y_list=[]
for j in range(len(mask_2)):
indices = [i for i, x in enumerate(mask_2_list[j]) if x==255]
if indices!=[]:
x_list.append(np.median(indices))
y_list.append(j)
if x_list==[] or y_list==[] or x1a_rc_pipette_2==[] or y1a_rc_pipette_2==[]:
view_2_x=int(xc_rc_pipette_2[0][list_classes_index_pipette_2])
view_2_y=int(yc_rc_pipette_2[0][list_classes_index_pipette_2])
print('CV tip x = ',view_2_x)
print('CV tip y = ',view_2_y)
else:
view_2_x=int(x_list[len(x_list)-1]+x1a_rc_pipette_2[0][list_classes_index_pipette_2])
view_2_y=int(y_list[len(y_list)-1]+y1a_rc_pipette_2[0][list_classes_index_pipette_2])
print('CV tip x = ',int(x_list[len(x_list)-1]+x1a_rc_pipette_2[0][list_classes_index_pipette_2]))
print('CV tip y = ',int(y_list[len(y_list)-1]+y1a_rc_pipette_2[0][list_classes_index_pipette_2]))
x1_1_crop=int(view_1_x-250)
x2_1_crop=int(view_1_x+250)
y1_1_crop=int(view_1_y-25)
y2_1_crop=int(view_1_y+300)
x1_2_crop=int(view_2_x-250)
x2_2_crop=int(view_2_x+250)
y1_2_crop=int(view_2_y-25)
y2_2_crop=int(view_2_y+300)
if x1_1_crop<0:
x1_1_crop=0
if y1_1_crop<0:
y1_1_crop=0
if x2_1_crop>1280:
x2_1_crop=1280
if y2_1_crop>720:
y2_1_crop=720
if x1_2_crop<0:
x1_2_crop=0
if y1_2_crop<0:
y1_2_crop=0
if x2_2_crop>1280:
x2_2_crop=1280
if y2_2_crop>720:
y2_2_crop=720
im_width_1=x2_1_crop-x1_1_crop
im_height_1=y2_1_crop-y1_1_crop
im_width_2=x2_2_crop-x1_2_crop
im_height_2=y2_2_crop-y1_2_crop
s_end=0
s=0
dx_p_1,dy_p_1=Delta_XY_FOV_1_lin(view_1_x,view_1_x_old)
dx_p_2,dy_p_2=Delta_XY_FOV_2_lin(view_2_x,view_2_x_old)
X_est=X_est+dx_p_1+dx_p_2
Y_est=Y_est+dy_p_1+dy_p_2
XYZ_Location(5000,5000,2000,X_est,Y_est,Z_est,ser)
time.sleep(10)
# view_1_x_list=[]
# view_1_y_list=[]
# view_2_x_list=[]
# view_2_y_list=[]
while s_end==0 and Z_est<Z_initial+500:
Z_est=Z_est_old+100*s
XYZ_Location(5000,5000,2000,X_est,Y_est,Z_est,ser)
time.sleep(.5)
img1,img2=stream_image(footage_socket_1,footage_socket_2,footage_socket_3,pic,0)
img1_crop=img1[y1_1_crop:y2_1_crop,x1_1_crop:x2_1_crop]
img2_crop=img2[y1_2_crop:y2_2_crop,x1_2_crop:x2_2_crop]
output_dict_detection_boxes_stored_1,output_dict_detection_classes_stored_1,output_dict_detection_scores_stored_1,y1a_rc_1,y2a_rc_1,x1a_rc_1,x2a_rc_1,xc_rc_1,yc_rc_1=ml_injection_point_estimation_new([img1_crop],.1,im_height_1,im_width_1,graph,sess,1)
list_classes_1_c=output_dict_detection_classes_stored_1[0].tolist()
# list_classes_1_t=output_dict_detection_classes_stored_1[0].tolist()
output_dict_detection_boxes_stored_2,output_dict_detection_classes_stored_2,output_dict_detection_scores_stored_2,y1a_rc_2,y2a_rc_2,x1a_rc_2,x2a_rc_2,xc_rc_2,yc_rc_2=ml_injection_point_estimation_new([img2_crop],.1,im_height_2,im_width_2,graph,sess,1)
list_classes_2_c=output_dict_detection_classes_stored_2[0].tolist()
# list_classes_2_t=output_dict_detection_classes_stored_2[0].tolist()
# if 5 not in list_classes_1_t:
# print('ok')
# else:
# list_classes_index_1_t=list_classes_1_t.index(5)
# view_1_x_list.append(int(xc_rc_1[list_classes_index_1_t]))
# view_1_y_list.append(int(yc_rc_1[list_classes_index_1_t]))
# if 5 not in list_classes_2_t:
# print('ok')
# else:
# list_classes_index_2_t=list_classes_2_t.index(5)
# view_2_x_list.append(int(xc_rc_2[list_classes_index_2_t]))
# view_2_y_list.append(int(yc_rc_2[list_classes_index_2_t]))
if 1 not in list_classes_1_c or 1 not in list_classes_2_c:
print('Centroid not detected in both FOVs')
s+=1
else:
Z_est=Z_est+100
print('Embryo in FOV')
print('Initial Z estimate = ',Z_est)
Z_new=Z_est
XYZ_Location(5000,5000,2000,X_est,Y_est,Z_new,ser)
time.sleep(.5)
s_end=1
current_x=X_est
current_y=Y_est
current_z=Z_est
while end!=3:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_cen_1,y_coord_emb_cen_1,x_coord_tip_cen_1,y_coord_tip_cen_1,x_coord_emb_cen_2,y_coord_emb_cen_2,x_coord_tip_cen_2,y_coord_tip_cen_2,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_width_1,im_height_1,im_width_2,im_height_2,current_z_new,move_num,injected,end_1,end_2,injected,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(1,'centroid',X_est,Y_est,Z_est,inj_depth,inj_speed,back_pressure_value,pressure_value,pressure_time,arduino,current_x,current_y,current_z,view_1_x,view_1_y,view_2_x,view_2_y,footage_socket_1,footage_socket_2,footage_socket_3,inj_num,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_height_1,im_width_1,im_height_2,im_width_2,graph,sess,ser,time_wait,next_z,post_z,current_z_new,move_num,pic,thresh_1,thresh_2,0,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0)
if end==2:
time_wait=.15
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_cen_1,y_coord_emb_cen_1,x_coord_tip_cen_1,y_coord_tip_cen_1,x_coord_emb_cen_2,y_coord_emb_cen_2,x_coord_tip_cen_2,y_coord_tip_cen_2,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_width_1,im_height_1,im_width_2,im_height_2,current_z_new,move_num,injected,end_1,end_2,injected,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(2,'centroid',X_est,Y_est,Z_est,inj_depth,inj_speed,back_pressure_value,pressure_value,pressure_time,arduino,current_x,current_y,current_z,view_1_x,view_1_y,view_2_x,view_2_y,footage_socket_1,footage_socket_2,footage_socket_3,inj_num,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_height_1,im_width_1,im_height_2,im_width_2,graph,sess,ser,time_wait,next_z,post_z,current_z_new,move_num,pic,thresh_1,thresh_2,0,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0)
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_cen_1,y_coord_emb_cen_1,x_coord_tip_cen_1,y_coord_tip_cen_1,x_coord_emb_cen_2,y_coord_emb_cen_2,x_coord_tip_cen_2,y_coord_tip_cen_2,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_width_1,im_height_1,im_width_2,im_height_2,current_z_new,move_num,injected,end_1,end_2,injected,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(1,'centroid',X_est,Y_est,Z_est,inj_depth,inj_speed,back_pressure_value,pressure_value,pressure_time,arduino,current_x,current_y,current_z,view_1_x,view_1_y,view_2_x,view_2_y,footage_socket_1,footage_socket_2,footage_socket_3,inj_num,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_height_1,im_width_1,im_height_2,im_width_2,graph,sess,ser,time_wait,next_z,post_z,current_z_new,move_num,pic,thresh_1,thresh_2,0,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0)
if end==2:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_cen_1,y_coord_emb_cen_1,x_coord_tip_cen_1,y_coord_tip_cen_1,x_coord_emb_cen_2,y_coord_emb_cen_2,x_coord_tip_cen_2,y_coord_tip_cen_2,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_width_1,im_height_1,im_width_2,im_height_2,current_z_new,move_num,injected,end_1,end_2,injected,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(1,'centroid',X_est,Y_est,Z_est,inj_depth,inj_speed,back_pressure_value,pressure_value,pressure_time,arduino,current_x,current_y,current_z,view_1_x,view_1_y,view_2_x,view_2_y,footage_socket_1,footage_socket_2,footage_socket_3,inj_num,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_height_1,im_width_1,im_height_2,im_width_2,graph,sess,ser,time_wait,next_z,post_z,current_z_new,move_num,pic,thresh_1,thresh_2,0,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0)
current_x_centroid=current_x
current_y_centroid=current_y
current_z_needle=current_z
end=3
else:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_cen_1,y_coord_emb_cen_1,x_coord_tip_cen_1,y_coord_tip_cen_1,x_coord_emb_cen_2,y_coord_emb_cen_2,x_coord_tip_cen_2,y_coord_tip_cen_2,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_width_1,im_height_1,im_width_2,im_height_2,current_z_new,move_num,injected,end_1,end_2,injected,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(2,'centroid',X_est,Y_est,Z_est,inj_depth,inj_speed,back_pressure_value,pressure_value,pressure_time,arduino,current_x,current_y,current_z,view_1_x,view_1_y,view_2_x,view_2_y,footage_socket_1,footage_socket_2,footage_socket_3,inj_num,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_height_1,im_width_1,im_height_2,im_width_2,graph,sess,ser,time_wait,next_z,post_z,current_z_new,move_num,pic,thresh_1,thresh_2,0,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0)
if end==1:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_cen_1,y_coord_emb_cen_1,x_coord_tip_cen_1,y_coord_tip_cen_1,x_coord_emb_cen_2,y_coord_emb_cen_2,x_coord_tip_cen_2,y_coord_tip_cen_2,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_width_1,im_height_1,im_width_2,im_height_2,current_z_new,move_num,injected,end_1,end_2,injected,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(2,'centroid',X_est,Y_est,Z_est,inj_depth,inj_speed,back_pressure_value,pressure_value,pressure_time,arduino,current_x,current_y,current_z,view_1_x,view_1_y,view_2_x,view_2_y,footage_socket_1,footage_socket_2,footage_socket_3,inj_num,y1_1_crop,y2_1_crop,x1_1_crop,x2_1_crop,y1_2_crop,y2_2_crop,x1_2_crop,x2_2_crop,im_height_1,im_width_1,im_height_2,im_width_2,graph,sess,ser,time_wait,next_z,post_z,current_z_new,move_num,pic,thresh_1,thresh_2,0,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0)
current_x_centroid=current_x
current_y_centroid=current_y
current_z_needle=current_z
end=3
#subtract dx dy
dx_move=(current_x_centroid-X_est_old)
dy_move=(current_y_centroid-Y_est_old)
dx_final=dx_final+dx_move
dy_final=dy_final+dy_move
dz_final=current_z_centroid-current_z
# dx_final=dx_move
# dy_final=dy_move
Z_new=next_z
current_z=Z_est
injected_embryos_count=0
# XYZ_Location(20000,20000,2000,current_x,current_y,current_z,ser)
new_pipette_end_time=time.time()
print('New pipette time (s) = ',new_pipette_end_time-new_pipette_start_time)
return dx_final,dy_final,current_x,current_y,current_z,footage_socket_1,footage_socket_2,Z_new,view_1_x,view_1_y,view_2_x,view_2_y,injected_embryos_count,dz_final,current_z_needle