Exemple #1
0
def demo(sess, net, image_name):
    """Detect object classes in an image using pre-computed object proposals."""

    # Load the demo image
    im_file = os.path.join(cfg.DATA_DIR, 'demo', image_name)
    im = cv2.imread(im_file)

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(sess, net, im)
    timer.toc()
    print('Detection took {:.3f}s for {:d} object proposals'.format(
        timer.total_time, boxes.shape[0]))

    # Visualize detections for each class
    CONF_THRESH = 0.8
    NMS_THRESH = 0.3
    for cls_ind, cls in enumerate(CLASSES[1:]):
        cls_ind += 1  # because we skipped background
        cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack(
            (cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32)
        keep = nms(dets, NMS_THRESH)
        dets = dets[keep, :]
        vis_detections(im, cls, dets, thresh=CONF_THRESH)
Exemple #2
0
def camdemo(sess, net, im, resize=(500, 375)):
    #Resize iamge so it fullfills the requirements needed by Faster-RCNN
    im = cv2.resize(im, resize)

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(sess, net, im)
    timer.toc()
    #    print('Detection took {:.3f}s for {:d} object proposals'.format(timer.total_time, boxes.shape[0]))

    #    return scores,boxes
    # Visualize detections for each class
    CONF_THRESH = 0.8
    NMS_THRESH = 0.3
    boxess = []
    classes = []
    for cls_ind, cls in enumerate(CLASSES[1:]):
        cls_ind += 1  # because we skipped background
        cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack(
            (cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32)
        keep = nms(dets, NMS_THRESH)
        dets = dets[keep, :]
        #	print(cls,dets)
        #	Threshing(cls,dets,thresh=CONF_THRESH)
        Img, box, CLASS = vis_detectionOnCam(im, cls, dets, thresh=CONF_THRESH)
        boxess.append(box),
        classes.append(CLASS)

    return Img, boxess, classes
Exemple #3
0
def demo(sess, net, image_name):
    """Detect object classes in an image using pre-computed object proposals."""

    # Load the demo image
    im_file = os.path.join(cfg.DATA_DIR, image_name)
    im = cv2.imread(im_file)
    print('bg img', im.shape)

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(sess, net, im)
    timer.toc()
    print('Detection took {:.3f}s for {:d} object proposals'.format(
        timer.total_time, boxes.shape[0]))

    N = scores.shape[0]  # num of proposals
    C = scores.shape[1] - 1  # num of real classes

    # Visualize detections for each class
    CONF_THRESH = 0.8
    NMS_THRESH = 0.3
    all_boxes_scores = np.zeros((N * C, 5), dtype=np.float32)

    print(len(CLASSES), all_boxes_scores.shape)

    for cls_ind, cls in enumerate(CLASSES[1:]):
        cls_ind += 1  # because we skipped background
        cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack(
            (cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32)

        all_boxes_scores[N * (cls_ind - 1):N * cls_ind, :4] = cls_boxes
        all_boxes_scores[N * (cls_ind - 1):N * cls_ind, 4] = cls_scores


#         keep = nms(dets, NMS_THRESH)
#         dets = dets[keep, :]
#         print('for class %d(%s) remain %d bboxes' % (cls_ind, cls, len(keep)))
#         vis_detections(im, cls, dets, thresh=CONF_THRESH)

    keep = nms(all_boxes_scores, NMS_THRESH)
    dets = all_boxes_scores[keep, :]
    idx_cls = [i // N + 1 for i in keep]
    print('it remains %d bboxes, total %d proposals' %
          (len(dets), len(all_boxes_scores)))
    vis_detections_all(im, dets, idx_cls, thresh=CONF_THRESH)
Exemple #4
0
def recognize(sess, net, im):
    """Detect object classes in an image using pre-computed object proposals."""

    print('img size:', im.shape)

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(sess, net, im)
    timer.toc()
    print('Detection took {:.3f}s for {:d} object proposals'.format(
        timer.total_time, boxes.shape[0]))

    N = scores.shape[0]  # num of proposals
    C = scores.shape[1] - 1  # num of real classes

    # Visualize detections for each class
    CONF_THRESH = 0.8
    NMS_THRESH = 0.3
    all_boxes_scores = np.zeros((N * C, 5), dtype=np.float32)

    print(len(CLASSES), all_boxes_scores.shape)

    for cls_ind, cls in enumerate(CLASSES[1:]):
        cls_ind += 1  # because we skipped background
        cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack(
            (cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32)

        all_boxes_scores[N * (cls_ind - 1):N * cls_ind, :4] = cls_boxes
        all_boxes_scores[N * (cls_ind - 1):N * cls_ind, 4] = cls_scores

    keep = nms(all_boxes_scores, NMS_THRESH)
    dets = all_boxes_scores[keep, :]
    idx_cls = [i // N + 1 for i in keep]
    print('for class %d(%s) remain %d bboxes, total %d proposals' %
          (cls_ind, cls, len(dets), len(all_boxes_scores)))

    return dets, idx_cls