def geoJsonToSBD(annotationName_cls, annotationName_inst, geoJson, rasterSource):
#Print raster file name
my_raster_source = rasterSource
print("Raster directory : ",my_raster_source)
srcRaster = gdal.Open(my_raster_source)
my_vector_source = geoJson
print("Vector directory : ",my_vector_source)
#Call main functions to create label datafor cls
my_cls_segmentation = createClassSegmentation(my_raster_source, my_vector_source, npDistFileName='', units='pixels')
my_cls_boundaries = createClassBoundaries(my_raster_source, my_vector_source, npDistFileName='', units='pixels')
my_cls_categories = createClassCategoriesPresent(my_vector_source)
#Call main functions to create label datafor inst
my_inst_segmentation = createInstanceSegmentation(my_raster_source, my_vector_source)
my_inst_boundaries = createInstanceBoundaries(my_raster_source, my_vector_source)
my_inst_categories = createInstanceCategories(my_vector_source)
#Wraps for cls struct
cls_boundaries_wrap = np.array([my_cls_boundaries])
cls_categories_wrap = my_cls_categories
#Wraps for inst struct
inst_boundaries_wrap = np.array([my_inst_boundaries])
inst_categories_wrap = my_inst_categories
#Create a class struct
GTcls = {'Segmentation': my_cls_segmentation , 'Boundaries': cls_boundaries_wrap, 'CategoriesPresent': cls_categories_wrap}
#Create the instance struct
GTinst = {'Segmentation': my_inst_segmentation , 'Boundaries': inst_boundaries_wrap, 'Categories': inst_categories_wrap}
#Save the files
scipy.io.savemat(annotationName_cls,{'GTcls': GTcls})
scipy.io.savemat(annotationName_inst,{'GTinst': GTinst})
print("Done with "+str())
entry = {'rasterFileName': my_raster_source,
'geoJsonFileName': geoJson,
'annotationName' : annotationName_cls,
'annotationName_cls': annotationName_cls,
'annotationName_inst':annotationName_inst,
'width': srcRaster.RasterXSize,
'height': srcRaster.RasterYSize,
'depth' : srcRaster.RasterCount,
'basename': os.path.splitext(os.path.basename(my_raster_source))[0]
}
return entry
评论列表
文章目录