Пример #1
0
def add_network_tasks_to_queue(chunks, tasks):
    """Adds network tasks to queue."""
    network_tasks = []
    network_client = PhotoScan.NetworkClient()
    network_client.connect(SERVER_IP)
    for task_parameters in tasks:
        new_network_task = PhotoScan.NetworkTask()
        for chunk in chunks:
            new_network_task.frames.append((chunk.key, 0))
            new_network_task.name = task_parameters['name']
            for key in task_parameters:
                if key != 'name':
                    new_network_task.params[key] = task_parameters[key]
        network_tasks.append(new_network_task)
    network_save = PhotoScan.app.document.path.replace(SHARED_ROOT, '')
    batch_id = network_client.createBatch(network_save, network_tasks)
    network_client.resumeBatch(batch_id)
Пример #2
0
def runNetwork(project_path,
               argstring,
               tname='RunScript',
               PSscript='scripts/reef3D/PyToolbox/PSmodel.py'):
    ''''
    Run a task over the network
    '''

    client = PhotoScan.NetworkClient()

    task1 = PhotoScan.NetworkTask()
    task1.name = tname
    task1.params['path'] = PSscript  #path to the script to be executed
    task1.params[
        'args'] = argstring  #string of the arguments with space as separator
    client.connect('agisoft-qmgr.aims.gov.au')  #server ip
    batch_id = client.createBatch(proj_path, [task1])
    client.resumeBatch(batch_id)
    print("Job started...")
Пример #3
0
def runNetwork(proj_path,
               argstring,
               tname='RunScript',
               PSscript='scripts/reef3D/PyToolbox/PSmodel.py'):
    ''''
    Run a task over the network
    '''

    client = PhotoScan.NetworkClient()
    # VIDEO_FILENAME=argstring.split(" ")[2]
    # VIDEO_FILENAME=VIDEO_FILENAME.strip('"')
    # doc = PhotoScan.Document(os.path.join(proj_dir,VIDEO_FILENAME + '.psx'))
    # doc.open("...")
    task1 = PhotoScan.NetworkTask()
    task1.name = tname
    task1.params['path'] = PSscript  #path to the script to be executed
    task1.params[
        'args'] = argstring  #string of the arguments with space as separator
    client.connect('agisoft-qmgr.aims.gov.au')  #server ip
    batch_id = client.createBatch(proj_path, [task1])
    client.resumeBatch(batch_id)
    client.disconnect()
    print("Job started...")
