/
dataset.py
717 lines (575 loc) · 26.9 KB
/
dataset.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
# -*- coding: utf-8 -*-
import os
import json
import logging
import pickle
import gzip
import cv2
import numpy as np
import networkx as nx
import six
from opensfm import io
from opensfm import config
from opensfm import context
from opensfm import geo
logger = logging.getLogger(__name__)
class DataSet(object):
"""Accessors to the main input and output data.
Data include input images, masks, and segmentation as well
temporary data such as features and matches and the final
reconstructions.
All data is stored inside a single folder with a specific subfolder
structure.
It is possible to store data remotely or in different formats
by subclassing this class and overloading its methods.
"""
def __init__(self, data_path):
"""Init dataset associated to a folder."""
self.data_path = data_path
self._load_config()
self._load_image_list()
self._load_mask_list()
def _load_config(self):
config_file = os.path.join(self.data_path, 'config.yaml')
self.config = config.load_config(config_file)
def _load_image_list(self):
"""Load image list from image_list.txt or list image/ folder."""
image_list_file = os.path.join(self.data_path, 'image_list.txt')
if os.path.isfile(image_list_file):
with io.open_rt(image_list_file) as fin:
lines = fin.read().splitlines()
self._set_image_list(lines)
else:
self._set_image_path(os.path.join(self.data_path, 'images'))
def images(self):
"""List of file names of all images in the dataset."""
return self.image_list
def _image_file(self, image):
"""Path to the image file."""
return self.image_files[image]
def open_image_file(self, image):
"""Open image file and return file object."""
return open(self._image_file(image), 'rb')
def load_image(self, image):
"""Load image pixels as numpy array.
The array is 3D, indexed by y-coord, x-coord, channel.
The channels are in RGB order.
"""
return io.imread(self._image_file(image))
def _undistorted_image_path(self):
return os.path.join(self.data_path, 'undistorted')
def _undistorted_image_file(self, image):
"""Path of undistorted version of an image."""
return os.path.join(self._undistorted_image_path(), image + '.jpg')
def load_undistorted_image(self, image):
"""Load undistorted image pixels as a numpy array."""
return io.imread(self._undistorted_image_file(image))
def save_undistorted_image(self, image, array):
io.mkdir_p(self._undistorted_image_path())
cv2.imwrite(self._undistorted_image_file(image), array[:, :, ::-1])
def _load_mask_list(self):
"""Load mask list from mask_list.txt or list masks/ folder."""
mask_list_file = os.path.join(self.data_path, 'mask_list.txt')
if os.path.isfile(mask_list_file):
with io.open_rt(mask_list_file) as fin:
lines = fin.read().splitlines()
self._set_mask_list(lines)
else:
self._set_mask_path(os.path.join(self.data_path, 'masks'))
def load_mask(self, image):
"""Load image mask if it exists, otherwise return None."""
if image in self.mask_files:
mask_path = self.mask_files[image]
mask = cv2.imread(mask_path)
if mask is None:
raise IOError("Unable to load mask for image {} "
"from file {}".format(image, mask_path))
if len(mask.shape) == 3:
mask = mask.max(axis=2)
else:
mask = None
return mask
def _undistorted_mask_path(self):
return os.path.join(self.data_path, 'undistorted_masks')
def _undistorted_mask_file(self, image):
"""Path of undistorted version of a mask."""
return os.path.join(self._undistorted_mask_path(), image + '.png')
def undistorted_mask_exists(self, image):
"""Check if the undistorted mask file exists."""
return os.path.isfile(self._undistorted_mask_file(image))
def load_undistorted_mask(self, image):
"""Load undistorted mask pixels as a numpy array."""
return io.imread(self._undistorted_mask_file(image))
def save_undistorted_mask(self, image, array):
"""Save the undistorted image mask."""
io.mkdir_p(self._undistorted_mask_path())
cv2.imwrite(self._undistorted_mask_file(image), array)
def _segmentation_path(self):
return os.path.join(self.data_path, 'segmentations')
def _segmentation_file(self, image):
return os.path.join(self._segmentation_path(), image + '.png')
def load_segmentation(self, image):
"""Load image segmentation if it exitsts, otherwise return None."""
segmentation_file = self._segmentation_file(image)
if os.path.isfile(segmentation_file):
segmentation = cv2.imread(segmentation_file)
if len(segmentation.shape) == 3:
segmentation = segmentation.max(axis=2)
else:
segmentation = None
return segmentation
def _undistorted_segmentation_path(self):
return os.path.join(self.data_path, 'undistorted_segmentations')
def _undistorted_segmentation_file(self, image):
"""Path of undistorted version of a segmentation."""
return os.path.join(self._undistorted_segmentation_path(), image + '.png')
def undistorted_segmentation_exists(self, image):
"""Check if the undistorted segmentation file exists."""
return os.path.isfile(self._undistorted_segmentation_file(image))
def load_undistorted_segmentation(self, image):
"""Load an undistorted image segmentation."""
segmentation = cv2.imread(self._undistorted_segmentation_file(image))
if len(segmentation.shape) == 3:
segmentation = segmentation.max(axis=2)
return segmentation
def save_undistorted_segmentation(self, image, array):
"""Save the undistorted image segmentation."""
io.mkdir_p(self._undistorted_segmentation_path())
cv2.imwrite(self._undistorted_segmentation_file(image), array)
def segmentation_ignore_values(self, image):
"""List of label values to ignore.
Pixels with this labels values will be masked out and won't be
processed when extracting features or computing depthmaps.
"""
return self.config.get('segmentation_ignore_values', [])
def load_segmentation_mask(self, image):
"""Build a mask from segmentation ignore values.
The mask is non-zero only for pixels with segmentation
labels not in segmentation_ignore_values.
"""
ignore_values = self.segmentation_ignore_values(image)
if not ignore_values:
return None
segmentation = self.load_segmentation(image)
if segmentation is None:
return None
return self._mask_from_segmentation(segmentation, ignore_values)
def load_undistorted_segmentation_mask(self, image):
"""Build a mask from the undistorted segmentation.
The mask is non-zero only for pixels with segmentation
labels not in segmentation_ignore_values.
"""
ignore_values = self.segmentation_ignore_values(image)
if not ignore_values:
return None
segmentation = self.load_undistorted_segmentation(image)
if segmentation is None:
return None
return self._mask_from_segmentation(segmentation, ignore_values)
def _mask_from_segmentation(self, segmentation, ignore_values):
mask = np.ones(segmentation.shape, dtype=np.uint8)
for value in ignore_values:
mask &= (segmentation != value)
return mask
def load_combined_mask(self, image):
"""Combine binary mask with segmentation mask.
Return a mask that is non-zero only where the binary
mask and the segmentation mask are non-zero.
"""
mask = self.load_mask(image)
smask = self.load_segmentation_mask(image)
return self._combine_masks(mask, smask)
def load_undistorted_combined_mask(self, image):
"""Combine undistorted binary mask with segmentation mask.
Return a mask that is non-zero only where the binary
mask and the segmentation mask are non-zero.
"""
mask = None
if self.undistorted_mask_exists(image):
mask = self.load_undistorted_mask(image)
smask = None
if self.undistorted_segmentation_exists(image):
smask = self.load_undistorted_segmentation_mask(image)
return self._combine_masks(mask, smask)
def _combine_masks(self, mask, smask):
if mask is None:
if smask is None:
return None
else:
return smask
else:
if smask is None:
return mask
else:
return mask & smask
def _depthmap_path(self):
return os.path.join(self.data_path, 'depthmaps')
def _depthmap_file(self, image, suffix):
"""Path to the depthmap file"""
return os.path.join(self._depthmap_path(), image + '.' + suffix)
def raw_depthmap_exists(self, image):
return os.path.isfile(self._depthmap_file(image, 'raw.npz'))
def save_raw_depthmap(self, image, depth, plane, score, nghbr, nghbrs):
io.mkdir_p(self._depthmap_path())
filepath = self._depthmap_file(image, 'raw.npz')
np.savez_compressed(filepath, depth=depth, plane=plane, score=score, nghbr=nghbr, nghbrs=nghbrs)
def load_raw_depthmap(self, image):
o = np.load(self._depthmap_file(image, 'raw.npz'))
return o['depth'], o['plane'], o['score'], o['nghbr'], o['nghbrs']
def clean_depthmap_exists(self, image):
return os.path.isfile(self._depthmap_file(image, 'clean.npz'))
def save_clean_depthmap(self, image, depth, plane, score):
io.mkdir_p(self._depthmap_path())
filepath = self._depthmap_file(image, 'clean.npz')
np.savez_compressed(filepath, depth=depth, plane=plane, score=score)
def load_clean_depthmap(self, image):
o = np.load(self._depthmap_file(image, 'clean.npz'))
return o['depth'], o['plane'], o['score']
def pruned_depthmap_exists(self, image):
return os.path.isfile(self._depthmap_file(image, 'pruned.npz'))
def save_pruned_depthmap(self, image, points, normals, colors, labels):
io.mkdir_p(self._depthmap_path())
filepath = self._depthmap_file(image, 'pruned.npz')
np.savez_compressed(filepath,
points=points, normals=normals,
colors=colors, labels=labels)
def load_pruned_depthmap(self, image):
o = np.load(self._depthmap_file(image, 'pruned.npz'))
return o['points'], o['normals'], o['colors'], o['labels']
def _is_image_file(self, filename):
extensions = {'jpg', 'jpeg', 'png', 'tif', 'tiff', 'pgm', 'pnm', 'gif'}
return filename.split('.')[-1].lower() in extensions
def _set_image_path(self, path):
"""Set image path and find all images in there"""
self.image_list = []
self.image_files = {}
if os.path.exists(path):
for name in os.listdir(path):
name = six.text_type(name)
if self._is_image_file(name):
self.image_list.append(name)
self.image_files[name] = os.path.join(path, name)
def _set_image_list(self, image_list):
self.image_list = []
self.image_files = {}
for line in image_list:
path = os.path.join(self.data_path, line)
name = os.path.basename(path)
self.image_list.append(name)
self.image_files[name] = path
def _set_mask_path(self, path):
"""Set mask path and find all masks in there"""
self.mask_files = {}
for image in self.images():
filepath = os.path.join(path, image + '.png')
if os.path.isfile(filepath):
self.mask_files[image] = filepath
def _set_mask_list(self, mask_list_lines):
self.mask_files = {}
for line in mask_list_lines:
image, relpath = line.split(None, 1)
path = os.path.join(self.data_path, relpath.strip())
self.mask_files[image.strip()] = path
def _exif_path(self):
"""Return path of extracted exif directory"""
return os.path.join(self.data_path, 'exif')
def _exif_file(self, image):
"""
Return path of exif information for given image
:param image: Image name, with extension (i.e. 123.jpg)
"""
return os.path.join(self._exif_path(), image + '.exif')
def load_exif(self, image):
"""
Return extracted exif information, as dictionary, usually with fields:
================ ===== ===================================
Field Type Description
================ ===== ===================================
width int Width of image, in pixels
height int Height of image, in pixels
focal_prior float Focal length (real) / sensor width
================ ===== ===================================
:param image: Image name, with extension (i.e. 123.jpg)
"""
with io.open_rt(self._exif_file(image)) as fin:
return json.load(fin)
def save_exif(self, image, data):
io.mkdir_p(self._exif_path())
with io.open_wt(self._exif_file(image)) as fout:
io.json_dump(data, fout)
def exif_exists(self, image):
return os.path.isfile(self._exif_file(image))
def feature_type(self):
"""Return the type of local features (e.g. AKAZE, SURF, SIFT)"""
feature_name = self.config['feature_type'].lower()
if self.config['feature_root']:
feature_name = 'root_' + feature_name
return feature_name
def _feature_path(self):
"""Return path of feature descriptors and FLANN indices directory"""
return os.path.join(self.data_path, "features")
def _feature_file(self, image):
"""
Return path of feature file for specified image
:param image: Image name, with extension (i.e. 123.jpg)
"""
return os.path.join(self._feature_path(), image + '.npz')
def _save_features(self, filepath, image, points, descriptors, colors=None):
io.mkdir_p(self._feature_path())
feature_type = self.config['feature_type']
if ((feature_type == 'AKAZE' and self.config['akaze_descriptor'] in ['MLDB_UPRIGHT', 'MLDB'])
or (feature_type == 'HAHOG' and self.config['hahog_normalize_to_uchar'])
or (feature_type == 'ORB')):
feature_data_type = np.uint8
else:
feature_data_type = np.float32
np.savez_compressed(filepath,
points=points.astype(np.float32),
descriptors=descriptors.astype(feature_data_type),
colors=colors)
def features_exist(self, image):
return os.path.isfile(self._feature_file(image))
def load_features(self, image):
feature_type = self.config['feature_type']
s = np.load(self._feature_file(image))
if feature_type == 'HAHOG' and self.config['hahog_normalize_to_uchar']:
descriptors = s['descriptors'].astype(np.float32)
else:
descriptors = s['descriptors']
return s['points'], descriptors, s['colors'].astype(float)
def save_features(self, image, points, descriptors, colors):
self._save_features(self._feature_file(image), image, points, descriptors, colors)
def feature_index_exists(self, image):
return os.path.isfile(self._feature_index_file(image))
def _feature_index_file(self, image):
"""
Return path of FLANN index file for specified image
:param image: Image name, with extension (i.e. 123.jpg)
"""
return os.path.join(self._feature_path(), image + '.flann')
def load_feature_index(self, image, features):
index = context.flann_Index()
index.load(features, self._feature_index_file(image))
return index
def save_feature_index(self, image, index):
index.save(self._feature_index_file(image))
def _preemptive_features_file(self, image):
"""
Return path of preemptive feature file (a short list of the full feature file)
for specified image
:param image: Image name, with extension (i.e. 123.jpg)
"""
return os.path.join(self._feature_path(), image + '_preemptive' + '.npz')
def load_preemtive_features(self, image):
s = np.load(self._preemptive_features_file(image))
return s['points'], s['descriptors']
def save_preemptive_features(self, image, points, descriptors):
self._save_features(self._preemptive_features_file(image), image, points, descriptors)
def _matches_path(self):
"""Return path of matches directory"""
return os.path.join(self.data_path, 'matches')
def _matches_file(self, image):
"""File for matches for an image"""
return os.path.join(self._matches_path(), '{}_matches.pkl.gz'.format(image))
def matches_exists(self, image):
return os.path.isfile(self._matches_file(image))
def load_matches(self, image):
with gzip.open(self._matches_file(image), 'rb') as fin:
matches = pickle.load(fin)
return matches
def save_matches(self, image, matches):
io.mkdir_p(self._matches_path())
with gzip.open(self._matches_file(image), 'wb') as fout:
pickle.dump(matches, fout)
def find_matches(self, im1, im2):
if self.matches_exists(im1):
im1_matches = self.load_matches(im1)
if im2 in im1_matches:
return im1_matches[im2]
if self.matches_exists(im2):
im2_matches = self.load_matches(im2)
if im1 in im2_matches:
if len(im2_matches[im1]):
return im2_matches[im1][:, [1, 0]]
return []
def _tracks_graph_file(self, filename=None):
"""Return path of tracks file"""
return os.path.join(self.data_path, filename or 'tracks.csv')
def load_tracks_graph(self, filename=None):
"""Return graph (networkx data structure) of tracks"""
with io.open_rt(self._tracks_graph_file(filename)) as fin:
return load_tracks_graph(fin)
def save_tracks_graph(self, graph, filename=None):
with io.open_wt(self._tracks_graph_file(filename)) as fout:
save_tracks_graph(fout, graph)
def load_undistorted_tracks_graph(self):
return self.load_tracks_graph('undistorted_tracks.csv')
def save_undistorted_tracks_graph(self, graph):
return self.save_tracks_graph(graph, 'undistorted_tracks.csv')
def _reconstruction_file(self, filename):
"""Return path of reconstruction file"""
return os.path.join(self.data_path, filename or 'reconstruction.json')
def reconstruction_exists(self, filename=None):
return os.path.isfile(self._reconstruction_file(filename))
def load_reconstruction(self, filename=None):
with io.open_rt(self._reconstruction_file(filename)) as fin:
reconstructions = io.reconstructions_from_json(io.json_load(fin))
return reconstructions
def save_reconstruction(self, reconstruction, filename=None, minify=False):
with io.open_wt(self._reconstruction_file(filename)) as fout:
io.json_dump(io.reconstructions_to_json(reconstruction), fout, minify)
def load_undistorted_reconstruction(self):
return self.load_reconstruction(
filename='undistorted_reconstruction.json')
def save_undistorted_reconstruction(self, reconstruction):
return self.save_reconstruction(
reconstruction, filename='undistorted_reconstruction.json')
def _reference_lla_path(self):
return os.path.join(self.data_path, 'reference_lla.json')
def invent_reference_lla(self, images=None):
lat, lon, alt = 0.0, 0.0, 0.0
wlat, wlon, walt = 0.0, 0.0, 0.0
if images is None: images = self.images()
for image in images:
d = self.load_exif(image)
if 'gps' in d and 'latitude' in d['gps'] and 'longitude' in d['gps']:
w = 1.0 / max(0.01, d['gps'].get('dop', 15))
lat += w * d['gps']['latitude']
lon += w * d['gps']['longitude']
wlat += w
wlon += w
if 'altitude' in d['gps']:
alt += w * d['gps']['altitude']
walt += w
if wlat: lat /= wlat
if wlon: lon /= wlon
if walt: alt /= walt
reference = {'latitude': lat, 'longitude': lon, 'altitude': 0} # Set altitude manually.
self.save_reference_lla(reference)
return reference
def save_reference_lla(self, reference):
with io.open_wt(self._reference_lla_path()) as fout:
io.json_dump(reference, fout)
def load_reference_lla(self):
with io.open_rt(self._reference_lla_path()) as fin:
return io.json_load(fin)
def load_reference(self):
"""Load reference as a topocentric converter."""
lla = self.load_reference_lla()
return geo.TopocentricConverter(
lla['latitude'], lla['longitude'], lla['altitude'])
def reference_lla_exists(self):
return os.path.isfile(self._reference_lla_path())
def _camera_models_file(self):
"""Return path of camera model file"""
return os.path.join(self.data_path, 'camera_models.json')
def load_camera_models(self):
"""Return camera models data"""
with io.open_rt(self._camera_models_file()) as fin:
obj = json.load(fin)
return io.cameras_from_json(obj)
def save_camera_models(self, camera_models):
"""Save camera models data"""
with io.open_wt(self._camera_models_file()) as fout:
obj = io.cameras_to_json(camera_models)
io.json_dump(obj, fout)
def _camera_models_overrides_file(self):
"""Path to the camera model overrides file."""
return os.path.join(self.data_path, 'camera_models_overrides.json')
def camera_models_overrides_exists(self):
"""Check if camera overrides file exists."""
return os.path.isfile(self._camera_models_overrides_file())
def load_camera_models_overrides(self):
"""Load camera models overrides data."""
with io.open_rt(self._camera_models_overrides_file()) as fin:
obj = json.load(fin)
return io.cameras_from_json(obj)
def save_camera_models_overrides(self, camera_models):
"""Save camera models overrides data"""
with io.open_wt(self._camera_models_overrides_file()) as fout:
obj = io.cameras_to_json(camera_models)
io.json_dump(obj, fout)
def _exif_overrides_file(self):
"""Path to the EXIF overrides file."""
return os.path.join(self.data_path, 'exif_overrides.json')
def exif_overrides_exists(self):
"""Check if EXIF overrides file exists."""
return os.path.isfile(self._exif_overrides_file())
def load_exif_overrides(self):
"""Load EXIF overrides data."""
with io.open_rt(self._exif_overrides_file()) as fin:
return json.load(fin)
def profile_log(self):
"Filename where to write timings."
return os.path.join(self.data_path, 'profile.log')
def _report_path(self):
return os.path.join(self.data_path, 'reports')
def load_report(self, path):
"""Load a report file as a string."""
with io.open_rt(os.path.join(self._report_path(), path)) as fin:
return fin.read()
def save_report(self, report_str, path):
"""Save report string to a file."""
filepath = os.path.join(self._report_path(), path)
io.mkdir_p(os.path.dirname(filepath))
with io.open_wt(filepath) as fout:
return fout.write(report_str)
def _navigation_graph_file(self):
"Return the path of the navigation graph."
return os.path.join(self.data_path, 'navigation_graph.json')
def save_navigation_graph(self, navigation_graphs):
with io.open_wt(self._navigation_graph_file()) as fout:
io.json_dump(navigation_graphs, fout)
def _ply_file(self, filename):
return os.path.join(self.data_path, filename or 'reconstruction.ply')
def save_ply(self, reconstruction, filename=None,
no_cameras=False, no_points=False):
"""Save a reconstruction in PLY format."""
ply = io.reconstruction_to_ply(reconstruction, no_cameras, no_points)
with io.open_wt(self._ply_file(filename)) as fout:
fout.write(ply)
def _ground_control_points_file(self):
return os.path.join(self.data_path, 'gcp_list.txt')
def ground_control_points_exist(self):
return os.path.isfile(self._ground_control_points_file())
def load_ground_control_points(self):
"""Load ground control points.
It uses reference_lla to convert the coordinates
to topocentric reference frame.
"""
exif = {image: self.load_exif(image) for image in self.images()}
reference = self.load_reference()
with io.open_rt(self._ground_control_points_file()) as fin:
return io.read_ground_control_points_list(fin, reference, exif)
def image_as_array(self, image):
logger.warning("image_as_array() is deprecated. Use load_image() instead.")
return self.load_image(image)
def undistorted_image_as_array(self, image):
logger.warning("undistorted_image_as_array() is deprecated. "
"Use load_undistorted_image() instead.")
return self.load_undistorted_image(image)
def mask_as_array(self, image):
logger.warning("mask_as_array() is deprecated. Use load_mask() instead.")
return self.load_mask(image)
def load_tracks_graph(fileobj):
g = nx.Graph()
for line in fileobj:
image, track, observation, x, y, R, G, B = line.split('\t')
g.add_node(image, bipartite=0)
g.add_node(track, bipartite=1)
g.add_edge(
image, track,
feature=(float(x), float(y)),
feature_id=int(observation),
feature_color=(float(R), float(G), float(B)))
return g
def save_tracks_graph(fileobj, graph):
for node, data in graph.nodes(data=True):
if data['bipartite'] == 0:
image = node
for track, data in graph[image].items():
x, y = data['feature']
fid = data['feature_id']
r, g, b = data['feature_color']
fileobj.write(u'%s\t%s\t%d\t%g\t%g\t%g\t%g\t%g\n' % (
str(image), str(track), fid, x, y, r, g, b))