Beispiel #1
0
        end = timer()
        odm_filterpoint_time = end - start
        
        start = timer()


        lib.odm_mesh_function(submodel_path, max_concurrency)

        end = timer()
        odm_mesh_time = end - start

        start = timer()


        lib.odm_texturing_function(submodel_path)

        end = timer()
        odm_texturing_time = end - start


        print('self processing id done')



        job_queue.join()


        #take all the submodel mesh_path
        #merge them
Beispiel #2
0
def do_task(job_queue):


    while True:
        
        try:
            task = job_queue.get() # returns a map 
            print("task: " + str(task))
            if task['clientid'] == task['nodeid']:
                print('equals self node id')

                response = False
                if task['title'] == 'upload_image':

                    #check if there is a is a submodel folder
                    print('no need to upload for self')



                
                if task['title'] == 'extract_exif':

                    #image path, opensfm_config, node_file_path
                  
                    print('extract exif in self')

                    # file_path
                    print(task['node_file_path'])

                    image_path = os.path.join(task['node_file_path'], 'images')

                    response = lib.sfm_extract_metadata_list_of_images(image_path, task['opensfm_config'], task['node_file_path'], task['imagelist'])

                    print('response in self')
                    print(response)

                elif task['title'] == 'detect_features':

                    print('detect features in task queue in self')
                    # needs images 

                    # current path, ref images, opensfm_config
                    current_path = task['node_file_path']

                    ref_image = os.listdir(current_path + '/images')

                    response = lib.sfm_detect_features(ref_image, current_path  ,task['opensfm_config'], task['imagelist'])
                    
                    
                elif task['title'] == 'feature_matching':
                    print('feature matching')

                    # needs images
                    # image path
                    # list of images 
                    # candidate images
                    # opensfm config


                    response = lib.sfm_feature_matching(task['node_file_path'], task['ref_image'], task['cand_images'], task['opensfm_config'])
                    
                elif task['title'] == 'feature_matching_pairs':

                    print('in task here ' + str(task['pair']))

                    pair = task['pair']

                    #send the pair of feature files

                    feature_0 = 'features/' + pair[0] + '.features.npz'
                    feature_1 = 'features/' + pair[1] + '.features.npz'


                    #response = task['client'].upload(task['filepath'], [feature_0, feature_1])

                    exif_0 = 'exif/' + pair[0] + '.exif'
                    exif_1 = 'exif/' + pair[1] + '.exif'

                    image_list = [pair[0], pair[1]]


                    pairs_matches = lib.sfm_feature_matching_pairs(task['filepath'],image_list,image_list ,task['opensfm_config'])
                    
                    filename = pair[0]+'-'+pair[1]


                        # save pair matches in a file 
                        # send it to client

                    opensfm_interface.save_matches(task['filepath'], filename, pairs_matches)

                    #filename =  pair[0]+'-'+pair[1] 
                    matches = opensfm_interface.load_matches(task['filepath'],filename)
                    #print('load matches')
                    #print(matches)
                    task['lock'].acquire()
                    try:
			print('lock acquired')
                        tup = (pair[0], pair[1])
                        task['results'].update(matches)
			print('updated matches')
                    except Exception as e:
                        print(e.message)
                        pass

		
                    
                    task['lock'].release()
		    print('lock release')

                elif task['title'] == 'sfm_create_tracks':
                    # needs images
                    # current path




                    #submodel version

                    print(task['cluster'])

                    sending_match_pairs = {}
                    print(task['results'].keys())
                    print('here')
                    for key, value in task['results'].items():
                        #print(key)
                        if key[0] in task['cluster'] and key[1] in task['cluster']:
                            print('key:' + str(key))
                            sending_match_pairs[key] = value

                    print(len(sending_match_pairs))


                    print(sending_match_pairs)
                    

                    print(os.path.join(task['filepath'], task['submodel_path']))

                    matches_filepath =os.path.join(task['filepath'], task['submodel_path'])

                    # maybe save the results in a results file and send it 
                    submodel_path = task['submodel_path']

                    print(submodel_path)

                    #opensfm_interface.save_matches(matches_filepath, submodel_matches, sending_match_pairs)
                    
                    #matches = opensfm_interface.load_matches(matches_filepath, submodel_matches)

                    #print(matches)

                    response = lib.sfm_create_tracks(submodel_path, task['cluster'],task['opensfm_config'], sending_match_pairs, True, task['filepath'])


                    start = timer()


                    # # need the exifs 

                    lib.sfm_opensfm_reconstruction(submodel_path, opensfm_config, True,task['filepath'] )


                    end = timer()
                    sfm_opensfm_reconstruction_time = end - start

                    start = timer()

                    lib.sfm_undistort_image(submodel_path, opensfm_config, True, task['filepath'])

                    end = timer()
                    sfm_undistort_image_time = end - start


                    start = timer()
                    
                    lib.sfm_export_visual_sfm(submodel_path, opensfm_config ,True, task['filepath'])


                    end = timer()
                    sfm_export_visualsfm_time = end - start


                    start = timer()


                    #test load
                    udata   = opensfm_interface.UndistortedDataSet(task['filepath'], task['opensfm_config'], 'undistorted')


                    for image_name in task['cluster']:
                        try:
                            #print(image_name)
                            ret = udata.load_raw_depthmap(image_name)
                        except Exception as e:
                            print(e.message)
                            print('image name bad ' + str(image_name))
                  




                    


                    
                    lib.sfm_compute_depthmaps(submodel_path, opensfm_config,  True, task['filepath'])


                    end = timer()
                    sfm_compute_depthmaps_time = end - start


                    # split merge here no problem


                    start = timer()

                    max_concurrency = 2


                    #need images

                    # delete from makescene
                    #lib.mve_makescene_function(submodel_path, max_concurrency, True, task['file_path'])



                    end = timer()
                    mve_makescene_function_time = end - start

                    start = timer()

                    #lib.mve_dense_reconstruction(submodel_path ,max_concurrency, True, task['file_path'])

                    end = timer()
                    mve_dense_reconstruction_time = end - start

                    start = timer()

                    #lib.mve_scene2pset_function(submodel_path, max_concurrency)

                    end = timer()
                    mve_mve_scene2pset_time = end - start

                    start = timer()

                    # lib.mve_cleanmesh_function(submodel_path, max_concurrency)

                    end = timer()
                    mve_mve_cleanmesh_time = end - start


                    start = timer()


                    # lib.odm_filterpoints_function(submodel_path, max_concurrency)


                    end = timer()
                    odm_filterpoint_time = end - start
                    
                    start = timer()


                    # lib.odm_mesh_function(submodel_path, max_concurrency)

                    end = timer()
                    odm_mesh_time = end - start


                    print('OpenSfm Reconstruction Total Time: ' + str(sfm_opensfm_reconstruction_time))
                    print('OpenSfm Undistort Image Total Time: ' + str(sfm_undistort_image_time))
                    print('OpenSfm Export Visual Sfm Total Time: ' + str(sfm_export_visualsfm_time))
                    print('OpenSfm Compute DepthMaps Sfm Total Time: ' + str(sfm_compute_depthmaps_time))
                    print('Mve Makescene Sfm Total Time: ' + str(mve_makescene_function_time))
                    print('Mve Dense Reconstruction Sfm Total Time: ' + str(mve_dense_reconstruction_time))
                    print('Mve Scene 2 Pset Sfm Total Time: ' + str(mve_mve_scene2pset_time))
                    print('Mve Cleanmesh Sfm Total Time: ' + str(mve_mve_cleanmesh_time))
                    print('ODM Filterpoints Total Time: ' + str(odm_filterpoint_time))
                    print('ODM Mesh Total Time: ' + str(odm_mesh_time))



                    
                elif task['title'] == 'opensfm_reconstruction':

                    # needs create tracks . csv
                    # return reconstruction.json

                    response = lib.sfm_opensfm_reconstruction(task['node_file_path'], task['opensfm_config'])
                    
                elif task['title'] == 'sfm_undistort_image':

                    response = lib.sfm_undistort_image(task['node_file_path'], task['opensfm_config'])
                    
                    
                elif task['title'] == 'export_visual_sfm':
                    #nvm file
                   
                    response = lib.sfm_export_visual_sfm(task['node_file_path'],task['opensfm_config'])

                elif task['title'] == 'compute_depthmaps':
                   
                   response = lib.sfm_compute_depthmaps(task['node_file_path']. task['opensfm_config'])
                    
                elif task['title'] == 'dense_reconstruction':

                   response = lib.mve_dense_reconstruction(task['node_file_path'])
                    
                    
                elif task['title'] == 'makescene_function':
                   response = lib.mve_makescene_function(task['node_file_path'], task['max_concurreny'])
                    
                elif task['title'] == 'scene2pset':
                    response = lib.mve_scene2pset_function(task['node_file_path'], task['max_concurreny'])
                    
                    
                elif task['title'] == 'cleanmesh':
                   response = lib.mve_cleanmesh_function(task['node_file_path'], task['max_concurreny'])
                    
                elif task['title'] == 'filterpoints':
                   response = lib.odm_filterpoints_function(task['node_file_path'], task['max_concurreny'])
                    
                elif task['title'] == 'mesh':
                   response = lib.odm_mesh_function(task['node_file_path'], task['max_concurreny'])
                                        
                elif task['title'] == 'texturing':
                    response = lib.odm_texturing_function(task['node_file_path'])
                    
            else:

                if task['title'] == 'upload_image':
                    print('upload')
        
                    response = task['client'].upload(task['filepath'], task['list'])
                    print(response)
                elif task['title'] == 'extract_exif':
                    print(str(task))
                    print('extract exif ')
                    response = task['client'].sendTask('exif', task['nodeid'], '/exif')
                    print(response)
                elif task['title'] == 'detect_features':

                    print('detect features in task queue')
                    # needs images 
                    response = task['client'].sendTask('detect_features', task['nodeid'], '/features')
                elif task['title'] == 'feature_matching':
                    print('feature matching')

                    # needs images
                    respone = task['client'].sendTask('feature_matching', task['nodeid'], '/matches')
                    
                elif task['title'] == 'sfm_create_tracks':
                    #needs images

                    print(task['cluster'])

                    sending_match_pairs = {}
                    print(task['results'].keys())
                    print('here')
                    for key, value in task['results'].items():
                        #print(key)
                        if key[0] in task['cluster'] and key[1] in task['cluster']:
                            print('key:' + str(key))
                            sending_match_pairs[key] = value

                    print(len(sending_match_pairs))


                    print(sending_match_pairs)
                    

                    print(os.path.join(task['filepath'], task['submodel_path']))

                    matches_filepath =os.path.join(task['filepath'], task['submodel_path'])

                    # maybe save the results in a results file and send it 
                    submodel_matches = task['submodel_path']

                    print(submodel_matches)

                    opensfm_interface.save_matches(matches_filepath, submodel_matches, sending_match_pairs)
                    
                    #matches = opensfm_interface.load_matches(matches_filepath, submodel_matches)

                    print(matches)

                    

                    

                    print(' upload matches ')
                    feature_matches_response = task['client'].upload(matches_filepath, [submodel_matches+'_matches.pkl.gz'], submodel_file='matches') 


                    print('here after feature matches send')


                    # send features 
                    # send matches
                    feature_list = []
                    for image_name in task['cluster']:
                       feature_0 = 'features/' + image_name + '.features.npz'
                       feature_list.append(feature_0)
                    
                    print(' send features ')
                    response = task['client'].upload(task['filepath'], feature_list, 'feature', task['submodel_path'] )




                    #send images
                    response = task['client'].upload(task['filepath'], task['cluster'], 'images', task['submodel_path'])

                    
                    #send exif
                    response = task['client'].upload(task['filepath'], task['cluster'], 'exif', task['submodel_path'])


                    #send cameras.json
                    response = task['client'].upload(task['filepath'], ['camera_models.json'], 'camera_models', task['submodel_path'] )




                    # 
                    respone = task['client'].sendTask('create_tracks', task['nodeid'], '/', submodel_path=task['submodel_path'], cluster_images = task['cluster'])
                    




                elif task['title'] == 'opensfm_reconstruction':

                    # needs create tracks . csv
                    # return reconstruction.json
                    respone = task['client'].sendTask('opensfm_reconstruction', task['nodeid'], '/')
                    
                elif task['title'] == 'sfm_undistort_image':
                    respone = task['client'].sendTask('undistort_image', task['nodeid'], '/undistorted')
                    
                elif task['title'] == 'export_visual_sfm':
                    #nvm file
                    respone = task['client'].sendTask('export_visual_sfm', task['nodeid'], '/undistorted')
                    
                elif task['title'] == 'compute_depthmaps':
                    respone = task['client'].sendTask('compute_depthmaps', task['nodeid'], '/depthmaps')
                    
                elif task['title'] == 'dense_reconstruction':
                    respone = task['client'].sendTask('dense_reconstrution', task['nodeid'], '/mve')
                    
                elif task['title'] == 'makescene_function':
                    respone = task['client'].sendTask('makescene_function', task['nodeid'], '/mve')
                    
                elif task['title'] == 'scene2pset':
                    respone = task['client'].sendTask('scene2pset', task['nodeid'], '/mve')
                    
                elif task['title'] == 'cleanmesh':
                    respone = task['client'].sendTask('cleanmesh', task['nodeid'], '/mve')
                    
                elif task['title'] == 'filterpoints':
                    respone = task['client'].sendTask('odm_filterpoints', task['nodeid'], '/filterpoints')
                    
                elif task['title'] == 'mesh':
                    respone = task['client'].sendTask('odm_mesh', task['nodeid'], '/mesh')
                    
                elif task['title'] == 'texturing':
                    respone = task['client'].sendTask('odm_texturing', task['nodeid'], '/mvs')
                    
                elif task['title'] == 'feature_matching_pairs':
                    # send over the pair feature files and exif files

                    print('in task here ' + str(task['pair']))

                    pair = task['pair']

                    #send the pair of feature files

                    feature_0 = 'features/' + pair[0] + '.features.npz'
                    feature_1 = 'features/' + pair[1] + '.features.npz'


                    response = task['client'].upload(task['filepath'], [feature_0, feature_1])

                    exif_0 = 'exif/' + pair[0] + '.exif'
                    exif_1 = 'exif/' + pair[1] + '.exif'


                    response = task['client'].upload(task['filepath'], [exif_0, exif_1])

                    response = task['client'].sendTask('feature_match_pairs', task['nodeid'], '/matches', [pair[0], pair[1]])

                    filename =  pair[0]+'-'+pair[1] 
                    matches = opensfm_interface.load_matches(task['filepath'],filename)
                    #print('load matches')
                    #print(matches)
		    print('try lock')
                    task['lock'].acquire()
                    try:
                        tup = (pair[0], pair[1])
                        task['results'].update(matches)
			print('lock acquired and reuslt done for send ')
                    except Exception as e:
                        print(e.message)
                        pass
                   
                    task['lock'].release()
		    print('lock release for send ')
                    
                        


                print('done')

            job_queue.task_done()
        except Exception as e:
            print(e.message)
            print(traceback.print_exc())

            print()
            sys.exit(0)
        except KeyboardInterrupt:
            sys.exit(0)
            photos = load_images_database(images_database_file)

        log.ODM_INFO('Found %s usable images' % len(photos))

        # Create reconstruction object
        reconstruction = types.ODM_Reconstruction(photos)

        lib.odm_mesh_function(opensfm_config, current_path, max_concurrency,
                              reconstruction)

        end = timer()
        odm_mesh_time = end - start

        start = timer()

        lib.odm_texturing_function(current_path)

        end = timer()
        odm_texturing_time = end - start

        import orthophoto
        start = timer()
        orthophoto.process(opensfm_config, current_path, 4, reconstruction)

        end = timer()
        odm_orthophoto_time = end - start
        print('odm_orthophoto' + ' ' + str(odm_orthophoto_time))

        # for each in ref_image:
        #     opensfm_interface.detect(current_path+'features', current_path+each,each ,opensfm_config)