/
injection_ml_tip_short_new_thresh.py
246 lines (228 loc) · 23.6 KB
/
injection_ml_tip_short_new_thresh.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
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 9 10:05:10 2022
@author: User
"""
from XYZ_Stage.XYZ_Position import XYZ_Location
from move_embryo_fov_new_new_thresh_pressure import move_embryo_fov_new_new_thresh_pressure
import time
# from stream_image import stream_image
from queue_image import queue_image
import cv2
from ML.ml_injection_point_estimation_new import ml_injection_point_estimation_new
import numpy as np
def injection_ml_tip_short_new_thresh(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,arduino,back_pressure_value,pressure_value,pressure_time,dz,inj_speed,inj_depth,inj_num_init,ser,pipette,post_z,pic,sum_image_thresh_min,target_pixel,miss,q,inj_pressure,pressure_value_current):
injection_start_time=time.time()
injection_list_num=0
X_est=X_pos
Y_est=Y_pos
Z_est=Z_pos
current_x=X_est
current_y=Y_est
current_z=Z_est
current_x_centroid=X_est
current_y_centroid=Y_est
current_z_centroid=Z_est
current_z_new=0
x_coord_emb_1=0
y_coord_emb_1=0
x_coord_emb_2=0
y_coord_emb_2=0
next_z=Z_est
move_num=2
thresh_1=.01
thresh_2=.01
print('Current X = ',X_est)
print('Current Y = ',Y_est)
print('Current Z = ',Z_est)
end=0
injection_time=0
#original
x1_1_crop=int(view_1_x-400)
x2_1_crop=int(view_1_x+400)
y1_1_crop=int(view_1_y-100)
y2_1_crop=int(view_1_y+300)
x1_2_crop=int(view_2_x-400)
x2_2_crop=int(view_2_x+400)
y1_2_crop=int(view_2_y-100)
y2_2_crop=int(view_2_y+300)
# prototype
# x1_1_crop=int(view_1_x-600)
# x2_1_crop=int(view_1_x+600)
# y1_1_crop=int(view_1_y-300)
# y2_1_crop=int(view_1_y+300)
# x1_2_crop=int(view_2_x-600)
# x2_2_crop=int(view_2_x+600)
# y1_2_crop=int(view_2_y-300)
# 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
XYZ_Location(20000,20000,8000,X_est,Y_est,Z_est,ser)
time.sleep(1)
while end!=3:
move_num=2
diff=0
# if miss==1 or miss==0:
if miss==1:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'no move 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,1,q,inj_pressure,pressure_value_current)
current_x_centroid=current_x
current_y_centroid=current_y
current_z_centroid=current_z
if end_1!=1 and end_2!=1:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'just move',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,q,inj_pressure,pressure_value_current)
else:
end==3
while diff==0 and move_num<7:
if move_num==2:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'no move',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,1,q,inj_pressure,pressure_value_current)
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'just move',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,q,inj_pressure,pressure_value_current)
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'no move',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,q,inj_pressure,pressure_value_current)
if end_1==1:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'no move',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,1,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'just move',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,1,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'no move',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,1,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
if end_1==1:
end=3
if end_2==1:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'no move',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,2,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'just move',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,2,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_1,y_coord_emb_1,x_coord_tip_1,y_coord_tip_1,x_coord_emb_2,y_coord_emb_2,x_coord_tip_2,y_coord_tip_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'no move',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,2,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
if end_2==1:
end=3
print('FOV 1 diff = ',abs(x_coord_emb_1-x_coord_tip_1))
print('FOV 2 diff = ',abs(x_coord_emb_2-x_coord_tip_2))
# if abs(x_coord_emb_1-x_coord_tip_1)<=5*move_num and abs(x_coord_emb_2-x_coord_tip_2)<=5*move_num:
if abs(x_coord_emb_1-x_coord_tip_1)<=17 and abs(x_coord_emb_2-x_coord_tip_2)<=17:
diff=1
else:
diff=0
move_num+=1
print('Move = ',move_num)
if diff==0:
end=3
else:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_inj_1,y_coord_emb_inj_1,x_coord_tip_inj_1,y_coord_tip_inj_1,x_coord_emb_inj_2,y_coord_emb_inj_2,x_coord_tip_inj_2,y_coord_tip_inj_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'inject new',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,q,inj_pressure,pressure_value_current)
if end_1==1:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_inj_1,y_coord_emb_inj_1,x_coord_tip_inj_1,y_coord_tip_inj_1,x_coord_emb_inj_2,y_coord_emb_inj_2,x_coord_tip_inj_2,y_coord_tip_inj_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'inject new',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,1,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
if end_1==1:
end=3
if end_2==1:
end,current_x,current_y,current_z,next_z,injection_list_num,x_coord_emb_inj_1,y_coord_emb_inj_1,x_coord_tip_inj_1,y_coord_tip_inj_1,x_coord_emb_inj_2,y_coord_emb_inj_2,x_coord_tip_inj_2,y_coord_tip_inj_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,sum_image,pressure_value=move_embryo_fov_new_new_thresh_pressure(0,'inject new',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,2,sum_image_thresh_min,target_pixel,x_coord_emb_1,y_coord_emb_1,x_coord_emb_2,y_coord_emb_2,0,q,inj_pressure,pressure_value_current)
if end_2==1:
end=3
injection_end_time=time.time()
print('Injection time (s) = ',injection_end_time-injection_start_time-2.5)
if pic%5!=0 and sum_image_thresh_min<sum_image:
injection_time=injection_end_time-injection_start_time-2.5
#subtract dx dy
dx_move=(current_x_centroid-X_est)
dy_move=(current_y_centroid-Y_est)
dx_final=dx_final+dx_move
dy_final=dy_final+dy_move
Z_inj_actual=current_z+300
if injection_list_num==1 or injection_list_num==2:
# Z_new=next_z
Z_new=Z_inj_actual-285
# Z_new=Z_inj_actual-300
else:
Z_new=Z_est
# if sum_image_thresh_min>sum_image:
if abs(x_coord_emb_1-x_coord_tip_1)>17 or abs(x_coord_emb_2-x_coord_tip_2)>17 or sum_image_thresh_min>sum_image:
miss=1
current_z=Z_est-1000
XYZ_Location(20000,20000,8000,current_x,current_y,current_z,ser)
time.sleep(3)
# Detect tip
tip_x_1=[]
tip_y_1=[]
tip_x_2=[]
tip_y_2=[]
lower_blue = np.array([52,30,35])
upper_blue = np.array([255,255,255])
# img1,img2=stream_image(footage_socket_1,footage_socket_2,footage_socket_3,pic,0)
img1,img2=queue_image(q)
# cv2.imwrite('C:/Users/User/Downloads/Andrew_files/Amey Code-20190710T183750Z-001/Amey Code/Test_pipette/FOV_1_{}.jpg'.format(inj_num),img1)
# cv2.imwrite('C:/Users/User/Downloads/Andrew_files/Amey Code-20190710T183750Z-001/Amey Code/Test_pipette/FOV_2_{}.jpg'.format(inj_num),img2)
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==[]:
tip_x_1.append(view_1_x)
tip_y_1.append(view_1_y)
print('CV tip x = ',view_1_x)
print('CV tip y = ',view_1_y)
else:
tip_x_1.append(int(x_list[len(x_list)-1]+x1a_rc_pipette_1[0][list_classes_index_pipette_1]))
tip_y_1.append(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==[]:
tip_x_2.append(view_2_x)
tip_y_2.append(view_2_y)
print('CV tip x = ',view_2_x)
print('CV tip y = ',view_2_y)
else:
tip_x_2.append(int(x_list[len(x_list)-1]+x1a_rc_pipette_2[0][list_classes_index_pipette_2]))
tip_y_2.append(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]))
if tip_x_1==[]:
tip_x_1=[view_1_x]
if tip_y_1==[]:
tip_y_1=[view_1_y]
if tip_x_2==[]:
tip_x_2=[view_2_x]
if tip_y_2==[]:
tip_y_2=[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))
else:
miss=0
return dx_final,dy_final,current_x,current_y,current_z,footage_socket_1,footage_socket_2,injection_list_num,Z_new,dz,view_1_x,view_1_y,view_2_x,view_2_y,Z_inj_actual,pipette,current_x_centroid,current_y_centroid,current_z_centroid,injected,sum_image,pressure_value,injection_time,miss,inj_pressure