-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasure_depth.py
159 lines (141 loc) · 5.5 KB
/
measure_depth.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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# ./measure_depth.py
#
# (c) 2010 Konstantin Sering, Nora Umbach, Dominik Wabersich
# <colorlab[at]psycho.uni-tuebingen.de>
#
# GPL 3.0+ or (cc) by-sa (http://creativecommons.org/licenses/by-sa/3.0/)
#
# content: Script for measuring monitor; define how many measurements,
# if you want to recalibrate i1, etc.
#
# input: --
# output: --
#
# created 2011-10-14
# last mod 2013-10-17 NU
import sys
sys.path.append("D:\\software\\achrolabutils")
sys.path.append("D:\\software\\")
import time
from achrolab import printing
from ctypes import c_float
from achrolab.eyeone import eyeone, constants
from psychopy import visual
from stimuli import eizoGS320
#############################
# Measurement values ####
#############################
# colors: list of colors that should be measured
# imi: inter measurement interval
colors = range(400, 500)
#colors = (374, 376, 380, 386, 392, 396, 398, 400, 404, 408, 410, 416, 422, 424, 428, 432, 436, 456, 476, 480, 496, 500, 504, 508, 512, 516, 536, 584, 588, 621)
imi = 0.5
#############################
# Repeat Measure-Process ####
#############################
# times: times variable repeats the whole measurement process 'times' times
# and asks to press the eyeone button before every new time.
# each: how often every stimulus will be repeated
# recalibrate: if times > 1, you can set 'recalibrate' to true, to recalibrate
# for every measurement process
times = 1
each = 5
recalibrate = True
#############################
# Measuring Information ####
#############################
# prefix: file prefix (in the filename)
prefix = "./EIZO_measure_bit_"
#############################
eyeone = eyeone.EyeOne(dummy=False) # EyeOne Object
# set EyeOne Pro variables
if(eyeone.I1_SetOption(constants.I1_MEASUREMENT_MODE,
constants.I1_SINGLE_EMISSION) ==
constants.eNoError):
print("Measurement mode set to single emission.")
else:
print("Failed to set measurement mode.")
if(eyeone.I1_SetOption(constants.COLOR_SPACE_KEY,
constants.COLOR_SPACE_CIExyY) == constants.eNoError):
print("Color space set to CIExyY.")
else:
print("Failed to set color space.")
# Initialization of spectrum and colorspace
colorspace = (c_float * constants.TRISTIMULUS_SIZE)()
spectrum = (c_float * constants.SPECTRUM_SIZE)()
spec_list = []
color_list = []
#set monitor color
mywin = visual.Window([1024,1536], monitor="mymon", color=(100,100,0),
screen=1, colorSpace="rgb255", allowGUI=False, units="pix")
# teststim=SquareStim(mywin,color=500, size=1024)
#background = eizoGS320.decode_color((mywin.color[0], mywin.color[1], mywin.color[2]))
#if not(background[0] == background[1]):
#print("WARNING: There is something wrong with the background color")
teststim = visual.GratingStim(mywin, tex=None, units='norm', pos=(0, 0), size=2,
colorSpace=mywin.colorSpace,
color=eizoGS320.encode_color(400, 400))
# while color > 0:
# teststim.draw()
# mywin.flip()
# color-=10
# teststim.setColor(eizoGS320.encode_color(color, color))
# print("something")
# if event.getKeys(keyList='escape'):
# break
# import pdb #@@@
# pdb.set_trace() #@@@
# print 'stop here' #@@@
def measure(color):
print "Color:" + str(color)
teststim.setColor(eizoGS320.encode_color(color, color))
teststim.draw()
mywin.flip()
time.sleep(imi)
# Trigger measurement
if(eyeone.I1_TriggerMeasurement() != constants.eNoError):
print("Measurement failed.")
# retrieve Color Space
if(eyeone.I1_GetTriStimulus(colorspace, 0) != constants.eNoError):
print("Failed to get color space.")
else:
print("Color Space " + str(colorspace[:]) + "\n")
color_list.append(colorspace[:])
# Write justmeasure color file containing the data
# f2.write(str(colorspace[:])[1:-1])
#f2.write("\n")
# retrieve spectrum
if(eyeone.I1_GetSpectrum(spectrum, 0) != constants.eNoError):
print("Failed to get spectrum.")
else:
print("Spectrum: " + str(spectrum[:]) + "\n")
spec_list.append(spectrum[:])
# write data to file
file.write_data_txt(grayvals=[color, color], rgb=None, xyY=colorspace,
voltage=None, spec_list=spectrum, delimiter="\t")
with printing.CalibDataFile(prefix=prefix) as file:
for n in range(times):
print("\nRound " + str(n + 1) + " of " + str(times) + ".\n")
# Put color changing code here, swap measurements dependence for
# some color dependence, and set times to number of recalibrations
# (perhaps batches of small numbers)
# Then recalibrate, repeat for all colours
if (recalibrate or (eyeone.I1_TriggerMeasurement() ==
constants.eDeviceNotCalibrated)):
# Calibration of EyeOne
print("\nPlease put EyeOne Pro on calibration plate and press \n key to start calibration.")
while(eyeone.I1_KeyPressed() != constants.eNoError):
time.sleep(0.1)
if (eyeone.I1_Calibrate() == constants.eNoError):
print("Calibration done.")
else:
print("Calibration failed.")
print("\nPlease put EyeOne Pro in measurement position and press \n key to start measurement.")
while(eyeone.I1_KeyPressed() != constants.eNoError):
time.sleep(0.1)
print("Starting measurement...")
for color in colors:
for i in range(each):
measure(color)