Exemple #1
0
def height_map_error(self, image_id, history=None):
  
  import numpy as np

  import vpgl_adaptor
  
  from vsi.io.image import imread, GdalReader
  
  from voxel_globe.meta import models
  import voxel_globe.tools
  from voxel_globe.tools.celery import Popen

  from voxel_globe.tools.wget import download as wget

  tie_points_yxz = []
  control_points_yxz = []

  image = models.Image.objects.get(id=image_id).history(history)

  with voxel_globe.tools.task_dir('height_map_error_calculation', cd=True) as processing_dir:
    wget(image.originalImageUrl, image.original_filename, secret=True)
    height_reader =  GdalReader(image.original_filename, autoload=True)
    transform = height_reader.object.GetGeoTransform()
    height = height_reader.raster()

  tie_point_ids = set([x for imagen in models.Image.objects.filter(
      objectId=image.objectId) for x in imagen.tiepoint_set.all().values_list(
      'objectId', flat=True)])

  for tie_point_id in tie_point_ids:
    tie_point = models.TiePoint.objects.get(objectId=tie_point_id, newerVersion=None).history(history)

    if not tie_point.deleted:
      lla_xyz = models.ControlPoint.objects.get(objectId = tie_point.geoPoint.objectId, newerVersion=None).history(history).point.coords
      control_points_yxz.append([lla_xyz[x] for x in [1,0,2]])
      tie_points_yxz.append([transform[4]*(tie_point.point.coords[0]+0.5) + transform[5]*(tie_point.point.coords[1]+0.5) + transform[3],
                             transform[1]*(tie_point.point.coords[0]+0.5) + transform[2]*(tie_point.point.coords[1]+0.5) + transform[0],
                             height[tie_point.point.coords[1], tie_point.point.coords[0]]])

  origin_yxz = np.mean(np.array(control_points_yxz), axis=0)
  tie_points_local = []
  control_points_local = []
  lvcs = vpgl_adaptor.create_lvcs(origin_yxz[0], origin_yxz[1], origin_yxz[2], 'wgs84')

  for tie_point in tie_points_yxz:
    tie_points_local.append(vpgl_adaptor.convert_to_local_coordinates2(lvcs, *tie_point))

  for control_point in control_points_yxz:
    control_points_local.append(vpgl_adaptor.convert_to_local_coordinates2(lvcs, *control_point))

  error = np.linalg.norm(np.array(tie_points_local)-np.array(control_points_local), axis=0)/(len(tie_points_local)**0.5)

  result={}
  result['error'] = list(error)
  result['horizontal_accuracy'] = 2.4477*0.5*(error[0]+error[1])
  result['vertical_accuracy'] = 1.96*error[2]

  return result
Exemple #2
0
def height_map_error(self, image_id):
  
  import numpy as np

  import vpgl_adaptor_boxm2_batch as vpgl_adaptor
  
  from vsi.io.image import imread, GdalReader
  
  from voxel_globe.meta import models
  import voxel_globe.tools
  from voxel_globe.tools.celery import Popen

  from vsi.tools.file_util import lncp

  tie_points_yxz = []
  control_points_yxz = []

  image = models.Image.objects.get(id=image_id)

  height_reader =  GdalReader(image.filename_path, autoload=True)
  transform = height_reader.object.GetGeoTransform()
  height = height_reader.raster()
  del height_reader

  tie_points = image.tiepoint_set.all()

  for tie_point in tie_points:
    lla_xyz = tie_point.control_point.point.coords
    control_points_yxz.append([lla_xyz[x] for x in [1,0,2]])
    tie_points_yxz.append([transform[4]*(tie_point.point.coords[0]+0.5) + transform[5]*(tie_point.point.coords[1]+0.5) + transform[3],
                           transform[1]*(tie_point.point.coords[0]+0.5) + transform[2]*(tie_point.point.coords[1]+0.5) + transform[0],
                           height[tie_point.point.coords[1], tie_point.point.coords[0]]])

  origin_yxz = np.mean(np.array(control_points_yxz), axis=0)
  tie_points_local = []
  control_points_local = []
  lvcs = vpgl_adaptor.create_lvcs(origin_yxz[0], origin_yxz[1], origin_yxz[2], 'wgs84')

  for tie_point in tie_points_yxz:
    tie_points_local.append(vpgl_adaptor.convert_to_local_coordinates2(lvcs, *tie_point))

  for control_point in control_points_yxz:
    control_points_local.append(vpgl_adaptor.convert_to_local_coordinates2(lvcs, *control_point))

  error = np.linalg.norm(np.array(tie_points_local)-np.array(control_points_local), axis=0)/(len(tie_points_local)**0.5)

  result={}
  result['error'] = list(error)
  result['horizontal_accuracy'] = 2.4477*0.5*(error[0]+error[1])
  result['vertical_accuracy'] = 1.96*error[2]

  return result