Пример #4
0
    def export_ortho(
        self, proc_type
    ):  # универсальная процедура экспорта для локлаьной и для сетевой обработки
        #global chunk
        ''' ЭТО ПРОВЕРКА ДЛЯ ПОСТРОЕНИЯ ОРТО ПЕРЕД РАБОТОЙ В ТЕКУЩЕЙ ВЕРСИИ ФУНКЦИЯ ОТКЛЮЧЕНА!!
		if self.checkExportOrtho.isChecked()==True:
			statOrthoBuild=True
		else:
			statOrthoBuild=False
		# 000000 Проверка на наличие ортофото или дем перед работой
		if (doc.chunk.orthomosaic==None and statOrthoBuild==False):
			PhotoScan.app.messageBox('Нет орто!!')
			return
		elif (doc.chunk.elevation==None and statOrthoBuild==True):
			PhotoScan.app.messageBox('Нет ДЕМ!!')
			return
		'''
        #Определение вида экспорта - орто или дем
        if self.CheckOrtho_Radio.isChecked() == True:
            ExportType = 'ORTHO'
        elif self.CheckDem_Radio.isChecked() == True:
            ExportType = 'DEM'
        else:
            AssertionError("Какой процесс экспорта?")

        #ПРОВЕРКИ НАЛИЧИЯ ДЕМ И ОРТО
        if (doc.chunk.orthomosaic == None and ExportType == 'ORTHO'):
            PhotoScan.app.messageBox('Нет орто!!')
            return
        elif (doc.chunk.elevation == None and ExportType == 'DEM'):
            PhotoScan.app.messageBox('Нет ДЕМ!!')
            return

        file_format = self.file_format.currentText()
        print('orthoBounds=', len(self.orthoBounds))
        task = []  #Это СПИСОК тасков
        DifPix = float(self.dif_pix.text())
        if self.block_size.currentText() == 'Full':
            BlockSize = 0
        else:
            BlockSize = int(self.block_size.currentText())

        # Цикл для запуска ортофото локально или для забивания стека на сеть из массива
        try:
            for cu_string in self.orthoBounds:
                OName = cu_string[0]
                XMLeft = float(cu_string[1])
                YMDown = float(cu_string[2])
                sizeXM = float(cu_string[3])
                sizeYM = float(cu_string[4])
                shapeNumber = int(cu_string[5])
                cu_Region = self.OrthoBoundCalc(
                    XMLeft, YMDown, sizeXM, sizeYM
                )  #Функция вычисления границ # изменить под сетевую обработку с тайлами
                if file_format == 'JPG' and ExportType == 'ORTHO':
                    fileoutname = self.OUT_dir + "\\ortho_" + OName + ".jpg"
                elif file_format == 'TIF' and ExportType == 'ORTHO':
                    fileoutname = self.OUT_dir + "\\ortho_" + OName + ".tif"
                elif file_format == 'TIF' and ExportType == 'DEM':
                    fileoutname = self.OUT_dir + "\\dem_" + OName + ".tif"
                else:
                    print("Формат файла?")

                if proc_type == 'local':  #КОММАНДЫ для локальной обработки
                    print('Обработка локально')
                    ''' ПОСТРОЕНИЕ ОРТОФОТО В ЭТОЙ ВЕРСИИ ОТКЛЮЧЕНО
					if statOrthoBuild==True: 
						#chunk.buildOrthomosaic(surface=PhotoScan.ElevationData, blending=PhotoScan.MosaicBlending, color_correction=False, projection=self.out_crs, region=cu_Region,dx=DifPix, dy=DifPix)
						chunk.buildOrthomosaic(surface=PhotoScan.ElevationData, blending=PhotoScan.MosaicBlending, projection=self.out_crs, region=cu_Region,dx=DifPix, dy=DifPix)
					'''

                    if CommandStack == 1 and ExportType == 'ORTHO':
                        if file_format == 'JPG':
                            chunk.exportOrthomosaic(fileoutname,
                                                    format="jpg",
                                                    projection=self.out_crs,
                                                    region=cu_Region,
                                                    dx=DifPix,
                                                    dy=DifPix,
                                                    blockw=BlockSize,
                                                    blockh=BlockSize,
                                                    write_kml=False,
                                                    write_world=True)
                        elif file_format == 'TIF':
                            chunk.exportOrthomosaic(fileoutname,
                                                    format="tif",
                                                    projection=self.out_crs,
                                                    region=cu_Region,
                                                    dx=DifPix,
                                                    dy=DifPix,
                                                    blockw=BlockSize,
                                                    blockh=BlockSize,
                                                    write_kml=False,
                                                    write_world=True,
                                                    tiff_compression="jpeg",
                                                    tiff_big=False)
                            #сжатие LZW
                            #elif file_format=='TIF': chunk.exportOrthomosaic(fileoutname, format="tif", region=cu_Region, projection=self.out_crs,dx=DifPix, dy=DifPix, blockw=BlockSize, blockh=BlockSize, write_kml=False, write_world=True, tiff_compression="lzw", tiff_big=False)
                        else:
                            print("Формат файла?")
                    elif CommandStack == 5 and ExportType == 'ORTHO':
                        if file_format == 'JPG':
                            chunk.exportOrthomosaic(
                                fileoutname,
                                PhotoScan.RasterFormatTiles,
                                PhotoScan.ImageFormatJPEG,
                                region=cu_Region,
                                projection=self.out_crs,
                                dx=DifPix,
                                dy=DifPix,
                                blockw=BlockSize,
                                blockh=BlockSize,
                                write_kml=False,
                                write_world=True)
                        elif file_format == 'TIF':
                            chunk.exportOrthomosaic(
                                fileoutname,
                                PhotoScan.RasterFormatTiles,
                                PhotoScan.ImageFormatTIFF,
                                region=cu_Region,
                                projection=self.out_crs,
                                dx=DifPix,
                                dy=DifPix,
                                blockw=BlockSize,
                                blockh=BlockSize,
                                write_kml=False,
                                write_world=True,
                                tiff_compression=PhotoScan.TiffCompressionJPEG,
                                tiff_big=False)
                            #сжатие LZW
                            #elif file_format=='TIF': chunk.exportOrthomosaic(fileoutname, PhotoScan.RasterFormatTiles,PhotoScan.ImageFormatTIFF, region=cu_Region, projection=self.out_crs,dx=DifPix, dy=DifPix, blockw=BlockSize, blockh=BlockSize, write_kml=False, write_world=True, tiff_compression=PhotoScan.TiffCompressionLZW, tiff_big=False)
                        else:
                            print("Формат файла?")
                    elif CommandStack == 1 and ExportType == 'DEM':
                        print("Экспорт ДЕМ локально")
                        if file_format == 'TIF':
                            chunk.exportDem(fileoutname,
                                            format="tif",
                                            projection=self.out_crs,
                                            region=cu_Region,
                                            dx=DifPix,
                                            dy=DifPix,
                                            blockw=BlockSize,
                                            blockh=BlockSize,
                                            write_kml=False,
                                            write_world=True,
                                            tiff_big=False)
                    elif CommandStack == 5 and ExportType == 'DEM':
                        print("Экспорт ДЕМ локально")
                        if file_format == 'TIF':
                            chunk.exportDem(fileoutname,
                                            PhotoScan.RasterFormatTiles,
                                            PhotoScan.ImageFormatTIFF,
                                            region=cu_Region,
                                            projection=self.out_crs,
                                            dx=DifPix,
                                            dy=DifPix,
                                            blockw=BlockSize,
                                            blockh=BlockSize,
                                            write_kml=False,
                                            write_world=True,
                                            tiff_big=False)

                elif proc_type == 'net':
                    print('Обработка по сети')
                    ''' ПОСТРОЕНИЕ ОРТОФОТО В ЭТОЙ ВЕРСИИ ОТКЛЮЧЕНО
					#Построить ортофото
					if statOrthoBuild==True:
						workBuild = PhotoScan.NetworkTask() # СОздаем ворк и забиваем его параметрами
						#Версионность
						if CommandStack==1:
							workBuild.params['ortho_surface'] = 0
							workBuild.params['resolution_x'] = DifPix
							workBuild.params['resolution_y'] = DifPix
						elif CommandStack==5:
							workBuild.params['ortho_surface'] = 4
							workBuild.params['resolution'] = DifPix
						else:
							return
						workBuild.name = "BuildOrthomosaic"
						workBuild.frames.append((chunk.key,0))
						workBuild.params['network_distribute'] = True
						
						task.append(workBuild) #Добавляем задачу построения в таск
					'''

                    #Экспортировать ортофото
                    workExport = PhotoScan.NetworkTask(
                    )  # СОздаем ворк и забиваем его параметрами
                    #ВЕРСИОННОСТЬ
                    if CommandStack == 1 and ExportType == 'ORTHO':
                        workExport.name = "ExportOrthomosaic"
                        workExport.params['resolution_x'] = DifPix
                        workExport.params['resolution_y'] = DifPix
                        if file_format == 'JPG':
                            workExport.params['raster_format'] = 2
                        elif file_format == 'TIF':
                            workExport.params['raster_format'] = 1
                        else:
                            print("Формат файла?")
                    elif CommandStack == 5 and ExportType == 'ORTHO':
                        workExport.name = "ExportRaster"
                        workExport.params['resolution'] = DifPix
                        if file_format == 'JPG':
                            workExport.params['image_format'] = 1
                        elif file_format == 'TIF':
                            workExport.params[
                                'image_format'] = 2  #Значение на шару!!! ПРОВЕРИТЬ
                        else:
                            print("Формат файла?")
                    elif CommandStack == 1 and ExportType == 'DEM':
                        print("Экспорт ДЕМ по сети")
                        workExport.name = "ExportDem"
                        workExport.params['resolution_x'] = DifPix
                        workExport.params['resolution_y'] = DifPix
                    elif CommandStack == 5 and ExportType == 'DEM':  #НЕ ОТЛАЖЕНО ПАРАМЕТРЫ НА ШАРУ
                        print("Экспорт ДЕМ по сети")
                        workExport.name = "ExportOrthomosaic"
                        workExport.params['resolution'] = DifPix
                        pass
                    else:
                        return

                    workExport.frames.append((chunk.key, 0))
                    workExport.params['write_world'] = 1
                    if self.block_size.currentText(
                    ) == 'Full':  # Условие на запись тайлов
                        workExport.params['write_tiles'] = 0
                    else:
                        workExport.params['write_tiles'] = 1
                    workExport.params['tile_width'] = BlockSize
                    workExport.params['tile_height'] = BlockSize
                    workExport.params[
                        'path'] = fileoutname  #выходная дирректория с именем файла
                    workExport.params['region'] = cu_Region
                    # ВНИМАНИЕ! По сети нельзя экспортировать в пользовательской проекции ИЛИ проекция должна быть НА ВСЕХ НОДАХ
                    workExport.params[
                        'projection'] = self.out_crs.authority  #Из объекта проекция берется только ее номер EPSG::32637
                    #ВНИМАНИЕ ЭКСПОРТ ОТКЛЮЧЕН!!!!
                    task.append(workExport)  #Добавляем задачу в таск
                else:
                    print('Пока не задано')
            PhotoScan.app.messageBox('Обработка закончена')
        except Exception as e:
            print(e)
            PhotoScan.app.messageBox('Что-то пошло не так ((')
            return
            #break
