Commit 189326bc authored by jlaura's avatar jlaura Committed by GitHub
Browse files

Update camera and fundamental (#247)

* fixes footprint test Polyon to LinearRing

* Updates for camera estimation from fundamental matrix

* Trying to fix the mac build

* typo in travis

* explicit libgdal for OSX builds - dep issues
parent ae7d8253
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -39,12 +39,12 @@ before_install:
  # Install dependencies
  - conda config --add channels conda-forge
  - conda config --set ssl_verify false
  - conda install -c conda-forge vlfeat scipy networkx numexpr cython matplotlib pillow runipy geopandas opencv numpy gdal
  - conda install -c conda-forge vlfeat scipy networkx numexpr cython matplotlib pillow runipy geopandas opencv numpy libgdal gdal
  - conda install -c menpo cyvlfeat
  - conda install -c usgs-astrogeology plio
  
  # Development installation
  - conda install pytest pytest-cov coverage sh anaconda-client
  - conda install -c conda-forge pytest pytest-cov coverage anaconda-client
  - pip install coveralls

script:
+3 −3
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ def idealized_camera():
    i[:,-1] = 0
    return i

def estimated_camera_from_f(f):
def camera_from_f(F):
    """
    Estimate a camera matrix using a fundamental matrix.

@@ -57,9 +57,9 @@ def estimated_camera_from_f(f):
         Estimated camera matrix
    """

    e, e1 = compute_epipoles(f)
    e, e1 = compute_epipoles(F)
    p1 = np.empty((3, 4))
    p1[:, :3] = e1.dot(f)
    p1[:, :3] = -e1.dot(F)
    p1[:, 3] = e

    return p1
+31 −38
Original line number Diff line number Diff line
import os
import sys
import unittest

import pytest
import numpy as np

sys.path.append(os.path.abspath('..'))

from .. import camera


class TestCamera(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.f = np.array([[3.27429392e-07, 8.31555374e-06, -1.37175583e-05],
                          [2.33349759e-07, 5.99315297e-07,  1.15196332e-01],
                          [-4.78065797e-03, -1.21448858e-01, 1.00000000e+00]])

    def test_compute_epipoles(self):
        e, e1 = camera.compute_epipoles(self.f)
        np.testing.assert_array_almost_equal(e, np.array([9.99999885e-01, -4.75272787e-04, 6.84672384e-05]))

        np.testing.assert_array_almost_equal(e1, np.array([[0.00000000e+00,  -6.84672384e-05,  -4.75272787e-04],
                                                    [6.84672384e-05,   0.00000000e+00,  -9.99999885e-01],
                                                    [4.75272787e-04,   9.99999885e-01,   0.00000000e+00]]))

    def test_idealized_camera(self):
        np.testing.assert_array_equal(np.eye(3,4), camera.idealized_camera())

    def test_estimated_camera_from_f(self):
        p1 = camera.estimated_camera_from_f(self.f)
        np.testing.assert_array_almost_equal(p1, np.array([[2.27210066e-06, 5.77212964e-05, -4.83159962e-04, 9.99999885e-01],
                                                    [4.78065745e-03,   1.21448845e-01,  -9.99999886e-01, -4.75272787e-04],
                                                    [2.33505351e-07,   6.03267385e-07,   1.15196312e-01, 6.84672384e-05]]))

    def test_triangulation_and_reprojection_error(self):
import autocnet.camera.camera as cam

@pytest.fixture
def F():
    return np.array([[-2.62542734e-07, 3.24680544e-08, 1.06264873e-06],
                     [-2.58739695e-07, 3.30340456e-09, 0.0015042137],
                     [0.0134032928, -0.00167767917, 1.00000026]])

def test_compute_epipoles(F):
        e, e1 = cam.compute_epipoles(F)
        np.testing.assert_array_almost_equal(e, np.array([ 9.99908150e-01, -1.35532934e-02, 1.93244935e-05]))

        np.testing.assert_array_almost_equal(e1, 
                                             np.array([[  0.00000000e+00, 1.93244935e-05, 1.35532934e-02],
                                                       [ -1.93244935e-05, 0.00000000e+00, 9.99908150e-01],
                                                       [ -1.35532934e-02, -9.99908150e-01, 0.00000000e+00]]))

def test_camera_from_f(F):
    truth = np.array([[-1.81658755e-04,  2.27380780e-05, -1.35533260e-02, 9.99908150e-01],
                      [-1.34020617e-02,  1.67752508e-03, -9.99908410e-01, -1.35532934e-02],
                      [-2.62274248e-07,  3.74315021e-09,  1.50408994e-03, 1.93244935e-05]])
    p = cam.camera_from_f(F)
    np.testing.assert_almost_equal(p, truth)

def test_idealized_camera():
    np.testing.assert_array_equal(np.eye(3,4), cam.idealized_camera())

def test_triangulation_and_reprojection_error():
    p = np.eye(3,4)
    p1 = np.array([[2.27210066e-06, 5.77212964e-05, -4.83159962e-04, 9.99999885e-01],
                    [4.78065745e-03,   1.21448845e-01,  -9.99999886e-01, -4.75272787e-04],
@@ -57,9 +50,9 @@ class TestCamera(unittest.TestCase):
                        [0.01167342, 0.00833074, 0.00898143, 0.01721084, 0.00906604],
                        [1., 1., 1., 1., 1. ]])

        c = camera.triangulate(coords1, coords2, p, p1)
    c = cam.triangulate(coords1, coords2, p, p1)
    np.testing.assert_array_almost_equal(c, truth)

    truth = np.array([0.17603 ,  0.510191,  0.285109,  0.746513,  0.021731])
        residuals = camera.projection_error(p1, p, coords1.T, coords2.T)
    residuals = cam.projection_error(p1, p, coords1.T, coords2.T)
    np.testing.assert_array_almost_equal(residuals, truth)
 No newline at end of file
+4 −3
Original line number Diff line number Diff line
@@ -5,10 +5,11 @@ def crossform(a):
    """
    Convert a three element vector into a 3 x 3 skew matrix as per
    Hartley and Zisserman pg. 581

    """
    return np.array([[0, -a[2], a[1]],
                     [a[2], 0, -a[0]],
                     [-a[1], a[0], 0]])
    return np.array([[0, a[2], -a[1]],
                     [-a[2], 0, a[0]],
                     [a[1], -a[0], 0]])

def normalize(a):
    """
+3 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import warnings
import numpy as np
import pandas as pd
import pytest
from shapely.geometry import Polygon
from shapely.geometry import LinearRing


from autocnet.examples import get_path
@@ -178,5 +178,6 @@ class TestNode(object):

    def test_footprint(self, geo_node, node_a):
        # Esnure that a shapely compliant poly is being returned
        assert isinstance(geo_node.footprint, Polygon)
        print(geo_node.footprint)
        assert isinstance(geo_node.footprint, LinearRing)
        assert node_a.footprint == None
Loading