Ejemplo n.º 1
0
 def test_filtered_copy(self):
     gcp = GCPFile('tests/assets/gcp_latlon_valid.txt')
     self.assertTrue(gcp.exists())
     self.assertEqual(gcp.entries_count(), 2)
     copy = GCPFile(gcp.make_filtered_copy('tests/assets/output/filtered_copy.txt', 'tests/assets/images', min_images=1))
     self.assertTrue(copy.exists())
     self.assertEqual(copy.entries_count(), 1)
Ejemplo n.º 2
0
    def georeference_with_gcp(self,
                              gcp_file,
                              output_coords_file,
                              output_gcp_file,
                              rerun=False):
        if not io.file_exists(output_coords_file) or not io.file_exists(
                output_gcp_file) or rerun:
            gcp = GCPFile(gcp_file)
            if gcp.exists():
                # Create coords file, we'll be using this later
                # during georeferencing
                with open(output_coords_file, 'w') as f:
                    coords_header = gcp.wgs84_utm_zone()
                    f.write(coords_header + "\n")
                    log.ODM_DEBUG("Generated coords file from GCP: %s" %
                                  coords_header)

                # Convert GCP file to a UTM projection since the rest of the pipeline
                # does not handle other SRS well.
                rejected_entries = []
                utm_gcp = GCPFile(
                    gcp.create_utm_copy(
                        output_gcp_file,
                        filenames=[p.filename for p in self.photos],
                        rejected_entries=rejected_entries,
                        include_extras=False))

                if not utm_gcp.exists():
                    raise RuntimeError(
                        "Could not project GCP file to UTM. Please double check your GCP file for mistakes."
                    )

                for re in rejected_entries:
                    log.ODM_WARNING("GCP line ignored (image not found): %s" %
                                    str(re))

                if utm_gcp.entries_count() > 0:
                    log.ODM_INFO(
                        "%s GCP points will be used for georeferencing" %
                        utm_gcp.entries_count())
                else:
                    raise RuntimeError(
                        "A GCP file was provided, but no valid GCP entries could be used. Note that the GCP file is case sensitive (\".JPG\" is not the same as \".jpg\")."
                    )

                self.gcp = utm_gcp
            else:
                log.ODM_WARNING("GCP file does not exist: %s" % gcp_file)
                return
        else:
            log.ODM_INFO("Coordinates file already exist: %s" %
                         output_coords_file)
            log.ODM_INFO("GCP file already exist: %s" % output_gcp_file)
            self.gcp = GCPFile(output_gcp_file)

        self.georef = ODM_GeoRef.FromCoordsFile(output_coords_file)
        return self.georef
Ejemplo n.º 3
0
    def georeference_with_gcp(self, gcp_file, output_coords_file, output_gcp_file, output_model_txt_geo, rerun=False):
        if not io.file_exists(output_coords_file) or not io.file_exists(output_gcp_file) or rerun:
            gcp = GCPFile(gcp_file)
            if gcp.exists():
                if gcp.entries_count() == 0:
                    raise RuntimeError("This GCP file does not have any entries. Are the entries entered in the proper format?")

                # Convert GCP file to a UTM projection since the rest of the pipeline
                # does not handle other SRS well.
                rejected_entries = []
                utm_gcp = GCPFile(gcp.create_utm_copy(output_gcp_file, filenames=[p.filename for p in self.photos], rejected_entries=rejected_entries, include_extras=False))
                
                if not utm_gcp.exists():
                    raise RuntimeError("Could not project GCP file to UTM. Please double check your GCP file for mistakes.")
                
                for re in rejected_entries:
                    log.ODM_WARNING("GCP line ignored (image not found): %s" % str(re))
                
                if utm_gcp.entries_count() > 0:
                    log.ODM_INFO("%s GCP points will be used for georeferencing" % utm_gcp.entries_count())
                else:
                    raise RuntimeError("A GCP file was provided, but no valid GCP entries could be used. Note that the GCP file is case sensitive (\".JPG\" is not the same as \".jpg\").")
                
                self.gcp = utm_gcp

                # Compute RTC offsets from GCP points
                x_pos = [p.x for p in utm_gcp.iter_entries()]
                y_pos = [p.y for p in utm_gcp.iter_entries()]
                x_off, y_off = int(np.round(np.mean(x_pos))), int(np.round(np.mean(y_pos)))

                # Create coords file, we'll be using this later
                # during georeferencing
                with open(output_coords_file, 'w') as f:
                    coords_header = gcp.wgs84_utm_zone()
                    f.write(coords_header + "\n")
                    f.write("{} {}\n".format(x_off, y_off))
                    log.ODM_INFO("Generated coords file from GCP: %s" % coords_header)
                
                # Deprecated: This is mostly for backward compatibility and should be
                # be removed at some point
                shutil.copyfile(output_coords_file, output_model_txt_geo)
                log.ODM_INFO("Wrote %s" % output_model_txt_geo)
            else:
                log.ODM_WARNING("GCP file does not exist: %s" % gcp_file)
                return
        else:
            log.ODM_INFO("Coordinates file already exist: %s" % output_coords_file)
            log.ODM_INFO("GCP file already exist: %s" % output_gcp_file)
            self.gcp = GCPFile(output_gcp_file)
        
        self.georef = ODM_GeoRef.FromCoordsFile(output_coords_file)
        return self.georef
Ejemplo n.º 4
0
def resize_gcp(gcp_path, out_path, resize_to, out_path_is_file=False):
    """
    :param gcp_path: path to the GCP
    :param out_path: path to the output directory or file
    :param resize_to: percentage ("perc%") or pixels
    """
    try:
        if out_path_is_file:
            resized_gcp_path = out_path
        else:
            resized_gcp_path = os.path.join(out_path,
                                            os.path.basename(gcp_path))

        if resize_to.endswith("%"):
            ratio = float(resize_to[:-1]) / 100.0
        else:
            ratio = resize_to

        gcp = GCPFile(gcp_path)
        if gcp.entries_count() > 0:
            gcp.make_resized_copy(resized_gcp_path, ratio)
        else:
            raise ValueError("No GCP entries")

        print("{} --> {}".format(gcp_path, resized_gcp_path))
    except (IOError, ValueError) as e:
        print("Error: Cannot resize {}: {}.".format(gcp_path, str(e)))
        nonloc.errors += 1