#Запуск сетевого стека, таска в обработку
        if proc_type == 'net':
            print(ProjectLocalPath_auto)
            print(ProjectPath)
            client.connect(ServerIP)
            batch_id = client.createBatch(ProjectPath, task)

            if batch_id == None:  #Проверка наличия проекта в сети
                PhotoScan.app.messageBox(
                    '<B>Этот проект уже запущен в обработку!!!<B>')
                self.unlock_export(5)
            else:
                print('Проект работает под номером ', batch_id)
                client.resumeBatch(batch_id)
                self.unlock_export(5)
                PhotoScan.app.messageBox(
                    'Проект поставлен в очередь сетевой обработки')

            client.disconnect()
            pass
Пример #5
0
addr_file.close()
# Create a PhotoScan Network Client object named 'client'
client = PhotoScan.NetworkClient()

# Combines the path to where the project is to be saved with the name of the project in order to save, open, and access the project in the script
filePath = (path + docName)
# Create a PhotoScan Document object and name it 'doc'
doc = PhotoScan.app.document
# Open the document that was previously created by MatchPhotos.py using the filePath variable we created
doc.open(filePath)
# Set the read only variable to false in order to enable editing
doc.read_only = False

#Task 2 or Align Cameras Task
# Create a PhotoScan Network Task object called 'task2'
task2 = PhotoScan.NetworkTask()
# Add all the chunks and frames(if applicable) to the network task so it has access to them
for c in doc.chunks:
    task2.chunks.append(c.key)
    task2.frames.append((c.key, 0))
    print("Added Chunk and Frame")
