예제 #1
0
def detect2(net, meta, image, thresh=.5, hier_thresh=.5, nms=.45):
    boxes = dn.make_boxes(net)
    probs = dn.make_probs(net)
    num =   dn.num_boxes(net)
    dn.network_detect(net, image, thresh, hier_thresh, nms, boxes, probs)
    res = []
    for j in range(num):
        for i in range(meta.classes):
            if probs[j][i] > 0:
                res.append((meta.names[i], probs[j][i], (boxes[j].x, boxes[j].y, boxes[j].w, boxes[j].h)))
    res = sorted(res, key=lambda x: -x[1])
    dn.free_ptrs(dn.cast(probs, dn.POINTER(dn.c_void_p)), num)
    return res
예제 #2
0
 def detect(self, img, thresh=0.1, hier_thresh=.5, nms=.45):
     img = array2image(dn, img)
     boxes = dn.make_boxes(self.net)
     probs = dn.make_probs(self.net)
     num = dn.num_boxes(self.net)
     dn.network_detect(self.net, img, thresh, hier_thresh, nms, boxes,
                       probs)
     res = []
     for j in range(num):
         if probs[j][0] > thresh:
             res.append((probs[j][0], (boxes[j].x, boxes[j].y, boxes[j].w,
                                       boxes[j].h)))
     res = sorted(res, key=lambda x: -x[0])
     dn.free_ptrs(dn.cast(probs, dn.POINTER(dn.c_void_p)), num)
     return res
예제 #3
0
def detect(net, meta, image, thresh=.5, hier_thresh=.5, nms=.45):
    """
	From darknet/python/darknet.py
	"""
    # im = dn.load_image(image, 0, 0)
    im = dn.load_image(image, dn.network_width(net), dn.network_height(net))
    boxes = dn.make_boxes(net)
    probs = dn.make_probs(net)
    num = dn.num_boxes(net)
    dn.network_detect(net, im, thresh, hier_thresh, nms, boxes, probs)
    res = []
    for j in range(num):
        for i in range(meta.classes):
            if probs[j][i] > 0:
                res.append((i, probs[j][i], (boxes[j].x, boxes[j].y,
                                             boxes[j].w, boxes[j].h)))
    res = sorted(res, key=lambda x: -x[1])
    dn.free_image(im)
    dn.free_ptrs(dn.cast(probs, dn.POINTER(dn.c_void_p)), num)
    return res