/
GUI_start.py
1716 lines (1598 loc) · 81 KB
/
GUI_start.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 13 20:05:36 2020
@author: Amey Joshi
"""
import tkinter as tk
from tkinter import messagebox as tkMessageBox
from PIL import ImageTk, Image
import threading
from queue import Queue
import serial
import time
import datetime
import numpy as np
import math
import pyautogui
from XYZ_stage.MyXYZ import MyXYZ
from DSLR_Camera.DSLR_Call import func_TakeNikonPicture
from MachineLearning_Zebrafish.detection_ML_forGUI import detections_dslr_image
from CameraWorkbench_master.camera import *
import os
from os import path
# from LED.LED_onoff import LED
from LED.LEDs_Both_onoff import LED
from Sensapex_Manipulator.MyUMP import MyUMP
from Transformation_matrix.transformation_DSLR_4x import transformation_DSLR_4x
from Transformation_matrix.transformation_DSLR_4x import transformation_DSLR_inj
from Transformation_matrix.transformation_inj_pip import transformation_inj_pip
from Transformation_matrix.transformation_inj_pip import transformation_pip_z
from Transformation_matrix.transformation_vial import transformation_vial
from Autofocus.autofocus import autofocus
from Needle_detection.needle_detection import needle_detection
from Needle_detection.needle_detection_live_1 import needle_detection_live_1
from Needle_detection.needle_detection_live_2 import needle_detection_live_2
from Pressure_system.MyPressureSystem import MyPressureSystem
from Path_planning.My_path_planning import My_path_planning
from ML_Yolo.yolo_object_detection_microscope_1 import YOLO_ML_1
from ML_Yolo.yolo_object_detection_microscope_2 import YOLO_ML_2
from ML_Yolo.yolo_object_detection_pipe_1 import YOLO_pipe_1
from ML_Yolo.yolo_object_detection_pipe_2 import YOLO_pipe_2
from ML_Yolo.yolo_object_detection_inj_success_1 import YOLO_inj_success_1
from ML_Yolo.yolo_object_detection_inj_success_2 import YOLO_inj_success_2
from ML_Yolo.yolo_object_detection_DSLR_divide import detections_dslr_divide_yolo
ML_flag = 0
app = tk.Tk()
app.geometry("1920x1080+0+0")
os.chdir('D:/Microinjection_Project/Python_Code/')
def DSLR_image(input_filename, Dish_number):
print('Start taking DSLR image')
start_time = time.time()
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), 0)
if Dish_number == 1:
values[0].delete(0, tk.END)
values[0].insert(10, default_DSLR_1[0])
values[1].delete(0, tk.END)
values[1].insert(10, default_DSLR_1[1])
values[2].delete(0, tk.END)
values[2].insert(10, default_DSLR_1[2])
if Dish_number == 2:
values[0].delete(0, tk.END)
values[0].insert(10, default_DSLR_2[0])
values[1].delete(0, tk.END)
values[1].insert(10, default_DSLR_2[1])
values[2].delete(0, tk.END)
values[2].insert(10, default_DSLR_2[2])
XYZ.Position(float((values[0]).get()), float((values[1]).get()), 0)
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
func_TakeNikonPicture(input_filename, 'D:/Microinjection_Project/Python_Code/')
# time.sleep(2)
image = cv2.imread(input_filename)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (640, 427))
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel = tk.Label(image=image)
panel.image = image
if Dish_number == 1:
panel.place(x=475, y=25)
x_place = 475
y_place = 25
if Dish_number == 2:
panel.place(x=1250, y=25)
x_place = 1250
y_place = 25
panel = tk.Label(app, text='DSLR {} time = {} sec'.format(Dish_number, round(time.time() - start_time, 2)))
panel.place(x=x_place+50, y=y_place+450)
print('Time = ', time.time() - start_time, 'sec')
print('DSLR image taken')
def ML_detect_faster_RCNN(input_filename, path, dish_number):
if dish_number == 1:
x_place = 475
y_place = 25
if dish_number == 2:
x_place = 1250
y_place = 25
detections_dslr_image(input_filename, path, float((values[6]).get()))
image = cv2.imread('DSLR_image_detection.jpg')
cv2.imwrite('DSLR_image_detection_{}.jpg'.format(dish_number), image)
cv2.imwrite('DSLR_image_with_clicked_Box_{}.jpg'.format(dish_number), image)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (640, 427))
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel = tk.Label(image=image)
panel.image = image
panel.place(x=x_place, y=y_place)
output_dict_detection_classes_stored = np.load('output_dict_detection_classes_stored.npy', allow_pickle=True)
num_1 = 0
num_2 = 0
num_3 = 0
for i in range(len(output_dict_detection_classes_stored)):
num_1 = np.count_nonzero(output_dict_detection_classes_stored[i] == 1) + num_1
num_2 = np.count_nonzero(output_dict_detection_classes_stored[i] == 2) + num_2
num_3 = np.count_nonzero(output_dict_detection_classes_stored[i] == 3) + num_3
panel = tk.Label(app, text='Alive Embryo Detected = {}'.format(num_1))
panel.place(x=x_place+50, y=y_place+430)
panel = tk.Label(app, text='Dead Embryo Detected = {}'.format(num_2))
panel.place(x=x_place+250, y=y_place+430)
panel = tk.Label(app, text='Bubbles Detected = {}'.format(num_3))
panel.place(x=x_place+450, y=y_place+430)
def ML_detect_YOLO(input_filename, path, dish_number):
print('Yolo detection start')
start_time = time.time()
if dish_number == 1:
x_place = 475
y_place = 25
if dish_number == 2:
x_place = 1250
y_place = 25
detections_dslr_divide_yolo(input_filename, path, float((values[6]).get()))
image = cv2.imread('DSLR_image_detection.jpg')
cv2.imwrite('DSLR_image_detection_{}.jpg'.format(dish_number), image)
cv2.imwrite('DSLR_image_with_clicked_Box_{}.jpg'.format(dish_number), image)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (640, 427))
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel = tk.Label(image=image)
panel.image = image
panel.place(x=x_place, y=y_place)
class_ids = np.load('class_ids.npy', allow_pickle=True)
Alive_num = np.count_nonzero(class_ids == 0)
Dead_num = np.count_nonzero(class_ids == 1)
Bubble_num = np.count_nonzero(class_ids == 2)
panel = tk.Label(app, text='Alive Embryo Detected = {}'.format(Alive_num))
panel.place(x=x_place+50, y=y_place+430)
panel = tk.Label(app, text='Dead Embryo Detected = {}'.format(Dead_num))
panel.place(x=x_place+250, y=y_place+430)
panel = tk.Label(app, text='Bubbles Detected = {}'.format(Bubble_num))
panel.place(x=x_place+450, y=y_place+430)
panel = tk.Label(app, text='Yolo detection {} time = {} sec'.format(dish_number, round(time.time() - start_time, 2)))
panel.place(x=x_place+250, y=y_place+450)
print('Time = ', time.time() - start_time, 'sec')
print('Yolo detection finished')
def call_ml_yolo(values):
yolo_detection_start[0] = True
b54.configure(bg='green')
def go_to_pos_GUI(values):
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def XYZ_set_speed(values):
XYZ = MyXYZ()
XYZ.set_Velocity(float((values[18]).get()), float((values[19]).get()), float((values[20]).get()))
def select_XYZ():
XYZ = MyXYZ()
def camera_on(videoloop_stop):
threading.Thread(target=videoLoop, args=(videoloop_stop,)).start()
print('Camera is on')
b5.configure(bg='green')
b41.configure(bg=app.cget('bg'))
def camera_off(videoloop_stop):
videoloop_stop[0] = True
b5.configure(bg=app.cget('bg'))
b41.configure(bg='red')
print('Camera is off')
def videoLoop(mirror=False):
No = 0
S=AmscopeCamera(0)
S.activate()
time.sleep(2)
flag = 0
panel = tk.Label(image=None)
panel.image = None
panel.place(x=1250, y=25)
while True:
frame=S.get_frame()
time.sleep(0.01)
frame=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame=cv2.resize(frame, (640, 480))
if mirror is True:
frame = frame[:, ::-1]
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel.configure(image=image)
panel.image = image
# check switcher value
if autofocus_start[0]:
autofocus_start[0] = False
S.deactivate()
panel.destroy()
print('Camera is off')
z_ref = autofocus(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
values[2].delete(0, tk.END)
values[2].insert(10, z_ref)
videoloop_stop[0] = False
camera_on(videoloop_stop)
break
if videoloop_stop[0]:
# if switcher tells to stop then we switch it again and stop videoloop
videoloop_stop[0] = False
S.deactivate()
panel.destroy()
break
return panel
def camera_on_inclined_1(videoloop_stop_inclined_1):
threading.Thread(target=videoLoop_inclined_1, args=(videoloop_stop_inclined_1, 1)).start()
print('Inclined Camera is on')
b43.configure(bg='green')
b44.configure(bg=app.cget('bg'))
# b53.configure(bg=app.cget('bg'))
def camera_off_inclined_1(videoloop_stop_inclined_1):
videoloop_stop_inclined_1[0] = True
needle_detection_start_1[0] = False
# b43.configure(bg=app.cget('bg'))
# b44.configure(bg='red')
print('Inclined Camera is off')
def camera_on_inclined_2(videoloop_stop_inclined_2):
threading.Thread(target=videoLoop_inclined_2, args=(videoloop_stop_inclined_2, 2)).start()
print('Inclined Camera is on')
b51.configure(bg='green')
b52.configure(bg=app.cget('bg'))
# b46.configure(bg=app.cget('bg'))
def camera_off_inclined_2(videoloop_stop_inclined_2):
videoloop_stop_inclined_2[0] = True
# b51.configure(bg=app.cget('bg'))
# b52.configure(bg='red')
print('Inclined Camera is off')
def videoLoop_inclined_1(yolk_left, pipe_left, inj_succ_left, take_image_flag_1, yolo_inj_succ_start_1, yolo_pipe_start_1, embryo_number, image_folder_time, attempt_number, mirror=False):
No = 0
panels = []
cap1 = cv2.VideoCapture(2)
if not(cap1.isOpened()):
print('Could not open video device 1')
else:
cap1.set(cv2.CAP_PROP_FRAME_WIDTH, 1280*1)
cap1.set(cv2.CAP_PROP_FRAME_HEIGHT, 720*1)
flag = 0
panel = tk.Label(image=None)
panel.image = None
panel.place(x=475, y=590)
# panel_ned_pos = tk.Label(app, text='Neddle Detection = (0,0)')
# panel_ned_pos.place(x=475, y=590)
while True:
# cap1 = cv2.VideoCapture(3)
ret1, frame1 = cap1.read()
# time.sleep(0.01)
if needle_detection_start_1[0]:
needle_detection_start_1[0] = False
frame1 = cv2.rotate(frame1, cv2.ROTATE_180)
cv2.imwrite('Needle_image.jpg', frame1)
# print('Inclined Camera is off')
(x_needle, y_needle) = needle_detection(0)
time.sleep(2)
# needle_point_detected[0] = True
# print(needle_point_detected)
videoloop_stop_inclined_1[0] = True
# cap1.release()
# panel.destroy()
image = cv2.imread('Needle_image_detected.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.rotate(image, cv2.ROTATE_180)
image = cv2.resize(image, (640, 320))
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel_ned = tk.Label(image=image)
panel_ned.image = image
panel_ned.place(x=475, y=590)
# panel_ned_pos = tk.Label(app, text='Neddle Detection = ({},{})'.format(x_needle,y_needle))
# panel_ned_pos.place(x=475, y=590)
print('Needle Detection Done')
needle_detection_start_1[0] = False
break
if take_image_flag_1.queue[-1]:
print('Image 1 captured')
current_embryo_number = embryo_number.queue[-1]
current_attempt = attempt_number.queue[-1]
folder_name = image_folder_time.queue[-1]
cv2.imwrite('Injection_Images/' + folder_name + '/Embryo_left_{}_{}.jpg'.format(current_embryo_number, current_attempt), frame1)
take_image_flag_1.put(False)
if yolo_inj_succ_start_1.queue[-1]:
frame1, success_status, unsuccess_status = YOLO_inj_success_1(frame1)
if whole_start[0]:
inj_succ_left.put(success_status)
yolo_inj_succ_start_1.put(False)
if yolo_detection_start[0]:
frame1, boxes_pipe, boxes_cell, boxes_yolk = YOLO_ML_1(frame1)
if whole_start[0]:
yolk_left.put(boxes_yolk)
if yolo_pipe_start_1.queue[-1]:
frame1, boxes_pipe_tip = YOLO_pipe_1(frame1)
if whole_start[0]:
pipe_left.put(boxes_pipe_tip)
# # Live Needle detection code
# frame1 = cv2.rotate(frame1, cv2.ROTATE_180)
# (x_needle, y_needle, frame1) = needle_detection_live_1(frame1)
# panel_ned_pos.configure(text='Neddle Detection = ({},{})'.format(x_needle,y_needle))
# panel_ned_pos.text = 'Neddle Detection = ({},{})'.format(x_needle,y_needle)
# frame1 = cv2.rotate(frame1, cv2.ROTATE_180)
# # Live needle detection end
# # Circles for references
# frame1 = cv2.circle(frame1, (0,366), radius=5, color=(0, 0, 255), thickness=-1)
# frame1 = cv2.circle(frame1, (1280,366), radius=5, color=(0, 0, 255), thickness=-1)
# frame1 = cv2.circle(frame1, (878,0), radius=5, color=(0, 0, 255), thickness=-1)
# frame1 = cv2.circle(frame1, (878,720), radius=5, color=(0, 0, 255), thickness=-1)
# frame1 = cv2.circle(frame1, (625,346), radius=5, color=(0, 0, 255), thickness=-1)
frame1 = cv2.resize(frame1, (640, 320))
if mirror is True:
frame1 = frame1[:, ::-1]
image = cv2.cvtColor(frame1, cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel.configure(image=image)
panel.image = image
# check switcher value
if videoloop_stop_inclined_1[0]:
# if switcher tells to stop then we switch it again and stop videoloop
videoloop_stop_inclined_1[0] = False
cap1.release()
app.update()
time.sleep(0.01)
panel.destroy()
break
return panel
def videoLoop_inclined_2(yolk_right, pipe_right, inj_succ_right, take_image_flag_2, yolo_inj_succ_start_2, yolo_pipe_start_2, embryo_number, image_folder_time, attempt_number, mirror=False):
No = 0
cap2 = cv2.VideoCapture(3)
if not(cap2.isOpened()):
print('Could not open video device')
else:
cap2.set(cv2.CAP_PROP_FRAME_WIDTH, 1280*1)
cap2.set(cv2.CAP_PROP_FRAME_HEIGHT, 720*1)
flag = 0
panel = tk.Label(image=None)
panel.image = None
panel.place(x=1250, y=590)
# panel_ned_pos = tk.Label(app, text='Neddle Detection = (0,0)')
# panel_ned_pos.place(x=1250, y=590)
while True:
# cap = cv2.VideoCapture(4)
ret2, frame2 = cap2.read()
# time.sleep(0.01)
if needle_detection_start_2[0]:
needle_detection_start_2[0] = False
frame2 = cv2.rotate(frame2, cv2.ROTATE_180)
cv2.imwrite('Needle_image.jpg', frame2)
# print('Inclined Camera is off')
(x_needle, y_needle) = needle_detection(0)
time.sleep(2)
# needle_point_detected[0] = True
# print(needle_point_detected)
videoloop_stop_inclined_2[0] = False
# cap2.release()
# panel.destroy()
image = cv2.imread('Needle_image_detected.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.rotate(image, cv2.ROTATE_180)
image = cv2.resize(image, (640, 320))
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel = tk.Label(image=image)
panel.image = image
panel.place(x=1250, y=590)
# panel = tk.Label(app, text='Neddle Detection = ({},{})'.format(x_needle,y_needle))
# panel.place(x=1250, y=590)
print('Needle Detection Done')
break
if take_image_flag_2.queue[-1]:
print('Image 2 captured')
current_embryo_number = embryo_number.queue[-1]
current_attempt = attempt_number.queue[-1]
folder_name = image_folder_time.queue[-1]
cv2.imwrite('Injection_Images/' + folder_name + '/Embryo_right_{}_{}.jpg'.format(current_embryo_number, current_attempt), frame2)
take_image_flag_2.put(False)
if yolo_inj_succ_start_2.queue[-1]:
frame2, success_status, unsuccess_status = YOLO_inj_success_2(frame2)
if whole_start[0]:
inj_succ_right.put(success_status)
yolo_inj_succ_start_2.put(False)
if yolo_detection_start[0]:
frame2, boxes_pipe, boxes_cell, boxes_yolk = YOLO_ML_2(frame2)
if whole_start[0]:
yolk_right.put(boxes_yolk)
if yolo_pipe_start_2.queue[-1]:
frame2, boxes_pipe_tip = YOLO_pipe_2(frame2)
if whole_start[0]:
pipe_right.put(boxes_pipe_tip)
# Live Needle detection code
# frame2 = cv2.rotate(frame2, cv2.ROTATE_180)
# (x_needle, y_needle, frame2) = needle_detection_live_2(frame2)
# panel_ned_pos.configure(text='Neddle Detection = ({},{})'.format(x_needle,y_needle))
# panel_ned_pos.text = 'Neddle Detection = ({},{})'.format(x_needle,y_needle)
# frame2 = cv2.rotate(frame2, cv2.ROTATE_180)
# Live needle detection end
# frame2 =cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
# frame2 = cv2.rotate(frame2, cv2.ROTATE_180)
# # Circles for references
# frame2 = cv2.circle(frame2, (0,427), radius=5, color=(0, 0, 255), thickness=-1)
# frame2 = cv2.circle(frame2, (1280,427), radius=5, color=(0, 0, 255), thickness=-1)
# frame2 = cv2.circle(frame2, (500,0), radius=5, color=(0, 0, 255), thickness=-1)
# frame2 = cv2.circle(frame2, (500,720), radius=5, color=(0, 0, 255), thickness=-1)
# frame2 = cv2.circle(frame2, (782,376), radius=5, color=(0, 0, 255), thickness=-1)
frame2 = cv2.resize(frame2, (640, 320))
if mirror is True:
frame2 = frame2[:, ::-1]
image = cv2.cvtColor(frame2, cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel.configure(image=image)
panel.image = image
# check switcher value
if videoloop_stop_inclined_2[0]:
# if switcher tells to stop then we switch it again and stop videoloop
videoloop_stop_inclined_2[0] = False
cap2.release()
app.update()
time.sleep(0.01)
panel.destroy()
break
return panel
def call_autofocus(values):
autofocus_start[0] = True
def move_center(default_center, values):
values[0].delete(0, tk.END)
values[0].insert(10, default_center[0])
values[1].delete(0, tk.END)
values[1].insert(10, default_center[1])
values[2].delete(0, tk.END)
values[2].insert(10, default_center[2])
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def move_y_plus(values):
m = float((values[1]).get()) - float((values[4]).get())
values[1].delete(0, tk.END)
values[1].insert(10, m)
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def move_y_negative(values):
m = float((values[1]).get()) + float((values[4]).get())
values[1].delete(0, tk.END)
values[1].insert(10, m)
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def move_x_plus(values):
m = float((values[0]).get()) - float((values[3]).get())
values[0].delete(0, tk.END)
values[0].insert(10, m)
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def move_x_negative(values):
m = float((values[0]).get()) + float((values[3]).get())
values[0].delete(0, tk.END)
values[0].insert(10, m)
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def move_z_plus(values):
m = float((values[2]).get()) + float((values[5]).get())
values[2].delete(0, tk.END)
values[2].insert(10, m)
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def move_z_negative(values):
m = float((values[2]).get()) - float((values[5]).get())
values[2].delete(0, tk.END)
values[2].insert(10, m)
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
def change_dx(value):
values[3].delete(0, tk.END)
values[3].insert(10, value)
values[4].delete(0, tk.END)
values[4].insert(10, value)
values[5].delete(0, tk.END)
values[5].insert(10, value)
def LED_on_off(value):
# if value == 0:
# b56.configure(bg='red')
# b18.configure(bg='red')
# b19.configure(bg='red')
# b55.configure(bg=app.cget('bg'))
# if value == 1:
# b18.configure(bg='green')
# b19.configure(bg='red')
# b55.configure(bg=app.cget('bg'))
# b56.configure(bg=app.cget('bg'))
# if value == 2:
# b18.configure(bg='red')
# b19.configure(bg='green')
# b55.configure(bg=app.cget('bg'))
# b56.configure(bg=app.cget('bg'))
# if value == 3:
# b55.configure(bg='green')
# b18.configure(bg='green')
# b19.configure(bg='green')
# b56.configure(bg=app.cget('bg'))
LED(value)
def select_UMP():
UMP = MyUMP()
def calibrate_UMP():
MyUMP.Calibration(True)
def go_to_UMP_pos_GUI(values):
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_center_UMP(default_center, values):
values[7].delete(0, tk.END)
values[7].insert(10, default_center_UMP[0])
values[8].delete(0, tk.END)
values[8].insert(10, default_center_UMP[1])
values[9].delete(0, tk.END)
values[9].insert(10, default_center_UMP[2])
values[10].delete(0, tk.END)
values[10].insert(10, default_center_UMP[3])
values[11].delete(0, tk.END)
values[11].insert(10, default_center_UMP[4])
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_x_plus_UMP(values):
m = float((values[7]).get()) + float((values[12]).get())
values[7].delete(0, tk.END)
values[7].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_x_negative_UMP(values):
m = float((values[7]).get()) - float((values[12]).get())
values[7].delete(0, tk.END)
values[7].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_y_plus_UMP(values):
m = float((values[8]).get()) + float((values[13]).get())
values[8].delete(0, tk.END)
values[8].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_y_negative_UMP(values):
m = float((values[8]).get()) - float((values[13]).get())
values[8].delete(0, tk.END)
values[8].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_z_plus_UMP(values):
m = float((values[9]).get()) + float((values[14]).get())
values[9].delete(0, tk.END)
values[9].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_z_negative_UMP(values):
m = float((values[9]).get()) - float((values[14]).get())
values[9].delete(0, tk.END)
values[9].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_d_plus_UMP(values):
m = float((values[10]).get()) + float((values[15]).get())
values[10].delete(0, tk.END)
values[10].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def move_d_negative_UMP(values):
m = float((values[10]).get()) - float((values[15]).get())
values[10].delete(0, tk.END)
values[10].insert(10, m)
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def change_dx_UMP(value):
values[12].delete(0, tk.END)
values[12].insert(10, value)
values[13].delete(0, tk.END)
values[13].insert(10, value)
values[14].delete(0, tk.END)
values[14].insert(10, value)
values[15].delete(0, tk.END)
values[15].insert(10, value)
def change_speed_UMP(value):
values[11].delete(0, tk.END)
values[11].insert(10, value)
def getorigin(eventorigin):
x = eventorigin.x
y = eventorigin.y
x = 8*x
y = 8*y
print(x, y)
box_center = np.load('box_center.npy')
dis = np.zeros((len(box_center),1))
for i in range(len(box_center)):
dis[i][0] = np.square(x - (box_center[i][0])) + np.square(y - (box_center[i][1]))
index = np.argmin(dis)
box_coordinate = np.load('output_dict_detection_boxes_stored_modi.npy')
box_center_x = box_center[index][0]#*6000
box_center_y = box_center[index][1]#*4000
# print(box_center[index][0]*6000, box_center[index][1]*4000)
image = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_detection.jpg')
image = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_with_clicked_Box.jpg')
# start_point = (int(box_coordinate[0][index][1]*6000), int(box_coordinate[0][index][0]*4000))
# end_point = (int(box_coordinate[0][index][3]*6000), int(box_coordinate[0][index][2]*4000))
start_point = (int(box_coordinate[index][1]), int(box_coordinate[index][0]))
end_point = (int(box_coordinate[index][3]), int(box_coordinate[index][2]))
image = cv2.rectangle(image, start_point, end_point, (255, 0, 0), 12)
# image = cv2.circle(image, (box_center_x, box_center_y), 50, (255, 0, 0), 2)
image_record = cv2.rectangle(image, start_point, end_point, (255, 255, 0), 12)
cv2.imwrite('DSLR_image_with_clicked_Box.jpg', image_record)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (640, 427))
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel = tk.Label(image=image)
panel.image = image
panel.place(x=475, y=25)
(x_stage, y_stage) = transformation_DSLR_4x(box_center_x, box_center_y)
XYZ = MyXYZ()
# Comment out this if you want to go to 4x objective
# XYZ.Position(x_stage, y_stage, z_reference)
values[0].delete(0, tk.END)
values[0].insert(10, x_stage)
values[1].delete(0, tk.END)
values[1].insert(10, y_stage)
values[2].delete(0, tk.END)
values[2].insert(10, z_reference)
def needle_position():
values[0].delete(0, tk.END)
values[0].insert(10, default_needle_XYZ[0])
values[1].delete(0, tk.END)
values[1].insert(10, default_needle_XYZ[1])
values[2].delete(0, tk.END)
values[2].insert(10, default_needle_XYZ[2])
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()), float((values[1]).get()), float((values[2]).get()))
values[7].delete(0, tk.END)
values[7].insert(10, default_needle[0])
values[8].delete(0, tk.END)
values[8].insert(10, default_needle[1])
values[9].delete(0, tk.END)
values[9].insert(10, default_needle[2])
values[10].delete(0, tk.END)
values[10].insert(10, default_needle[3])
values[11].delete(0, tk.END)
values[11].insert(10, default_needle[4])
MyUMP.Position(float((values[7]).get()), float((values[8]).get()), float((values[9]).get()), float((values[10]).get()), float((values[11]).get()))
def get_inject_status(status):
if status == True:
inject_status[0] = True
b48.configure(bg='green')
b49.configure(bg='red')
if status == False:
inject_status[0] = False
b48.configure(bg='red')
b49.configure(bg='green')
def inject_fun(values):
if inject_status[0] == True:
call_pressure(values, 'I')
if inject_status[0] == False:
call_pressure(values, 'W')
def call_needle_detection_1(values):
needle_detection_start_1[0] = True
b43.configure(bg=app.cget('bg'))
b44.configure(bg='red')
b53.configure(bg='green')
print('Inclined Camera is off')
def call_needle_detection_2(values):
needle_detection_start_2[0] = True
b51.configure(bg=app.cget('bg'))
b52.configure(bg='red')
b46.configure(bg='green')
print('Inclined Camera is off')
def call_inject(values):
XYZ = MyXYZ()
XYZ.Position(float((values[0]).get()) + default_inject[0], float((values[1]).get()) + default_inject[1], 15)
# time.sleep(1)
XYZ.Position(float((values[0]).get()) + default_inject[0], float((values[1]).get()) + default_inject[1], float((values[2]).get()) + default_inject[2] - 1)
# time.sleep(1)
XYZ.Position(float((values[0]).get()) + default_inject[0], float((values[1]).get()) + default_inject[1], float((values[2]).get()) + default_inject[2] - 0.5)
# time.sleep(1)
XYZ.Position(float((values[0]).get()) + default_inject[0], float((values[1]).get()) + default_inject[1], float((values[2]).get()) + default_inject[2])
time.sleep(1)
call_pressure(values, 'I')
time.sleep(1)
XYZ.Position(float((values[0]).get()) + default_inject[0], float((values[1]).get()) + default_inject[1], 15)
# m = float((values[0]).get()) - 80.2284
# n = float((values[1]).get()) + 2.1979
# p = float((values[2]).get()) + 16.8
m = float((values[0]).get()) + default_inject[0]
n = float((values[1]).get()) + default_inject[1]
# p = float((values[2]).get()) + 15
p = 15
values[0].delete(0, tk.END)
values[0].insert(10, m)
values[1].delete(0, tk.END)
values[1].insert(10, n)
values[2].delete(0, tk.END)
values[2].insert(10, p)
# Recording function
def recording(mirror=False):
# display screen resolution, get it from your OS settings
SCREEN_SIZE = (1920, 1080)
# define the codec
fourcc = cv2.VideoWriter_fourcc(*"XVID")
# create the video write object
out = cv2.VideoWriter("output.avi", fourcc, 60.0, (SCREEN_SIZE))
while True:
# make a screenshot
img = pyautogui.screenshot()
# convert these pixels to a proper numpy array to work with OpenCV
frame = np.array(img)
# convert colors from BGR to RGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# write the frame
out.write(frame)
# if the user clicks q, it exits
if recording_stop[0] == True:
cv2.destroyAllWindows()
out.release()
break
# Stop Recording function
def stop_recording(mirror = False):
recording_stop = [True]
def decide_dish(dish_number):
global dish1_flag
global dish2_flag
if dish_number == 1:
if b64.cget('bg') == 'red':
dish1_flag = [True]
b64.configure(bg='green')
print(dish1_flag)
elif b64.cget('bg') == 'green':
dish1_flag = [False]
b64.configure(bg='red')
print(dish1_flag)
if dish_number == 2:
if b65.cget('bg') == 'red':
dish2_flag = [True]
b65.configure(bg='green')
print(dish2_flag)
elif b65.cget('bg') == 'green':
dish2_flag = [False]
b65.configure(bg='red')
print(dish2_flag)
def decide_pipe():
global pipe_flag
if b66.cget('bg') == 'red':
pipe_flag = [True]
b66.configure(bg='green')
print(pipe_flag)
elif b66.cget('bg') == 'green':
pipe_flag = [False]
b66.configure(bg='red')
print(pipe_flag)
def Data_save(dish_number, injection_material, values, current_time, unsuccess_inj, success_inj):
time = datetime.datetime.now()
time = time.strftime("%m-%d-%Y_%H-%M-%S")
os.mkdir('D:/Microinjection_Project/Python_Code/Injection_Data/'+time)
ori_img = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_{}.jpg'.format(dish_number))
yolo_img = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_detection_{}.jpg'.format(dish_number))
inje_img = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_with_clicked_Box_{}.jpg'.format(dish_number))
path_img = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_2opt_path.jpg')
box_center = np.load('D:/Microinjection_Project/Python_Code/box_center.npy')
box_coordinate = np.load('D:/Microinjection_Project/Python_Code/box_coordinate.npy')
class_ids = np.load('D:/Microinjection_Project/Python_Code/class_ids.npy')
file = open("D:/Microinjection_Project/Python_Code/Injection_Data/{}/Injection_{}.txt".format(time, time), "w+")
file.write("Date and Time: %s \n" %(time))
file.write("Injection material: %s \n" %(injection_material[dish_number-1]))
file.write("Volume: %d nl\n" %(int((values[16]).get())))
file.write("Rate: %d nl/sec \n" %(int((values[17]).get())))
Alive_num = np.count_nonzero(class_ids == 0)
Dead_num = np.count_nonzero(class_ids == 1)
Bubble_num = np.count_nonzero(class_ids == 2)
file.write("Alive embryo: %d Dead embryo: %d Bubble: %d \n" %(Alive_num, Dead_num, Bubble_num))
file.write("Successful injection: %d Unsuccessful injection: %d \n" %(success_inj, unsuccess_inj))
file.write("Injection time: %s min \n" %(str(current_time)))
file.close()
cv2.imwrite('D:/Microinjection_Project/Python_Code/Injection_Data/{}/DSLR_image_{}.jpg'.format(time, dish_number), ori_img)
cv2.imwrite('D:/Microinjection_Project/Python_Code/Injection_Data/{}/DSLR_image_detection_{}.jpg'.format(time, dish_number), yolo_img)
cv2.imwrite('D:/Microinjection_Project/Python_Code/Injection_Data/{}/DSLR_image_with_clicked_Box_{}.jpg'.format(time, dish_number), inje_img)
cv2.imwrite('D:/Microinjection_Project/Python_Code/Injection_Data/{}/DSLR_image_2opt_path.jpg'.format(time), path_img)
np.save('D:/Microinjection_Project/Python_Code/Injection_Data/{}/box_center.npy'.format(time), box_center)
np.save('D:/Microinjection_Project/Python_Code/Injection_Data/{}/box_coordinate.npy'.format(time), box_coordinate)
np.save('D:/Microinjection_Project/Python_Code/Injection_Data/{}/class_ids.npy'.format(time), class_ids)
def Data_save_injection_images(image_time, pip_left, pip_righ, initial_xyz_stage, yolk_data, change_xyz, sorted_box_center):
file = open("D:/Microinjection_Project/Python_Code/Injection_Images/" + image_time + "/Pipette.txt", "w+")
file.write("Pipette left: X=%d, Y=%d\n" %(pip_left.item(0), pip_left.item(1)))
file.write("Pipette right: X=%d, Y=%d" %(pip_righ.item(0), pip_righ.item(1)))
file.close()
for i in range(len(yolk_data)):
file = open("D:/Microinjection_Project/Python_Code/Injection_Images/" + image_time + "/Embryo_{}.txt".format(i+1), "w+")
file.write("Initial XYZ: X=%d, Y=%d, Z=%d \n" %(initial_xyz_stage[i][0], initial_xyz_stage[i][1], initial_xyz_stage[i][2]))
file.write("Initial DSLR Pixel: X=%d, Y=%d \n" %(sorted_box_center[i][0], sorted_box_center[i][1]))
for j in range(len(yolk_data[i])):
file.write("Attempt %d: \n" %(j))
file.write("Yolk left: X=%s, Y=%s; Yolk right: X=%s, Y=%s \n" %(str(yolk_data[i][j][0]), str(yolk_data[i][j][1]), str(yolk_data[i][j][2]), str(yolk_data[i][j][3])))
file.write("dX=%s, dY=%s, dZ=%s \n" %(str(change_xyz[i][j][0]), str(change_xyz[i][j][1]), str(change_xyz[i][j][2])))
file.write("\n")
file.close()
pip_orig_left = cv2.imread('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/Embryo_left_1000_0.jpg')
pip_orig_righ = cv2.imread('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/Embryo_right_1000_0.jpg')
cv2.imwrite('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/Pipette_left.jpg', pip_orig_left)
cv2.imwrite('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/Pipette_right.jpg', pip_orig_righ)
np.save('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/Pipette_left.npy', pip_left)
np.save('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/Pipette_right.npy', pip_righ)
np.save('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/initial_xyz_stage.npy', initial_xyz_stage)
np.save('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/yolk_data.npy', yolk_data)
np.save('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/change_xyz.npy', change_xyz)
np.save('D:/Microinjection_Project/Python_Code/Injection_Images/' + image_time + '/sorted_box_center.npy', sorted_box_center)
def call_pressure(values, direction):
Pressure = MyPressureSystem()
if direction == 'I':
Pressure.inject(float((values[16]).get()), float((values[17]).get()))
if direction == 'W':
Pressure.withdraw(float((values[16]).get()), float((values[17]).get()))
def vial(vial_num, volume, rate, status):
XYZ = MyXYZ()
Position = XYZ.Get_Pos()
XYZ.Position(Position['1'], Position['2'], 0)
x, y, z = transformation_vial(vial_num)
XYZ.Position(x, y, 0)
XYZ.Position(x, y, z)
# Add pressure line here
Pressure = MyPressureSystem()
if status[0] == True:
Pressure.inject(volume, rate)
if status[0] == False:
Pressure.withdraw(volume, rate)
time.sleep(2)
XYZ.Position(x, y, 0)
values[0].delete(0, tk.END)
values[0].insert(10, x)
values[1].delete(0, tk.END)
values[1].insert(10, y)
values[2].delete(0, tk.END)
values[2].insert(10, 0)
def start_whole(mirror=False):
LED_on_off(3)
# DSLR_image('DSLR_image.jpg')
app.update()
ML_detect_faster_RCNN('DSLR_image.jpg', 'D:/Microinjection_Project/Python_Code/', 1)
app.update()
box_center = np.load('box_center.npy')
box_coordinate = np.load('output_dict_detection_boxes_stored_modi.npy')
number_detection = len(box_center)
pre_box_center_x = int(box_center[0][0])
pre_box_center_y = int(box_center[0][1])
for i in range(number_detection):
box_center_x = box_center[i][0]
box_center_y = box_center[i][1]
(x_stage, y_stage) = transformation_DSLR_4x(box_center_x, box_center_y)
# image = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_detection.jpg')
image = cv2.imread('D:/Microinjection_Project/Python_Code/DSLR_image_with_clicked_Box.jpg')
start_point = (int(box_coordinate[i][1]), int(box_coordinate[i][0]))
end_point = (int(box_coordinate[i][3]), int(box_coordinate[i][2]))
image = cv2.rectangle(image, start_point, end_point, (255, 0, 0), 12)
image = cv2.line(image, (int(pre_box_center_x), int(pre_box_center_y)), (int(box_center_x), int(box_center_y)), (0, 0, 255), 3)
image_record = image
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (640, 427))
image = Image.fromarray(image)
image = ImageTk.PhotoImage(image)
panel = tk.Label(image=image)
panel.image = image
panel.place(x=475, y=25)
if i == 0:
image_record = cv2.rectangle(image_record, start_point, end_point, (0, 0, 0), 12)
elif i == (number_detection - 1):
image_record = cv2.rectangle(image_record, start_point, end_point, (255, 0, 0), 12)
else:
image_record = cv2.rectangle(image_record, start_point, end_point, (50, 205, 154), 12)
image_record = cv2.rectangle(image_record, start_point, end_point, (0, 255, 255), 6)
cv2.imwrite('DSLR_image_with_clicked_Box.jpg', image_record)
pre_box_center_x = int(box_center_x)
pre_box_center_y = int(box_center_y)
app.update()
values[0].delete(0, tk.END)
values[0].insert(10, x_stage)
values[1].delete(0, tk.END)
values[1].insert(10, y_stage)
values[2].delete(0, tk.END)
values[2].insert(10, z_reference)
# call_inject(values)
panel = tk.Label(app, text='{} Embryo injected'.format(i+1))
panel.place(x=1600, y=555)
print(i+1,'Embryo injected')
LED_on_off(0)
def pip_detection(pipe_left, pipe_right):
pipe_left_data = pipe_left.queue[-1]
pipe_right_data = pipe_right.queue[-1]
if pipe_left_data:
print(pipe_left_data[0])
x, y, w, h = pipe_left_data[0]
pip_left_x = x + (w/2)
pip_left_y = y + h
pip_left = np.matrix([[pip_left_x], [pip_left_y]])
else:
pip_left = np.matrix([[], []])
if pipe_right_data:
print(pipe_right_data[0])
x, y, w, h = pipe_right_data[0]
pip_righ_x = x + (w/2)
pip_righ_y = y + h
pip_righ = np.matrix([[pip_righ_x], [pip_righ_y]])
else:
pip_righ = np.matrix([[], []])
# pip_left = np.matrix([[543], [194]])
# pip_righ = np.matrix([[614], [208]])
print('pip_left', pip_left)
print('pip_righ', pip_righ)
return pip_left, pip_righ
def get_z_reference(box_center, dish_number, pip_left, pip_righ, yolk_left, yolk_right):
box_center_x = box_center[int(len(box_center)/2)][0]
box_center_y = box_center[int(len(box_center)/2)][1]
(x_stage, y_stage) = transformation_DSLR_inj(box_center_x, box_center_y, dish_number)
emb_status = 0
XYZ = MyXYZ()
z_reference = 0
while emb_status == 0:
z_reference = z_reference + 0.5