-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcam_comparison_planning.py
executable file
·190 lines (166 loc) · 7.64 KB
/
cam_comparison_planning.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
#! /usr/bin/env python
#David Shean
#dshean@gmail.com
#3/1/13
#Script to compute resolution and fov for Nikon D800 for variable focal length and range
#Add weight
#Add MicaSense RedEdge
#Add diag fov plot
import sys
import numpy as np
import matplotlib.pyplot as plt
from itertools import cycle
def calcfov(cam, f):
fov = 2*np.arctan2(cam['diag_mm'], (2*f))
#print np.degrees(fov)
return fov
def calcres(cam, alt, fov, offnadir=0):
res = 2*alt*np.tan(fov/2)/cam['diag_px']
#return res/np.cos(np.radians(offnadir))
return res/np.cos(offnadir)
def plotgen(cam, alt_range):
c = next(colorcycler)
linecycler = cycle(lines)
if alt_units == 'ft':
alt_scale = 0.3048
else:
alt_scale = 1.0
for f in cam['f_list']:
fov = calcfov(cam, f)
res_center = calcres(cam, alt_range, fov, offnadir=0)
res_corner = calcres(cam, alt_range, fov, offnadir=fov/2.)
x_gd = np.array(res_center)*cam['x_px']
y_gd = np.array(res_center)*cam['y_px']
#diag_gd = np.array(res_center)*cam['diag_px']
diag_gd = np.sqrt(x_gd**2 + y_gd**2)
gd_area = x_gd * y_gd
#ls = next(linecycler)
ls = '-'
plt.figure(1)
plt.plot(alt_range/alt_scale, res_center*100, color=c, ls=ls, label='%s, %0.1f mm (%0.1f$^\circ$, %0.1f mm eq) Center' % (cam['name'],f,np.degrees(fov),f*cam['crop_factor']))
#plt.plot(alt_range/alt_scale, res_corner*100, color=c, ls='--', label='%s, %0.1f mm (%0.1f$^\circ$, %0.1f mm eq) Corner' % (cam['name'],f,np.degrees(fov),f*cam['crop_factor']))
plt.figure(2)
plt.plot(alt_range/alt_scale, x_gd, color=c, ls=ls, label='%s, %0.1f mm (%0.1f$^\circ$, %0.1f mm eq)' % (cam['name'],f,np.degrees(fov),f*cam['crop_factor']))
plt.figure(3)
plt.plot(alt_range/alt_scale, y_gd, color=c, ls=ls, label='%s, %0.1f mm (%0.1f$^\circ$, %0.1f mm eq)' % (cam['name'],f,np.degrees(fov),f*cam['crop_factor']))
plt.figure(4)
plt.plot(alt_range/alt_scale, diag_gd, color=c, ls=ls, label='%s, %0.1f mm (%0.1f$^\circ$, %0.1f mm eq)' % (cam['name'],f,np.degrees(fov),f*cam['crop_factor']))
plt.figure(5)
plt.plot(alt_range/alt_scale, gd_area, color=c, ls=ls, label='%s, %0.1f mm (%0.1f$^\circ$, %0.1f mm eq)' % (cam['name'],f,np.degrees(fov),f*cam['crop_factor']))
offnadir = 0
#Altitude range in feet
#alt_units = 'ft'
#alt_list = np.arange(0, 401, 10)
#if alt_units == 'ft':
# alt_list *= 0.3048
#Altitude range in meters
alt_units = 'm'
alt_list = np.arange(0, 122, 4)
d800 = {'name':'D800', 'weight':1193, 'x_mm':35.9, 'y_mm':24.0, 'x_px':7360, 'y_px':4912, 'f_list': (50.0,) }
#NEX5 = {'name':'NEX-5', 'x_mm':23.4, 'y_mm':15.6, 'x_px':4912, 'y_px':3264, 'f_list': (16.0, 20.0) }
NEX5 = {'name':'NEX-5', 'weight':338, 'x_mm':23.4, 'y_mm':15.6, 'x_px':4912, 'y_px':3264, 'f_list': (20.0,) }
#a5000 = {'name':'a5000', 'weight':338, 'x_mm':23.4, 'y_mm':15.6, 'x_px':5456, 'y_px':3632, 'f_list': (16.0, 20.0) }
a5000 = {'name':'a5000', 'weight':338, 'x_mm':23.4, 'y_mm':15.6, 'x_px':5456, 'y_px':3632, 'f_list': (20.0,) }
#rx100 = {'name':'rx100_III', 'x_mm':13.2, 'y_mm':8.8, 'x_px':5472, 'y_px':3648, 'f_list': (8.8, 25.7) }
rx100 = {'name':'RX100_III', 'weight':287, 'x_mm':13.2, 'y_mm':8.8, 'x_px':5472, 'y_px':3648, 'f_list': (8.8,) }
#gx1 = {'name':'GX1', 'weight':418, 'x_mm':17.3, 'y_mm':13.0, 'x_px':4592, 'y_px':3448, 'f_list': (14.0, 20.0) }
gx1 = {'name':'GX1', 'weight':418, 'x_mm':17.3, 'y_mm':13.0, 'x_px':4592, 'y_px':3448, 'f_list': (20.0,) }
s100 = {'name':'s100', 'weight':173, 'x_mm':7.6, 'y_mm':5.7, 'x_px':4000, 'y_px':3000, 'f_list': (5.2,) }
gopro12 = {'name':'gopro_12MP', 'weight':74, 'x_mm':6.17, 'y_mm':4.55, 'x_px':4000, 'y_px':3000, 'f_list': (2.77,) }
gopro7 = {'name':'gopro_7MP', 'weight':74, 'x_mm':4.6275, 'y_mm':3.4125, 'x_px':3000, 'y_px':2250, 'f_list': (2.77,) }
#the 'x_mm' tag was inverted from 8 cm/px resolution at 120 m altitude
#alt=120
#x_px=1280
#x_gd=0.08
#f=4.2
#x_mm=2*f*np.tan(np.arctan(0.5*(x_px*x_gd)/alt))
#y_mm=2*f*np.tan(np.arctan(0.5*(y_px*x_gd)/alt))
micasense = {'name':'rededge', 'weight':150, 'x_mm':3.584, 'y_mm':2.688, 'x_px':1280, 'y_px':960, 'f_list':(4.2,)}
cams = [micasense, d800, NEX5, a5000, gx1, rx100, s100, gopro12, gopro7]
#cams = [d800, NEX5, s100, gopro12, gopro7]
cams = cams[::-1]
lines = ["-","--","-.",":"]
colors = ['r','b','g','orange','y','c','m','k','0.5']
colors = colors[::-1]
colorcycler = cycle(colors)
diag_px_35mm = 43.3
for cam in cams:
cam['diag_mm'] = np.sqrt(cam['x_mm']**2 + cam['y_mm']**2)
cam['diag_px'] = np.sqrt(cam['x_px']**2 + cam['y_px']**2)
cam['pitch'] = cam['x_mm']/cam['x_px']
cam['crop_factor'] = diag_px_35mm/cam['diag_mm']
plt.figure(0)
plt.title('Camera Pixel Pitch (sensor pixel size)')
plt.scatter(range(0,len(cams)), [(cam['pitch']*1000.0)**2 for cam in cams], color=colors)
plt.xticks(range(0,len(cams)), [cam['name'] for cam in cams])
plt.ylabel(r'Pixel Area $(\mu m^2)$')
plt.gca().tick_params(axis='x', labelsize=8)
plt.savefig('pixel_pitch.pdf')
for cam in cams:
plotgen(cam, alt_list)
plt.figure(1)
plt.grid(b=True, which='major', color='k', linestyle=':', linewidth=0.2)
#plt.grid(b=True, which='minor', color='k', linestyle=':', linewidth=0.2)
plt.gca().minorticks_on()
plt.title('Camera Altitude vs. Ground Sample Distance (best possible pixel res)')
plt.xlabel('Altitude (%s)' % alt_units)
plt.ylabel('GSD (cm)')
plt.legend(loc=2,prop={'size':8})
plt.figure(2)
plt.grid(b=True, which='major', color='k', linestyle=':', linewidth=0.2)
#plt.grid(b=True, which='minor', color='k', linestyle=':', linewidth=0.2)
plt.gca().minorticks_on()
plt.title('Camera Altitude vs. Image Width (on ground)')
plt.xlabel('Altitude (%s)' % alt_units)
plt.ylabel('X field of view (m)')
plt.legend(loc=2,prop={'size':8})
plt.figure(3)
plt.grid(b=True, which='major', color='k', linestyle=':', linewidth=0.2)
#plt.grid(b=True, which='minor', color='k', linestyle=':', linewidth=0.2)
plt.gca().minorticks_on()
plt.title('Camera Altitude vs. Image Height (on ground)')
plt.xlabel('Altitude (%s)' % alt_units)
plt.ylabel('Y field of view (m)')
plt.legend(loc=2,prop={'size':8})
plt.figure(4)
plt.grid(b=True, which='major', color='k', linestyle=':', linewidth=0.2)
#plt.grid(b=True, which='minor', color='k', linestyle=':', linewidth=0.2)
plt.gca().minorticks_on()
plt.title('Camera Altitude vs. Image Diag (on ground)')
plt.xlabel('Altitude (%s)' % alt_units)
plt.ylabel('Diag field of view (m)')
plt.legend(loc=2,prop={'size':8})
plt.figure(5)
plt.grid(b=True, which='major', color='k', linestyle=':', linewidth=0.2)
#plt.grid(b=True, which='minor', color='k', linestyle=':', linewidth=0.2)
plt.gca().minorticks_on()
plt.title('Camera Altitude vs. Image Area (on ground)')
plt.xlabel('Altitude (%s)' % alt_units)
plt.ylabel('Image area (m^2)')
plt.legend(loc=2,prop={'size':8})
plt.figure(6)
plt.title('Camera Weight (inc. lens+battery+card)')
plt.scatter(range(0,len(cams)), [cam['weight'] for cam in cams], color=colors)
plt.xticks(range(0,len(cams)), [cam['name'] for cam in cams])
plt.ylabel('Mass (g)')
plt.gca().tick_params(axis='x', labelsize=8)
plt.savefig('cam_weight.pdf')
plt.figure(7)
plt.title('Camera Pixel Area vs. Weight')
plt.scatter(range(0,len(cams)), [(cam['pitch']*1000.0)**2/cam['weight'] for cam in cams], color=colors)
plt.xticks(range(0,len(cams)), [cam['name'] for cam in cams])
plt.ylabel(r'Pixel Area $(\mu m^2)$ per g')
plt.gca().tick_params(axis='x', labelsize=8)
plt.savefig('pitch_weight_ratio.pdf')
plt.figure(1)
plt.savefig('alt_vs_gsd.pdf')
plt.figure(2)
plt.savefig('alt_vs_xfov.pdf')
plt.figure(3)
plt.savefig('alt_vs_yfov.pdf')
plt.figure(4)
plt.savefig('alt_vs_dfov.pdf')
plt.figure(5)
plt.savefig('alt_vs_area.pdf')
#plt.show()
sys.exit()