Exemple #3
0
def height_map_error(self, image_id):

    import numpy as np

    import vpgl_adaptor_boxm2_batch as vpgl_adaptor

    from vsi.io.image import imread, GdalReader

    from voxel_globe.meta import models
    import voxel_globe.tools
    from voxel_globe.tools.celery import Popen

    from vsi.tools.file_util import lncp

    tie_points_yxz = []
    control_points_yxz = []

    image = models.Image.objects.get(id=image_id)

    height_reader = GdalReader(image.filename_path, autoload=True)
    transform = height_reader.object.GetGeoTransform()
    height = height_reader.raster()
    del height_reader

    tie_points = image.tiepoint_set.all()

    for tie_point in tie_points:
        lla_xyz = tie_point.control_point.point.coords
        control_points_yxz.append([lla_xyz[x] for x in [1, 0, 2]])
        tie_points_yxz.append([
            transform[4] * (tie_point.point.coords[0] + 0.5) + transform[5] *
            (tie_point.point.coords[1] + 0.5) + transform[3],
            transform[1] * (tie_point.point.coords[0] + 0.5) + transform[2] *
            (tie_point.point.coords[1] + 0.5) + transform[0],
            height[tie_point.point.coords[1], tie_point.point.coords[0]]
        ])

    origin_yxz = np.mean(np.array(control_points_yxz), axis=0)
    tie_points_local = []
    control_points_local = []
    lvcs = vpgl_adaptor.create_lvcs(origin_yxz[0], origin_yxz[1],
                                    origin_yxz[2], 'wgs84')

    for tie_point in tie_points_yxz:
        tie_points_local.append(
            vpgl_adaptor.convert_to_local_coordinates2(lvcs, *tie_point))

    for control_point in control_points_yxz:
        control_points_local.append(
            vpgl_adaptor.convert_to_local_coordinates2(lvcs, *control_point))

    error = np.linalg.norm(
        np.array(tie_points_local) - np.array(control_points_local),
        axis=0) / (len(tie_points_local)**0.5)

    result = {}
    result['error'] = list(error)
    result['horizontal_accuracy'] = 2.4477 * 0.5 * (error[0] + error[1])
    result['vertical_accuracy'] = 1.96 * error[2]

    return result
Exemple #4
0
def height_map_error(self, image_id, history=None):

    import numpy as np

    import vpgl_adaptor

    from vsi.io.image import imread, GdalReader

    from voxel_globe.meta import models
    import voxel_globe.tools
    from voxel_globe.tools.celery import Popen

    from voxel_globe.tools.wget import download as wget

    tie_points_yxz = []
    control_points_yxz = []

    image = models.Image.objects.get(id=image_id).history(history)

    with voxel_globe.tools.task_dir('height_map_error_calculation',
                                    cd=True) as processing_dir:
        wget(image.originalImageUrl, image.original_filename, secret=True)
        height_reader = GdalReader(image.original_filename, autoload=True)
        transform = height_reader.object.GetGeoTransform()
        height = height_reader.raster()

    tie_point_ids = set([
        x for imagen in models.Image.objects.filter(objectId=image.objectId)
        for x in imagen.tiepoint_set.all().values_list('objectId', flat=True)
    ])

    for tie_point_id in tie_point_ids:
        tie_point = models.TiePoint.objects.get(
            objectId=tie_point_id, newerVersion=None).history(history)

        if not tie_point.deleted:
            lla_xyz = models.ControlPoint.objects.get(
                objectId=tie_point.geoPoint.objectId,
                newerVersion=None).history(history).point.coords
            control_points_yxz.append([lla_xyz[x] for x in [1, 0, 2]])
            tie_points_yxz.append([
                transform[4] * (tie_point.point.coords[0] + 0.5) +
                transform[5] * (tie_point.point.coords[1] + 0.5) +
                transform[3], transform[1] *
                (tie_point.point.coords[0] + 0.5) + transform[2] *
                (tie_point.point.coords[1] + 0.5) + transform[0],
                height[tie_point.point.coords[1], tie_point.point.coords[0]]
            ])

    origin_yxz = np.mean(np.array(control_points_yxz), axis=0)
    tie_points_local = []
    control_points_local = []
    lvcs = vpgl_adaptor.create_lvcs(origin_yxz[0], origin_yxz[1],
                                    origin_yxz[2], 'wgs84')

    for tie_point in tie_points_yxz:
        tie_points_local.append(
            vpgl_adaptor.convert_to_local_coordinates2(lvcs, *tie_point))

    for control_point in control_points_yxz:
        control_points_local.append(
            vpgl_adaptor.convert_to_local_coordinates2(lvcs, *control_point))

    error = np.linalg.norm(
        np.array(tie_points_local) - np.array(control_points_local),
        axis=0) / (len(tie_points_local)**0.5)

    result = {}
    result['error'] = list(error)
    result['horizontal_accuracy'] = 2.4477 * 0.5 * (error[0] + error[1])
    result['vertical_accuracy'] = 1.96 * error[2]

    return result