# Names the task
task2.name = "AlignCameras"
# Applies the task to the chunks we added to the task
task2.params['apply'] = task2.chunks
# Grants the task permission to distribute the processing onto our client
task2.params['network_distribute'] = True

# Connect to the IP Address of the PhotoScan server node we read in from address.txt
client.connect(addr_str)
# Create a batch to submit to the server node
Пример #6
0
addr_file.close()
# Create a PhotoScan Network Client object named 'client'
client = PhotoScan.NetworkClient()

# Combines the path to where the project is to be saved with the name of the project in order to save, open, and access the project in the script
filePath = (path + docName)
# Create a PhotoScan Document object and name it 'doc'
doc = PhotoScan.app.document
# Open the document that was previously created by MatchPhotos.py using the filePath variable we created
doc.open(filePath)
# Set the read only variable to false in order to enable editing
doc.read_only = False

# Task 3 or Build Depth Maps Task
# Create a PhotoScan Network Task object called 'task3'
task3 = PhotoScan.NetworkTask()
# Add all the chunks and frames(if applicable) to the network task so it has access to them
for c in doc.chunks:
    task3.chunks.append(c.key)
    task3.frames.append((c.key, 0))
# Names the task
task3.name = "BuildDepthMaps"
# Applies the task to the chunks we added to the task
task3.params['apply'] = task3.chunks
# Set the processing quality to Ultra, which is the highest quality for PhotoScan
task3.params['downscale'] = int(PhotoScan.UltraQuality)
# Set filtering to not filter
task3.params['filter'] = int(PhotoScan.FilterMode.NoFiltering)
# Tells the task not to look for previously created depth maps since this task is creating the first one for the project
task3.params['reuse_depth'] = False
# Grants the task permission to distribute the processing onto our client
Пример #7
0
addr_file.close()
# Create a PhotoScan Network Client object named 'client'
client = PhotoScan.NetworkClient()

