def test_intersect2(self):
     bflt = bbox.BBox(0.96, 0.49, 1.2, 0.64)
     bflt.intersect(bbox.BBox(0.0, 0.0, 1.0, 1.0))
     self.assertAlmostEqual(bflt.xmin, 0.96, places=5)
     self.assertAlmostEqual(bflt.ymin, 0.49, places=5)
     self.assertAlmostEqual(bflt.xmax, 1.0, places=5)
     self.assertAlmostEqual(bflt.ymax, 0.64, places=5)
 def test_normalize_to_outer_box(self):
     # test bflt
     self.bflt.normalize_to_outer_box(bbox.BBox(0, 0, 3.0, 2.0))
     self.assertAlmostEqual(self.bflt.xmin, 0.2/3.0, places=5)
     self.assertAlmostEqual(self.bflt.ymin, 0.3/2.0, places=5)
     self.assertAlmostEqual(self.bflt.xmax, 0.5/3.0, places=5)
     self.assertAlmostEqual(self.bflt.ymax, 0.6/2.0, places=5)
     # test bint
     self.bint.normalize_to_outer_box(bbox.BBox(50, 10, 80, 60))
     self.assertAlmostEqual(self.bint.xmin, 10.0/30.0, places=5)
     self.assertAlmostEqual(self.bint.ymin, 20.0/50.0, places=5)
     self.assertAlmostEqual(self.bint.xmax, 50.0/30.0, places=5)
     self.assertAlmostEqual(self.bint.ymax, 40.0/50.0, places=5)
