Commit 52360416 authored by jlaura's avatar jlaura Committed by Kelvin Rodriguez
Browse files

Updates for testing control and ring_matching (#265)

* updates to get control tests updated

* Updates tests for ring matcher

* Refactors OpenCV SIFT extractor out of unit/functional tests

* Removes unused control code

* Should fix failing conda build

* pyproj datdir issues

* Working on deprecation fixes for scipy imread

* Swapping imageio
parent 97c0ad20
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ before_install:
  - conda config --add channels usgs-astrogeology
  - conda config --add channels conda-forge
  - conda env update -n test -f environment.yml

  - export PROJ_LIB=$CONDA_PREFIX/share/proj  
script:
  - pytest autocnet tests

+13 −2
Original line number Diff line number Diff line
@@ -12,12 +12,23 @@ import autocnet.matcher
import autocnet.transformation
import autocnet.utils

from pkg_resources import get_distribution, DistributionNotFound
try:
    _dist = get_distribution('autocnet')
    # Normalize case for Windows systems
    dist_loc = os.path.normcase(_dist.location)
    here = os.path.normcase(__file__)
    if not here.startswith(os.path.join(dist_loc, 'autocnet')):
        # not installed, but there is another version that *is*
        raise DistributionNotFound
except DistributionNotFound:
    __version__ = 'Please install this project with setup.py'
else:
    __version__ = _dist.version

# Patch the candidate graph into the root namespace
from autocnet.graph.network import CandidateGraph

__version__ = "0.1.0"

def get_data(filename):
    packagdir = autocnet.__path__[0]
    dirname = os.path.join(os.path.dirname(packagdir), 'data')
+3 −23
Original line number Diff line number Diff line
import numpy as np
from autocnet.camera.utils import crossform
try:
import cv2
except:
    cv2 = None



def compute_epipoles(f):
@@ -103,29 +101,11 @@ def triangulate(pt, pt1, p, p1):
        pt = pt.T
    if pt1.shape[0] != 3:
        pt1 = pt1.T
    #if cv2:

    X = cv2.triangulatePoints(p, p1, pt[:2], pt1[:2])
    X /= X[3] # Homogenize
    return X
    """
    # Stubbed in for a ticket addressing making OpenCV an optional dependency
    else:
        npts = len(pt)
        a = np.zeros((4, 4))
        coords = np.empty((npts, 4))
        coords[:] = 1
        for i in range(npts):
            # Compute AX = 0
            a[0] = pt[i][0] * p[2] - p[0]
            a[1] = pt[i][1] * p[2] - p[1]
            a[2] = pt1[i][0] * p1[2] - p1[0]
            a[3] = pt1[i][1] * p1[2] - p1[1]
            # v.T is a least squares solution that minimizes the error residual
            u, s, vh = np.linalg.svd(a)
            v = vh.T
            coords[i] = v[:,3] / (v[:,3][-1])
        return coords.T
    """

def projection_error(p1, p, pt, pt1):
    """
    Based on Hartley and Zisserman p.285 this function triangulates
+1 −36
Original line number Diff line number Diff line
@@ -10,37 +10,6 @@ from autocnet.matcher import subpixel as sp
from plio.io.io_controlnetwork import to_isis, write_filelist


def subpixel_match(cg, cn, threshold=0.9, template_size=19, search_size=53, max_x_shift=1.0, max_y_shift=1.0, **kwargs):

    def subpixel_group(group, threshold=0.9, template_size=19, search_size=53, max_x_shift=1.0, max_y_shift=1.0, **kwargs):
        offs = []
        for i, (idx, r) in enumerate(group.iterrows()):
            if i == 0:
                x = r.x
                y = r.y
                offs.append([0, 0, np.inf])
                continue

            e = r.edge
            s_img = cg.edge[e[0]][e[1]].source.geodata
            s_template = sp.clip_roi(s_img, (x, y), template_size)
            # s_template = cv2.Canny(bytescale(s_template), 50,100) # Canny - bad idea
            d_img = cg.edge[e[0]][e[1]].destination.geodata
            d_search = sp.clip_roi(d_img, (r.x, r.y), search_size)
            #d_search = cv2.Canny(bytescale(d_search), 50,100)

            xoff, yoff, corr = sp.subpixel_offset(
                s_template, d_search, **kwargs)
            offs.append([xoff, yoff, corr])
        df = pd.DataFrame(
            offs, columns=['x_off', 'y_off', 'corr'], index=group.index)
        return df
    gps = cn.data.groupby('point_id').apply(subpixel_group, threshold=0.9, max_x_shift=5,
                                            max_y_shift=5, template_size=template_size, search_size=search_size, **kwargs)
    cn.data[['x_off', 'y_off', 'corr']] = gps.reset_index()[
        ['x_off', 'y_off', 'corr']]


def identify_potential_overlaps(cg, cn, overlap=True):
    """
    Identify those points that could have additional measures
@@ -67,7 +36,7 @@ def identify_potential_overlaps(cg, cn, overlap=True):
    candidate_cliques = []
    geoms = []
    idx = []
    for i, p in cn.data.groupby('point_id'):
    for i, p in cn.groupby('point_id'):
        # Which images are covered already.  This finds any connected cycles that
        #  a node is in (this can be more than one - an hourglass network for example)
        # Extract the fully connected subgraph for each covered image in order to
@@ -123,7 +92,3 @@ def identify_potential_overlaps(cg, cn, overlap=True):
        return candidate_cliques.query('overlap == True')['candidates']
    else:
        return candidate_cliques.candidates


def deepen_correspondences(cg, cn):
    pass
+28 −26
Original line number Diff line number Diff line
"""from unittest.mock import MagicMock
from unittest.mock import MagicMock
import geopandas as gpd
import pandas as pd
from shapely.geometry import Polygon

import pytest
from autocnet.control import control

import os
import sys
sys.path.insert(0, '..')
from .. import control
def test_identify_potential_overlaps(controlnetwork, candidategraph):
    res = control.identify_potential_overlaps(candidategraph,
                                              controlnetwork,
                                              overlap=False)

    assert res.equals(pd.Series([(2,), (2,),
                                 (1,), (1,),
                                 (0,), (0,)],
                                 index=[6,7,8,9,10,11]))

def test_potential_overlap(controlnetwork, candidategraph):
    # Patch in an intersection check so that all points intersect all geoms
    candidategraph.create_node_subgraph = MagicMock(return_value=candidategraph)
    coords = [(-1., -1.), (-1., 1.), (1., 1.), (1., -1.), (-1., -1.)]
    poly = gpd.GeoSeries(Polygon(coords))
    candidategraph.compute_intersection = MagicMock(return_value=(poly, 0))
    res = control.identify_potential_overlaps(candidategraph,
                                              controlnetwork,
                                              overlap=True)

    assert res.equals(pd.Series([(2,), (2,),
                                 (1,), (1,),
                                 (0,), (0,)],
                                 index=[6,7,8,9,10,11]))

"""
def test_fromcandidategraph(candidategraph, controlnetwork_data):#, controlnetwork):
    matches = candidategraph.get_matches()
    cn = control.ControlNetwork.from_candidategraph(matches)
@@ -42,28 +65,7 @@ def test_bad_validate_points(bad_controlnetwork):
    assert bad_controlnetwork.validate_points().iloc[0] == True
    assert not bad_controlnetwork.validate_points().iloc[1:].all()

def test_identify_potential_overlaps(controlnetwork, candidategraph):
    res = control.identify_potential_overlaps(candidategraph,
                                              controlnetwork,
                                              overlap=False)

    assert res.equals(pd.Series([(2,), (2,),
                                 (1,), (1,),
                                 (0,), (0,)],
                                 index=[6,7,8,9,10,11]))

def test_potential_overlap(controlnetwork, candidategraph):
    # Patch in an intersection check so that all points intersect all geoms
    candidategraph.create_node_subgraph = MagicMock(return_value=candidategraph)
    coords = [(-1., -1.), (-1., 1.), (1., 1.), (1., -1.), (-1., -1.)]
    poly = gpd.GeoSeries(Polygon(coords))
    candidategraph.compute_intersection = MagicMock(return_value=(poly, 0))
    res = control.identify_potential_overlaps(candidategraph,
                                              controlnetwork,
                                              overlap=True)

    assert res.equals(pd.Series([(2,), (2,),
                                 (1,), (1,),
                                 (0,), (0,)],
                                 index=[6,7,8,9,10,11]))
"""
 No newline at end of file
Loading