質問編集履歴

2

試したことの追加

2020/06/09 05:47

投稿

runa0202
runa0202

スコア6

test CHANGED
File without changes
test CHANGED
@@ -187,3 +187,125 @@
187
187
  df1 = df[df['isPhoto'] > 0]
188
188
 
189
189
  をfor文の中に入れてみました。
190
+
191
+
192
+
193
+ floatをintに変えてみました。
194
+
195
+ ```import numpy as np
196
+
197
+ import pandas as pd
198
+
199
+ from fractions import Fraction
200
+
201
+ import piexif
202
+
203
+ from PIL import Image
204
+
205
+ import droon1
206
+
207
+
208
+
209
+ df = droon1.df
210
+
211
+ df1 = df[df['isPhoto'] > 0]
212
+
213
+
214
+
215
+ for i in range(2,88+1):
216
+
217
+ num = str(i).zfill(4)
218
+
219
+ fn = 'DJI_'+num+'.JPG'
220
+
221
+ rf = '../Photo/' + fn
222
+
223
+ img = Image.open(rf)
224
+
225
+
226
+
227
+ exif_dict = piexif.load(img.info['exif'])
228
+
229
+
230
+
231
+ exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (df1.iloc[(i)-1][3],1)
232
+
233
+
234
+
235
+ lat = df1.iloc[(i)-1][0]
236
+
237
+ lat_a = int(lat)
238
+
239
+ lat_b = int((lat - lat_a)*60)
240
+
241
+ lat_c = ((lat - lat_a)*60-lat_b)*60
242
+
243
+ lat_c = str(lat_c)
244
+
245
+ lat_c = lat_c.replace('.','')
246
+
247
+ lat_c = lat_c[:6]
248
+
249
+ lat_c = int(lat_c)
250
+
251
+
252
+
253
+ lon = df1.iloc[(i)-1][1]
254
+
255
+ lon_a = int(lon)
256
+
257
+ lon_b = int((lon - lon_a)*60)
258
+
259
+ lon_c = ((lon - lon_a)*60-lon_b)*60
260
+
261
+ lon_c = str(lon_c)
262
+
263
+ lon_c = lon_c.replace('.','')
264
+
265
+ lon_c = lon_c[:6]
266
+
267
+ lon_c = int(lon_c)
268
+
269
+
270
+
271
+ a = np.array(exif_dict['GPS'][2])
272
+
273
+ b = np.array(exif_dict['GPS'][4])
274
+
275
+
276
+
277
+
278
+
279
+ a[0,0] = lat_a
280
+
281
+ a[1,0] = lat_b
282
+
283
+ a[2,0] = lat_c
284
+
285
+
286
+
287
+ b[0,0] = lon_a
288
+
289
+ b[1,0] = lon_b
290
+
291
+ b[2,0] = lon_c
292
+
293
+
294
+
295
+ exif_dict['GPS'][2] = tuple(map(tuple,a))
296
+
297
+ exif_dict['GPS'][4] = tuple(map(tuple,b))
298
+
299
+ exif_bytes = piexif.dump(exif_dict)
300
+
301
+
302
+
303
+ fnn = 'DJI_'+num+'p.JPG'
304
+
305
+ rff = '../Photo/' + fnn
306
+
307
+ img.save(rff, "jpeg",exif=exif_bytes)
308
+
309
+ コード
310
+
311
+ ```

1

エラーの全文を追加しました。

2020/06/09 05:47

投稿

runa0202
runa0202

スコア6

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,65 @@
10
10
 
11
11
  ```
12
12
 
13
+ UnboundLocalError Traceback (most recent call last)
14
+
15
+ ~/Droon/image.py in <module>
16
+
17
+ 43 exif_dict['GPS'][2] = tuple(map(tuple,a))
18
+
19
+ 44 exif_dict['GPS'][4] = tuple(map(tuple,b))
20
+
21
+ ---> 45 exif_bytes = piexif.dump(exif_dict)
22
+
23
+ 46
24
+
25
+ 47 fnn = 'DJI_'+num+'p.JPG'
26
+
27
+
28
+
29
+ /data/kako/anaconda3/lib/python3.7/site-packages/piexif/_dump.py in dump(exif_dict_original)
30
+
31
+ 72 exif_length = 0
32
+
33
+ 73 if gps_is:
34
+
35
+ ---> 74 gps_set = _dict_to_bytes(gps_ifd, "GPS", zeroth_length + exif_length)
36
+
37
+ 75 gps_bytes = b"".join(gps_set)
38
+
39
+ 76 gps_length = len(gps_bytes)
40
+
41
+
42
+
43
+ /data/kako/anaconda3/lib/python3.7/site-packages/piexif/_dump.py in _dict_to_bytes(ifd_dict, ifd, ifd_offset)
44
+
45
+ 335 length_str, value_str, four_bytes_over = _value_to_bytes(raw_value,
46
+
47
+ 336 value_type,
48
+
49
+ --> 337 offset)
50
+
51
+ 338 except ValueError:
52
+
53
+ 339 raise ValueError(
54
+
55
+
56
+
57
+ /data/kako/anaconda3/lib/python3.7/site-packages/piexif/_dump.py in _value_to_bytes(raw_value, value_type, offset)
58
+
59
+ 245 struct.pack(">L", den))
60
+
61
+ 246 value_str = struct.pack(">I", offset)
62
+
63
+ --> 247 four_bytes_over = new_value
64
+
65
+ 248 elif value_type == TYPES.SRational:
66
+
67
+ 249 if isinstance(raw_value[0], numbers.Integral):
68
+
69
+
70
+
13
- local variable 'new_value' referenced before assignment
71
+ UnboundLocalError: local variable 'new_value' referenced before assignment
14
72
 
15
73
  ```
16
74