-
Notifications
You must be signed in to change notification settings - Fork 0
/
take n pictures8.py
191 lines (106 loc) · 4.01 KB
/
take n pictures8.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
from picamera import PiCamera
from time import sleep
from fractions import Fraction
import cv2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
font = cv2.FONT_HERSHEY_SIMPLEX
#camera = PiCamera(resolution=(1280,720 ))
#camera = PiCamera(resolution=(1280, 720),framerate=(Fraction (1,8)),sensor_mode=3)
camera = PiCamera(resolution=(1280, 720),framerate=(.3),sensor_mode=3)
#camera = PiCamera(framerate=(30))
filename="expfile"
#set wait time should be min 5 sec
waitime = 3
xrange = 5
print ("test")
#capture seed picture
camera.shutter_speed = 0
camera.iso = 0
sleep(waitime)
camera.capture('/home/pi/Desktop/testexposure.jpg')
img = cv2.imread('/home/pi/Desktop/testexposure.jpg')
#cv2.putText(img,"{0},{1}".format(x,y),(5,50), font, 2, (0,255,0), 9, cv2.LINE_AA)
img = cv2.resize(img, (0, 0), None, .25, .25)
#print ((x),(y),"{0:10s}".format(str(camera.shutter_speed/10000000)),(camera.iso))
#print ((x),(y),"{0:10s}".format(str(round(camera.shutter_speed/10000000))),(camera.iso))
#Raspberry pi exptime is in microseconds , program desigend to accept time in sec and convert to microsecinds
# enter times in sec
#times = [10,100,400,800]
exposure_times = np.array([0.1, 1.0, 2.0, 3.0], dtype=np.float32)
np.save(filename, exposure_times)
print (exposure_times)
print (" number exp time (sec) exp time (microsceoned) ")
for i in range (1,xrange):
sleep(waitime)
camera.shutter_speed = int(1000000*(exposure_times[i-1]))
print ("{0} {1:.4} {2}".format(i,exposure_times[i-1],((camera.shutter_speed))))
camera.iso = 200
camera.capture('/home/pi/Desktop/img{0:02d}.jpg'.format(i))
img1 = cv2.imread('/home/pi/Desktop/img{0:02d}.jpg'.format(i))
img1 = cv2.resize(img1, (0, 0), None, .25, .25)
img = np.concatenate((img,img1), axis=1)
#cv2.imwrite("/home/pi/Desktop/img2.jpg", img)
cv2.imshow("img", img)
#cv2.imwrite("/home/pi/Desktop/img", img)
sleep(1)
cv2.waitKey(0)
#cv2.destroyAllWindows()
camera.framerate = 20
sleep(.3)
camera.close()
"""
cv2.destroyAllWindows()
for x in range (1,xrange):
if x == 1:
#capture seed picture
camera.shutter_speed = 0
camera.iso = 0
sleep(waitime)
camera.capture('/home/pi/Desktop/testexposure3.jpg')
print ("test2")
img4 = cv2.imread('/home/pi/Desktop/testexposure3.jpg')
cv2.putText(img4,"auto",(5,50), font, 2, (0,255,0), 9, cv2.LINE_AA)
img4 = cv2.resize(img4, (0, 0), None, .25, .25)
else:
print ("test")
camera.shutter_speed = 0
camera.iso = 0
sleep(waitime)
camera.capture('img5.jpg')
img5 = cv2.imread('img5.jpg')
cv2.putText(img5,"auto",(5,50), font, 2, (0,255,0), 9, cv2.LINE_AA)
img5 = cv2.resize(img5, (0, 0), None, .25, .25)
img4 = np.concatenate((img4, img5), axis=1)
print ((x),(y),"{0:10s}".format(str(round(camera.shutter_speed/100000))),(camera.iso))
img3 = np.concatenate((img3, img4), axis=0)
#img3 = cv2.resize(img3, (0, 0), None, .25, .25)
cv2.imshow("image2", img3)
cv2.imwrite("/home/pi/Desktop/img3.jpg", img3)
#Displaying a Matplotlib Scale Image
#Imports a file and displays labels (x,y, title} and resolution tick marks
#requires matplotlib
#Enter input file name
filein = "/home/pi/Desktop/img3.jpg"
image = mpimg.imread("/home/pi/Desktop/img3.jpg")
plt.imshow(image)
#if you want title only
#plt.axis ("off")
plt.xlabel('shutter_speed')
plt.ylabel('iso')
plt.title('Public Lab Raspberry Pi Test')
plt.show()
def readImagesAndTimes():
times = np.array([ 1/30.0, 0.25, 2.5, 15.0 ], dtype=np.float32)
filenames = ["img_0.033.jpg", "img_0.25.jpg", "img_2.5.jpg", "img_15.jpg"]
images = []
for filename in filenames:
im = cv2.imread(filename)
images.append(im)
return images, times
if __name__ == '__main__':
# Read images and exposure times
print("Reading images ... ")
images, times = readImagesAndTimes()
"""