Example #1
0
    def _draw_contour_impl(self, bitmap, color=None, thickness=1, config=None):
        if config is not None:
            # If a config with edges and colors is passed, make sure it is
            # consistent with the our set of points.
            self.validate(self.geometry_name(), config)

        # Draw edges first so that nodeas are then drawn on top.
        for edge in self._get_nested_or_default(config, [EDGES], []):
            src = self._nodes.get(edge[SRC], None)
            dst = self._nodes.get(edge[DST], None)
            if (src is not None) and (not src.disabled) and (
                    dst is not None) and (not dst.disabled):
                edge_color = edge.get(COLOR, color)
                cv2.line(bitmap, (src.location.col, src.location.row),
                         (dst.location.col, dst.location.row),
                         tuple(edge_color), thickness)

        nodes_config = self._get_nested_or_default(config, [NODES])
        for node_id, node in self._nodes.items():
            if not node.disabled:
                effective_color = self._get_nested_or_default(
                    nodes_config, [node_id, COLOR], color)
                Point.from_point_location(node.location).draw(
                    bitmap=bitmap,
                    color=effective_color,
                    thickness=thickness,
                    config=None)
Example #2
0
 def to_bbox(self):
     '''
     The function to_bbox create Rectangle class object from current GraphNodes class object
     :return: Rectangle class object
     '''
     return Rectangle.from_geometries_list(
         [Point.from_point_location(node.location) for node in self._nodes.values()])
Example #3
0
 def test_from_json(self):
     packed_obj = {
         'some_stuff': 'aaa',
         POINTS: {
             EXTERIOR: [[17, 3]],
             INTERIOR: []
         }
     }
     res_point = Point.from_json(packed_obj)
     self.assertIsInstance(res_point, Point)
     self.assertEqual(res_point.row, 3)
     self.assertEqual(res_point.col, 17)
Example #4
0
 def setUp(self):
     self.point = Point(row=10,  col=5)
Example #5
0
class PointTest(unittest.TestCase):
    def setUp(self):
        self.point = Point(row=10,  col=5)

    def assertPointEquals(self, point, row, col):
        self.assertIsInstance(point, Point)
        self.assertEqual(point.row, row)
        self.assertEqual(point.col, col)

    def test_empty_crop(self):
        crop_rect = Rectangle(100, 100, 200, 200)
        res_geoms = self.point.crop(crop_rect)
        self.assertEqual(len(res_geoms), 0)

    def test_crop(self):
        crop_rect = Rectangle(0, 0, 100, 100)
        res_geoms = self.point.crop(crop_rect)
        self.assertEqual(len(res_geoms), 1)
        res_point = res_geoms[0]
        self.assertPointEquals(res_point, self.point.row, self.point.col)

    def test_relative_crop(self):
        crop_rect = Rectangle(5, 5, 100, 100)
        res_geoms = self.point.relative_crop(crop_rect)
        self.assertEqual(len(res_geoms), 1)
        res_point = res_geoms[0]
        self.assertPointEquals(res_point, 5, 0)

    def test_rotate(self):
        rotator = ImageRotator((21, 21), 90)  # Center pixel is (10, 10)
        rot_point = self.point.rotate(rotator)
        self.assertPointEquals(rot_point, 15, 10)

    def test_resize(self):
        in_size = (20, 40)
        out_size = (30, KEEP_ASPECT_RATIO)
        res_point = self.point.resize(in_size, out_size)
        self.assertPointEquals(res_point, 15, 8)

    def test_scale(self):
        factor = 2.7
        res_point = self.point.scale(factor)
        self.assertPointEquals(res_point, 27, 14)

    def test_translate(self):
        drow = 21
        dcol = -9
        res_point = self.point.translate(drow=drow, dcol=dcol)
        self.assertPointEquals(res_point, 31, -4)

    def test_fliplr(self):
        imsize = (110, 100)
        res_point = self.point.fliplr(imsize)
        self.assertPointEquals(res_point, self.point.row, 95)

    def test_flipud(self):
        imsize = (90, 100)
        res_point = self.point.flipud(imsize)
        self.assertPointEquals(res_point, 80, self.point.col)

    def test_area(self):
        area = self.point.area
        self.assertIsInstance(area, float)
        self.assertEqual(area, 0.0)

    def test_to_bbox(self):
        rect = self.point.to_bbox()
        self.assertPointEquals(self.point, rect.top, rect.left)
        self.assertPointEquals(self.point, rect.bottom, rect.right)

    def test_clone(self):
        res_point = self.point.clone()
        self.assertPointEquals(res_point, self.point.row, self.point.col)
        self.assertIsNot(res_point, self.point)

    def test_from_json(self):
        packed_obj = {
            'some_stuff': 'aaa',
            POINTS: {
                EXTERIOR: [[17, 3]],
                INTERIOR: []
            }
        }
        res_point = Point.from_json(packed_obj)
        self.assertIsInstance(res_point, Point)
        self.assertEqual(res_point.row, 3)
        self.assertEqual(res_point.col, 17)

    def test_to_json(self):
        res_obj = self.point.to_json()
        expected_dict = {
            POINTS: {
                EXTERIOR: [[5, 10]],
                INTERIOR: []
            }
        }
        self.assertDictEqual(res_obj, expected_dict)
Example #6
0
 def to_bbox(self):
     return Rectangle.from_geometries_list([
         Point.from_point_location(node.location)
         for node in self._nodes.values()
     ])