@@ -184,42 +184,25 @@ def _load_images_bin(self, input_file):
184184 def _load_images_txt (self , input_file ):
185185 self .images = OrderedDict ()
186186
187- with open (input_file , "r" ) as f :
188- is_camera_description_line = False
189-
190- for line in iter (lambda : f .readline ().strip (), "" ):
191- if not line or line .startswith ("#" ):
192- continue
193-
194- is_camera_description_line = not is_camera_description_line
195-
196- data = line .split ()
197-
198- if is_camera_description_line :
199- read_quat = np .array (list (map (float , data [1 :5 ])))
200- read_pos = np .array (list (map (float , data [5 :8 ])))
201- image_id = int (data [0 ])
202- image = Image (
203- data [- 1 ],
204- int (data [- 2 ]),
205- Quaternion (read_quat ),
206- read_pos ,
207- )
208- else :
209- points_2d_x = [float (x ) for x in data [::3 ]]
210- points_2d_y = [float (y ) for y in data [1 ::3 ]]
211- point3d_ids = [np .uint64 (pid ) for pid in data [2 ::3 ]]
212- image .points2D = np .array ([points_2d_x , points_2d_y ]).T
213- image .point3D_ids = np .array (point3d_ids , dtype = np .uint64 )
214-
215- # automatically remove points without an associated 3D point
216- # mask = (image.point3D_ids != SceneManager.INVALID_POINT3D)
217- # image.points2D = image.points2D[mask]
218- # image.point3D_ids = image.point3D_ids[mask]
219-
220- self .images [image_id ] = image
221- self .name_to_image_id [image .name ] = image_id
222-
187+ with open (input_file , "r" ) as fid :
188+ while True :
189+ line = fid .readline ()
190+ if not line :
191+ break
192+ line = line .strip ()
193+ if len (line ) > 0 and line [0 ] != "#" :
194+ elems = line .split ()
195+ image_id = int (elems [0 ])
196+ qvec = np .array (list (map (float , elems [1 :5 ])))
197+ tvec = np .array (list (map (float , elems [5 :8 ])))
198+ camera_id = int (elems [8 ])
199+ image_name = elems [9 ]
200+ elems = fid .readline ().split ()
201+ xys = np .column_stack ([tuple (map (float , elems [0 ::3 ])), tuple (map (float , elems [1 ::3 ]))])
202+ point3D_ids = np .array (tuple (map (int , elems [2 ::3 ])))
203+ self .images [image_id ] = Image (image_name , camera_id , Quaternion (qvec ), tvec )
204+ self .images [image_id ].points2D = xys
205+ self .images [image_id ].point3D_ids = point3D_ids
223206 self .last_image_id = max (self .last_image_id , image_id )
224207
225208 # ---------------------------------------------------------------------------
@@ -386,7 +369,11 @@ def _save_images_txt(self, output_file):
386369 print >> fid , image .camera_id , image .name
387370
388371 data = np .rec .fromarrays (
389- (image .points2D [:, 0 ], image .points2D [:, 1 ], image .point3D_ids .astype (np .int64 ))
372+ (
373+ image .points2D [:, 0 ],
374+ image .points2D [:, 1 ],
375+ image .point3D_ids .astype (np .int64 ),
376+ )
390377 )
391378 if len (data ) > 0 :
392379 np .savetxt (fid , data , "%.2f %.2f %d" , newline = " " )
@@ -591,7 +578,14 @@ def delete_images(self, image_list):
591578
592579 # camera_list: set of cameras whose points we'd like to keep
593580 # min/max triangulation angle: in degrees
594- def filter_points3D (self , min_track_len = 0 , max_error = np .inf , min_tri_angle = 0 , max_tri_angle = 180 , image_set = set ()):
581+ def filter_points3D (
582+ self ,
583+ min_track_len = 0 ,
584+ max_error = np .inf ,
585+ min_tri_angle = 0 ,
586+ max_tri_angle = 180 ,
587+ image_set = set (),
588+ ):
595589
596590 image_set = set (image_set )
597591
0 commit comments