-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcallibrate.py
74 lines (62 loc) · 2.58 KB
/
callibrate.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
import os
from process import lasers
import cv2, numpy
threshold = 10
useGuide = False
useLasers = True
def init():
os.system("gphoto2 --set-config /main/imgsettings/iso=0 " +
"--set-config /main/capturesettings/shutterspeed2=32 " +
"--set-config /main/imgsettings/whitebalance=3 " +
"--set-config /main/capturesettings/f-number=10 " +
"--set-config /main/imgsettings/imagesize=2 " +
"--set-config /main/capturesettings/imagequality=0 ")
def captureGuide():
os.system("gphoto2 --filename callibrate-guide.jpg " +
"--capture-image-and-download --force-overwrite")
def captureLasers():
os.system("gphoto2 --filename callibrate-lasers.jpg " +
"--capture-image-and-download --force-overwrite")
def captureBackground():
os.system("capture/all-off")
#os.system("capture/lights-on")
os.system("gphoto2 --filename callibrate-background.jpg " +
"--capture-image-and-download --force-overwrite")
init()
captureBackground()
background = cv2.imread('callibrate-background.jpg')
background = cv2.resize(background, (500, 748))
while True:
if useGuide:
os.system("capture/lasers-off")
os.system("capture/guide-on")
captureGuide()
guideImage = cv2.imread('callibrate-guide.jpg')
guideImage = cv2.resize(guideImage, (500, 748))
if useLasers:
os.system("capture/guide-off")
os.system("capture/lasers-on")
captureLasers()
laserImage = cv2.imread('callibrate-lasers.jpg')
laserImage = cv2.resize(laserImage, (500, 748))
if useGuide:
guideImage = cv2.transpose(guideImage)
cv2.flip(guideImage, 0, guideImage)
guideMask = lasers.findLaserImage(guideImage, cv2.transpose(background), threshold=threshold)
cv2.imwrite('guide-mask.png', guideMask)
guidePoints = lasers.extractLaserPoints(guideMask, (0, guideImage.shape[0]))
guideLaser = lasers.Laser(guideMask, guidePoints, True, True, True)
print 'guide pos:', guideLaser.curve[0], '/', guideMask.shape[0]
print 'guide:', - guideLaser.getAngle() - 90
if useLasers:
laserMask = lasers.findLaserImage(laserImage, background, threshold=threshold)
cv2.imwrite('laser-mask.png', laserMask)
topLaser, bottomLaser = lasers.extractLasers(laserMask, True, True)
print 'top pos:', topLaser.curve[0], '/', laserImage.shape[0]
print 'top:', topLaser.getAngle()
print 'bottom pos:', bottomLaser.curve[0], '/', laserImage.shape[0]
print 'bottom:', bottomLaser.getAngle()
os.system("capture/guide-on")
raw_input('Press enter...')
#os.system("capture/guide-on")
#os.system("capture/lasers-on")