示例#3
0
def detect_objects(img_read):
    ''' returns list of classes detected and corresponding bounding boxes '''

    image = cv2.imread(img_read)

    Width = image.shape[1]
    Height = image.shape[0]
    scale = 0.00392

    classes = None

    with open(classes_dir, 'r') as f:
        classes = [line.strip() for line in f.readlines()]

    COLORS = np.random.uniform(0, 255, size=(len(classes), 3))

    net = cv2.dnn.readNet(weights, config)

    blob = cv2.dnn.blobFromImage(image,
                                 scale, (416, 416), (0, 0, 0),
                                 True,
                                 crop=False)

    net.setInput(blob)

    outs = net.forward(get_output_layers(net))

    class_ids = []
    confidences = []
    boxes = []
    conf_threshold = 0.5
    nms_threshold = 0.4

    for out in outs:
        for detection in out:
            scores = detection[5:]
            class_id = np.argmax(scores)
            confidence = scores[class_id]
            if confidence > 0.5:
                center_x = int(detection[0] * Width)
                center_y = int(detection[1] * Height)
                w = int(detection[2] * Width)
                h = int(detection[3] * Height)
                x = center_x - w / 2
                y = center_y - h / 2
                class_ids.append(class_id)
                confidences.append(float(confidence))
                boxes.append([x, y, w, h])

    class_list = []
    bbox_list = []

    for class_indx in class_ids:
        class_list.append(str(classes[class_indx]))

    for box in boxes:
        bbox_list.append(bbox.BBox(box[0], box[1], box[2], box[3]))

    return class_list, confidences, bbox_list
 def test_non_maxima_suppression(self):
     # empty case
     bb = bbox.BBox.non_maxima_suppression([], 0.5)
     self.assertEqual(bb, [])
     # None case
     bb = bbox.BBox.non_maxima_suppression(None, 0.5)
     self.assertEqual(bb, [])
     # 1-bbox case
     bboxes = [bbox.BBox(0.6, 0.8, 0.7, 0.9, confidence=0.5)]
     bb = bbox.BBox.non_maxima_suppression(bboxes, 0.5)
     self.assertEqual(len(bb), 1)
     self.assertEqual(bb[0].xmin, 0.6)
     self.assertEqual(bb[0].ymin, 0.8)
     self.assertEqual(bb[0].xmax, 0.7)
     self.assertEqual(bb[0].ymax, 0.9)
     self.assertEqual(bb[0].confidence, 0.5)
     # 3-bboxes example
     bboxes = [bbox.BBox(0.6, 0.8, 0.7, 0.9, confidence=0.5), \
               bbox.BBox(0.6, 0.8, 0.7, 0.95, confidence=0.1), \
               bbox.BBox(0.6, 0.8, 0.75, 0.9, confidence=0.7), \
               bbox.BBox(0.1, 0.2, 0.4, 0.9, confidence=0.8) ]
     # threshold 0.3
     bb = bbox.BBox.non_maxima_suppression(bboxes, 0.3)
     self.assertEqual(len(bboxes), 4)
     self.assertEqual(bboxes[0].confidence, 0.5)
     self.assertEqual(bboxes[1].confidence, 0.1)
     self.assertEqual(bboxes[2].confidence, 0.7)
     self.assertEqual(bboxes[3].confidence, 0.8)
     self.assertEqual(len(bb), 2)
     self.assertEqual(bb[0].confidence, 0.8)
     self.assertEqual(bb[0].xmax, 0.4)
     self.assertEqual(bb[1].confidence, 0.7)
     self.assertEqual(bb[1].xmax, 0.75)
     # threshold 1.0 (i.e. there is no NMS at all)
     bb = bbox.BBox.non_maxima_suppression(bboxes, 1.0)
     self.assertEqual(len(bboxes), 4)
     self.assertEqual(bboxes[0].confidence, 0.5)
     self.assertEqual(bboxes[1].confidence, 0.1)
     self.assertEqual(bboxes[2].confidence, 0.7)
     self.assertEqual(bboxes[3].confidence, 0.8)
     self.assertEqual(len(bb), 4)
     self.assertEqual(bb[0].confidence, 0.8)
     self.assertEqual(bb[1].confidence, 0.7)
     self.assertEqual(bb[2].confidence, 0.5)
     self.assertEqual(bb[3].confidence, 0.1)
 def test_intersect(self):
     # test bflt
     self.bflt.intersect(bbox.BBox(0.15, 0.4, 0.35, 0.7))
     self.assertAlmostEqual(self.bflt.xmin, 0.2, places=5)
     self.assertAlmostEqual(self.bflt.ymin, 0.4, places=5)
     self.assertAlmostEqual(self.bflt.xmax, 0.35, places=5)
     self.assertAlmostEqual(self.bflt.ymax, 0.6, places=5)
     # test bint
     self.bint.intersect(bbox.BBox(50, 10, 80, 60))
     self.assertAlmostEqual(self.bint.xmin, 60, places=5)
     self.assertAlmostEqual(self.bint.ymin, 30, places=5)
     self.assertAlmostEqual(self.bint.xmax, 80, places=5)
     self.assertAlmostEqual(self.bint.ymax, 50, places=5)
     # intersect 2 bbox (that do not have intesection)
     self.bflt.intersect(bbox.BBox(0.6, 0.8, 0.7, 0.9))
     self.assertAlmostEqual(self.bflt.xmin, 0.0, places=5)
     self.assertAlmostEqual(self.bflt.ymin, 0.0, places=5)
     self.assertAlmostEqual(self.bflt.xmax, 0.0, places=5)
     self.assertAlmostEqual(self.bflt.ymax, 0.0, places=5)
    def test_jaccard_similarity(self):
        s = self.bint.jaccard_similarity(bbox.BBox(70, 40, 120, 65))
        self.assertEqual(s, 300 / float(40*20 + 50*25 - 300))

        s = self.bflt.jaccard_similarity(bbox.BBox(0.6, 0.8, 0.7, 0.9))
        self.assertEqual(s, 0.0)
 def setUp(self):
     self.bflt = bbox.BBox(0.2, 0.3, 0.5, 0.6, 0.1)
     self.bint = bbox.BBox(60, 30, 100, 50)
示例#8
0
plane.pitch(radians(-90))
plane.setEffect("colored -d gray")

# Create first light
light1 = Light.create()
light1.setColor(Color(1, 0.8, 0.8, 1))
light1.setPosition(Vector3(0, 0, -4))
light1.setEnabled(True)

# Create second light
light2 = Light.create()
light2.setColor(Color(0.8, 0.8, 0.1, 1))
light2.setPosition(Vector3(0, 4, -4))
light2.setLightType(LightType.Spot)
light2.setLightDirection(Vector3(0, -1, 0))
light2.setSpotCutoff(30)
light2.setSpotExponent(20)
light2.setEnabled(True)


# Spin the box!
def onUpdate(frame, t, dt):
    torus.pitch(dt)
    torus.yaw(dt / 3)


setUpdateFunction(onUpdate)

import bbox
bbox.BBox(torus)