Esempio n. 1
0
def get_edgeboxes_test(img_id, top_num):
    try:
        raw_boxes = sio.loadmat(
            os.path.join(ENV_PATHS.EDGEBOX_PATH,
                         str(img_id) + '.mat'))['bbs'][0:top_num, :]
    except:
        import edge_boxes
        raw_boxes_ = edge_boxes.get_windows([img_id])[0][0:top_num, :]
        raw_boxes = np.zeros(raw_boxes_.shape)
        raw_boxes[:, 0] = raw_boxes_[:, 1]
        raw_boxes[:, 1] = raw_boxes_[:, 0]
        raw_boxes[:, 2] = raw_boxes_[:, 3] - raw_boxes_[:, 1] + 1
        raw_boxes[:, 3] = raw_boxes_[:, 2] - raw_boxes_[:, 0] + 1

    edge_boxes = np.zeros((0, 4))
    edge_boxes = np.concatenate((edge_boxes, raw_boxes[:, 0:4]))
    return edge_boxes
def demo(net, image_name, classes):
    """Detect object classes in an image using pre-computed object proposals."""

    # Load the demo image
    im_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo', image_name + '.jpg')
    im = cv2.imread(im_file)
    
    # Compute EdgeBoxes proposals
    image_filenames = [ im_file ] 
    initial_boxes = get_windows(image_filenames);
    
    # Get just the boxes, without the EdgeBoxes confidence scores
    obj_proposals = (initial_boxes[0])[:, [0,1,2,3]]
    
    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(net, im, obj_proposals)
    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 in classes:
        cls_ind = CLASSES.index(cls)
        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 'All {} detections with p({} | box) >= {:.1f}'.format(cls, cls,
                                                                    CONF_THRESH)
        vis_detections(im, cls, dets, thresh=CONF_THRESH)
Esempio n. 3
0
import edge_boxes as edges
windows = edges.get_windows(['/home/zawlin/data/indoor.jpg'])
print windows
Esempio n. 4
0
#		Why?  Of the 15 seconds, something like 14.5 of them are "waiting for Matlab to load".  Only
#		0.5 of them are doing work.  If you have to loop over 400 images, waiting 14.5 seconds per image
#		(for Matlab to load) adds up to something like 100 minutes.  If you call the edge_boxes function
#		once (with paths to all 400 images), it only takes 3 minutes to run on ecegrid.
# 		SO... again my advice: develop your code by passing in a single image (since waiting 15 seconds
#		is better than waiting 3 minutes).  Then, when you're ready to run your code on the entire
#		directory of images, tweak your code to call edge_boxes once.
# NOTE:	When I had finished coding and was ready to run my code on the entire directory of images,
#		it took ~15 minutes from beginning to end.  Each directory of images (4 total) took ~3 minutes
#		for edge_boxes to run and ~1.5 minutes for the discovery, sorting, and saving of pos/neg images.
#		What can you do while you wait 15 minutes for your code to complete?  Start working on phase2!
#################################################################################################
#imageFileNames = []
#imageFileNames.append(imageDir + "/n02119789_122.JPEG")
#imageFileNames.append(imageDir + "/n02119789_257.JPEG")
windows = edge_boxes.get_windows(imageFileNames)
#print(windows[1])
pos_num = 1
neg_num = 1
for i in range(len(imageFileNames)):
    orig_image = cv2.imread(imageFileNames[i])
    neg = 0  # count how many negative proposal
    pos = 0  # count how many positive proposal
    boxnum = 0
    loop_num = 0
    tree = ET.parse(annotationFileName[i])  # ground truth
    objs_ground = tree.findall('object')  # ground truth
    #iou_his = []
    while (pos < 5 and neg < 5):  # for each image
        loop_num = loop_num + 1
        iou_his = []
Esempio n. 5
0
num = 0
w = []
ka = "/home/min/a/prachapu/ee570/hw3/"
while True:
    line = f.readline()
    if not line:
        break
    l = line.split()
    pa = l[0][2:]
    l[0] = ka + pa
    #	print line, l
    #	print l
    print(l[0])
    w = []
    w.append(l[0])
    windows = edge_boxes.get_windows(w)
    windows = numpy.array(windows)
    image = cv2.imread(l[0])
    #	cv2.imshow('image',image)
    #	cv2.waitKey(0)
    #print windows
    prop_ctr = 0
    best = -1
    result = []
    store = []
    for u in xrange(0, 4):
        result.append(0)
        store.append([])
    for proposals in windows:
        for boxes in proposals:
            p = []