예제 #1
0
    def test_match_multiple_solutions(self):
        left_box_frame_1 = Interval(Bounds3D(1, 1, 0.1, 0.4, 0.4, 0.8))
        right_box_frame_1 = Interval(Bounds3D(1, 1, 0.6, 0.9, 0.3, 0.7))
        bottom_left_box_frame_2 = Interval(Bounds3D(2, 2, 0.1, 0.3, 0.8, 0.9))
        top_right_box_frame_2 = Interval(Bounds3D(2, 2, 0.5, 0.7, 0.2, 0.7))
        is1 = IntervalSet([
            left_box_frame_1,
            right_box_frame_1,
            bottom_left_box_frame_2,
            top_right_box_frame_2,
            Interval(Bounds3D(3, 3)),
        ])

        pattern = [
            (
                ["left", "right"],
                [
                    # Two boxes on left and right on same frame
                    Bounds3D.T(equal()),
                    Bounds3D.XY(left_of()),
                ]),
        ]
        results = is1.match(pattern, exact=False)
        self.assertEqual(len(results), 2)

        # Add single interval constraints.
        pattern = pattern + [
            (["left"], [Bounds3D.XY(height_at_least(0.3))]),
            (["right"], [Bounds3D.XY(height_at_least(0.3))]),
        ]
        results = is1.match(pattern, exact=False)
        self.assertEqual(len(results), 1)
        result = results[0]
        self.assertIntervalsEq(left_box_frame_1, result['left'])
        self.assertIntervalsEq(right_box_frame_1, result['right'])
예제 #2
0
    def test_match(self):
        left_box_frame_1 = Interval(Bounds3D(1, 1, 0.1, 0.4, 0.4, 0.8))
        right_box_frame_1 = Interval(Bounds3D(1, 1, 0.6, 0.9, 0.3, 0.7))
        bottom_left_box_frame_2 = Interval(Bounds3D(2, 2, 0.1, 0.3, 0.8, 0.9))
        top_right_box_frame_2 = Interval(Bounds3D(2, 2, 0.5, 0.7, 0.2, 0.7))
        is1 = IntervalSet([
            left_box_frame_1, right_box_frame_1, bottom_left_box_frame_2,
            top_right_box_frame_2
        ])

        pattern = [
            (
                ["left", "right"],
                [
                    # Two boxes on left and right on same frame
                    Bounds3D.T(equal()),
                    Bounds3D.XY(left_of()),
                ]),
            (
                ["top", "bottom"],
                [
                    # Two boxes on top and bottom on overlapping frame
                    Bounds3D.T(equal()),
                    Bounds3D.XY(above()),
                ]),
            (
                ["left", "top"],
                [
                    # Left-Right pattern comes before Top-Bottom
                    Bounds3D.T(meets_before(epsilon=1))
                ])
        ]
        results = is1.match(pattern, exact=True)
        self.assertEqual(len(results), 1)
        result = results[0]
        self.assertIntervalsEq(left_box_frame_1, result['left'])
        self.assertIntervalsEq(right_box_frame_1, result['right'])
        self.assertIntervalsEq(top_right_box_frame_2, result['top'])
        self.assertIntervalsEq(bottom_left_box_frame_2, result['bottom'])