# Combines the path to where the project is to be saved with the name of the project in order to save, open, and access the project in the script
filePath = (path + docName)
# Create a PhotoScan Document object and name it 'doc'
doc = PhotoScan.app.document
# Open the document that was previously created by MatchPhotos.py using the filePath variable we created
doc.open(filePath)
# Set the read only variable to false in order to enable editing
doc.read_only = False

#Task 4 or Build Dense Cloud Task
# Create a PhotoScan Network Task object called 'task4'
task4 = PhotoScan.NetworkTask()
# Add all the chunks and frames(if applicable) to the network task so it has access to them
for c in doc.chunks:
    task4.chunks.append(c.key)
    task4.frames.append((c.key, 0))
# Names the task
task4.name = "BuildDenseCloud"
# Applies the task to the chunks we added to the task
task4.params['apply'] = task4.chunks
# Set the processing quality to Ultra, which is the highest quality for PhotoScan
task4.params['downscale'] = int(PhotoScan.UltraQuality)
# Set filtering to not filter
task4.params['filter'] = int(PhotoScan.FilterMode.NoFiltering)
# Grants the task permission to distribute the processing onto our client
task4.params['network_distribute'] = True
Пример #8
0
addr_file.close()
# Create a PhotoScan Network Client object named 'client'
client = PhotoScan.NetworkClient()

# Combines the path to where the project is to be saved with the name of the project in order to save, open, and access the project in the script
filePath = (path + docName)
# Create a PhotoScan Document object and name it 'doc'
doc = PhotoScan.app.document
# Open the document that was previously created by MatchPhotos.py using the filePath variable we created
doc.open(filePath)
# Set the read only variable to false in order to enable editing
doc.read_only = False

#Task 6 or Build DEM Task
# Create a PhotoScan Network Task object called 'task6'            
task6 = PhotoScan.NetworkTask()  
# Add all the chunks and frames(if applicable) to the network task so it has access to them 
for c in doc.chunks:
        task6.chunks.append(c.key)    
        task6.frames.append((c.key,0))
# Names the task
task6.name = "BuildDEM"    
# Applies the task to the chunks we added to the task  
task6.params['apply'] = task6.chunks
#Set the Dense Cloud as the source data to be used to construct the mesh
task6.params['source_data'] = int(PhotoScan.DataSource.DenseCloudData)
#Enable deafult Interpolation
task6.params['interpolation'] = int(PhotoScan.Interpolation.EnabledInterpolation)
# Grants the task permission to distribute the processing onto our client
task6.params['network_distribute'] = True
Пример #9
0
addr_file.close()
# Create a PhotoScan Network Client object named 'client'
client = PhotoScan.NetworkClient()

