-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmosaic.py
73 lines (60 loc) · 1.68 KB
/
mosaic.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
'''
Creates a photo mosaic using the stage
check this
https://github.com/opencv/opencv_attic/blob/master/opencv/samples/cpp/fitellipse.cpp
https://stackoverflow.com/questions/42206042/ellipse-detection-in-opencv-python
http://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html
'''
from devices import *
from serial import SerialException
from AutomaticPatch.Camera.camera_init import *
from pylab import *
import cv2
from os.path import expanduser
home = expanduser("~")
SM5 = True
mmc = camera_init('SM5')
try:
if SM5:
dev = LuigsNeumann_SM5('COM3')
else:
dev = LuigsNeumann_SM10()
except SerialException:
print "L&N not found. Falling back on fake device."
dev = FakeDevice()
"""
if SM5:
microscope_Z = Leica('COM1')
microscope = XYMicUnit(dev, microscope_Z, [7, 8])
else:
microscope = XYZUnit(dev, [7, 8, 9])
"""
microscope = XYZUnit(dev, [7,8])
print "Device initialized"
# We first need to calibrate the stage
# Then we take a series of photos
frames = []
for j in range(5):
for i in range(10):
microscope.relative_move(200., axis = 0)
microscope.wait_motor_stop(axis = 0)
mmc.snapImage()
frames.append(mmc.getImage())
microscope.relative_move(200., axis = 1)
microscope.wait_motor_stop(axis=1)
mmc.snapImage()
frames.append(mmc.getImage())
for i in range(10):
microscope.relative_move(-200., axis = 0)
microscope.wait_motor_stop(axis = 0)
mmc.snapImage()
frames.append(mmc.getImage())
camera_unload(mmc)
for i in enumerate(frames):
cv2.imwrite(home+'/mosaic'+str(i)+'.jpg')
del dev
"""
for frame in frames[:10]:
imshow(frame, cmap='gray')
show()
"""