Exemple #1
0
    def test_SimpleMatchAbsoluteNeighbor(self):
        points, dummy = Utils.getSimplePatterns()

        pointsAsNpArray = np.array(points)
        R = Utils.getRotationMatrix(35 + 180)
        translation = np.array([[0.11, -0.03]])
        points2 = Utils.transform(1.0, R, translation, pointsAsNpArray)

        c = AbsoluteNeighborFitnessComputer(points2, 0.1)
        m = SimulatedAnnealingPointMatcher2D(c)

        Utils.addPointsToAnnealer(points, m)
        m.setSlowMovementBreakpoint(0.75)
        m.setInitialRotationSigma(360)
        m.setInitialTranslationSigma(0.2)
        m.setSlowTranslationSigma(0.1)
        m.setStartTemperature(0.0)
        m.setNumIterations(200)

        scale, rotation, translation, fitness = m.match()

        self.assertAlmostEqual(fitness[0, 0], 0.0)
        self.assertAlmostEqual(scale[0, 0], 1.0)
        numDigits = 1
        self.assertMatrixAlmostEquals(rotation, R, numDigits)
        self.assertMatrixAlmostEquals(translation, translation, numDigits)
Exemple #2
0
    def test_SimpleMatch(self):
        refCloud = np.array([[0.0, 0.0], [0.0, 1.0], [1.0, 1.0]])
        scale = 1.0
        rotation = Utils.getRotationMatrix(90)
        translation = np.array([[1.0, 2.0]])
        matchCloud = Utils.transform(scale, rotation, translation, refCloud)

        c = MeanShortestDistanceFitnessComputer(refCloud)
        m = BruteForceMatcher(c, refCloud)
        m.setCandidateKeepRatio(1)
        scale, rotation, translation, fitness = m.match(matchCloud)

        self.assertAlmostEqual(fitness[0, 0], 0.0)
        self.assertEqual(scale[0, 0], 1.0)
        self.assertAlmostEqual(rotation[0, 0], 0.0)
        self.assertAlmostEqual(rotation[0, 1], 1.0)
        self.assertAlmostEqual(rotation[1, 0], -1.0)
        self.assertAlmostEqual(rotation[1, 1], 0.0)