# Combines the path to where the project is to be saved with the name of the project in order to save, open, and access the project in the script
filePath = (path + docName)
# Create a PhotoScan Document object and name it 'doc'
doc = PhotoScan.app.document
# Open the document that was previously created by MatchPhotos.py using the filePath variable we created
doc.open(filePath)
# Set the read only variable to false in order to enable editing
doc.read_only = False

#Task 5 or Build Mesh Task
# Create a PhotoScan Network Task object called 'task5'
task5 = PhotoScan.NetworkTask()
# Add all the chunks and frames(if applicable) to the network task so it has access to them
for c in doc.chunks:
    task5.chunks.append(c.key)
    task5.frames.append((c.key, 0))
# Names the task
task5.name = "BuildMesh"
# Applies the task to the chunks we added to the task
task5.params['apply'] = task5.chunks
# Set the processing quality to Ultra, which is the highest quality for PhotoScan
#task5.params['downscale'] = int(PhotoScan.UltraQuality)
# Set filtering to not filter
task5.params['filter'] = int(PhotoScan.FilterMode.NoFiltering)
#Set the Dense Cloud as the source data to be used to construct the mesh
task5.params['source_data'] = int(PhotoScan.DataSource.DenseCloudData)
#Enable deafult Interpolation
Пример #10
0
addr_file.close()
# Create a PhotoScan Network Client object named 'client'
client = PhotoScan.NetworkClient()

# Combines the path to where the project is to be saved with the name of the project in order to save, open, and access the project in the script
filePath = (path + docName)
# Create a PhotoScan Document object and name it 'doc'
doc = PhotoScan.app.document
# Open the document that was previously created by MatchPhotos.py using the filePath variable we created
doc.open(filePath)
# Set the read only variable to false in order to enable editing
doc.read_only = False

#Task 7 or Build Orthomosaic Task
# Create a PhotoScan Network Task object called 'task7'
task7 = PhotoScan.NetworkTask()
# Add all the chunks and frames(if applicable) to the network task so it has access to them
for c in doc.chunks:
    task7.chunks.append(c.key)
    task7.frames.append((c.key, 0))
# Names the task
task7.name = "BuildOrtho"
# Applies the task to the chunks we added to the task
task7.params['apply'] = task7.chunks
# Sets the blending mode to Mosaic Blending
task7.params['blending_mode'] = int(PhotoScan.BlendingMode.MosaicBlending)
# Tells the task to enable hole filling
task7.params['fill_holes'] = True
# Tells task to get surface data from the previously created Elevation Model(DEM)
task7.params['ortho_surface'] = int(PhotoScan.DataSource.ElevationData)
# Grants the task permission to distribute the processing onto our client
Пример #11
0
photos = []
# Using glob, grab all the photos from the photos folder and add them to the list
for photo in glob.glob(sourceFolderPath):
    photos.append(photo)

# Add all the photos from the list to the chunk
chunk.addPhotos(photos)

# Set the read only variable to false in order to enable editing
doc.read_only = False
# Saves the current state of the project
doc.save()

# Task 1 or Match Photos Task
# Create a PhotoScan Network Task object called 'task1'
task1 = PhotoScan.NetworkTask()
# Add all the chunks and frames(if applicable) to the network task so it has access to them
for c in doc.chunks:
    task1.frames.append((c.key, 0))
    task1.chunks.append(c.key)
    print(c)
    print("Added Chunk and Frame")
# Names the task
task1.name = "MatchPhotos"
# Sets the matching accuracy to the highest accuracy possible
task1.params['downscale'] = int(PhotoScan.HighestAccuracy)
# Grants the task permission to distribute the processing onto our client
task1.params['network_distribute'] = True

# Connect to the IP Address of the PhotoScan server node we read in from address.txt
client.connect(addr_str)