Пример #1
0
def test_random_with_same_aspect():
    # rect = gm.PixelRectangle.random_with_same_aspect(window_dims, imsize)
    # if not any((rect.intersects_pixelrectangle(pr) for pr in excl_info)):

    # # Test random_with_same_aspect:
    # img_path = neg_regions[0].fname
    # img = cv2.imread(img_path)
    window_dims = (300, 200)
    img = np.zeros((500, 500, 3), np.uint8)
    h, w = img.shape[:2]
    imsize = (w, h)
    rects = []
    for i in range(10000):
        rect = gm.PixelRectangle.random_with_same_aspect(window_dims, imsize)
        rects.append(rect)
        clone = img.copy()
        training.cvDrawRectangle(clone, rect, (255, 0, 0), 2)

        # Test moved_to_clear:
        new_rect = gm.PixelRectangle.random_with_same_aspect(window_dims, imsize)
        training.cvDrawRectangle(clone, new_rect, (0, 255, 0), 2)
        moved_rect = new_rect.moved_to_clear(rect)
        training.cvDrawRectangle(clone, moved_rect, (0, 0, 255), 2)
        print rect.intersects_pixelrectangle(moved_rect)

        # Test intersects_pixelrectangle:
        # for i in range(200):
        #     new_rect = gm.PixelRectangle.random_with_same_aspect(window_dims, imsize)
        #     col = (0, 0, 255) if rect.intersects_pixelrectangle(new_rect) else (255, 255, 255)
        #     if not rect.intersects_pixelrectangle(new_rect):
        #         training.cvDrawRectangle(clone, new_rect, col, 2)

        cv2.imshow("img", clone)
        while True:
            key = cv2.waitKey(1) & 0xFF
            # if key == 27: # ESC key
            #     cv2.destroyAllWindows()
            #     return
            if key != 255:
                break

    print "Saving histogram..."
    from cardetection.carutils.plotting import saveHistogram

    aspects = map(lambda r: r.w, rects)
    saveHistogram("region-aspects.pdf", aspects, bins=20)
    print "Saved!"
Пример #2
0
def test_random_with_same_aspect():
    # rect = gm.PixelRectangle.random_with_same_aspect(window_dims, imsize)
    # if not any((rect.intersects_pixelrectangle(pr) for pr in excl_info)):

    # # Test random_with_same_aspect:
    # img_path = neg_regions[0].fname
    # img = cv2.imread(img_path)
    window_dims = (300, 200)
    img = np.zeros((500, 500, 3), np.uint8)
    h, w = img.shape[:2]
    imsize = (w, h)
    rects = []
    for i in range(10000):
        rect = gm.PixelRectangle.random_with_same_aspect(window_dims, imsize)
        rects.append(rect)
        clone = img.copy()
        training.cvDrawRectangle(clone, rect, (255, 0, 0), 2)

        # Test moved_to_clear:
        new_rect = gm.PixelRectangle.random_with_same_aspect(
            window_dims, imsize)
        training.cvDrawRectangle(clone, new_rect, (0, 255, 0), 2)
        moved_rect = new_rect.moved_to_clear(rect)
        training.cvDrawRectangle(clone, moved_rect, (0, 0, 255), 2)
        print rect.intersects_pixelrectangle(moved_rect)

        # Test intersects_pixelrectangle:
        # for i in range(200):
        #     new_rect = gm.PixelRectangle.random_with_same_aspect(window_dims, imsize)
        #     col = (0, 0, 255) if rect.intersects_pixelrectangle(new_rect) else (255, 255, 255)
        #     if not rect.intersects_pixelrectangle(new_rect):
        #         training.cvDrawRectangle(clone, new_rect, col, 2)

        cv2.imshow('img', clone)
        while True:
            key = cv2.waitKey(1) & 0xFF
            # if key == 27: # ESC key
            #     cv2.destroyAllWindows()
            #     return
            if key != 255:
                break

    print 'Saving histogram...'
    from cardetection.carutils.plotting import saveHistogram
    aspects = map(lambda r: r.w, rects)
    saveHistogram('region-aspects.pdf', aspects, bins=20)
    print 'Saved!'
Пример #3
0
    # for img_path in training.sampleTrainingImages(positive_dir, ['.*'], None, require_bboxes=True, bbinfo_dir=bbinfo_dir):
    #     key = img_path.split('/')[-1]
    #     rects_str = global_info[key]
    #     rects = utils.rectangles_from_cache_string(rects_str)
    #     for rect in rects:
    #         all_rects.append(rect)
    #
    #
    # aspects = map(lambda rect: rect.h/float(rect.w), all_rects)

    kitti_base = '/Users/mitchell/data/kitti/'
    category_types = ['Car', 'Van']
    pos_labels = kitti.getPositiveImageLabels(kitti_base, category_types)

    aspects = map(lambda l: l.aspect, pos_labels)
    saveHistogram('aspects.pdf', aspects)
    plt.close()

    # angles = map(lambda l: l.alpha*180.0/np.pi, pos_labels)
    angles = map(lambda l: l.ry * 180.0 / np.pi, pos_labels)
    # angles = map(lambda l: l.ry, pos_labels)
    saveHistogram('angles.pdf', angles)

    shape = (64, 64)
    aspect = shape[0] / float(shape[1])
    angle = -90
    angleRange = 5
    aspectRange = 0.5

    filtered = pos_labels
    filtered = filter(
Пример #4
0
    # for img_path in training.sampleTrainingImages(positive_dir, ['.*'], None, require_bboxes=True, bbinfo_dir=bbinfo_dir):
    #     key = img_path.split('/')[-1]
    #     rects_str = global_info[key]
    #     rects = utils.rectangles_from_cache_string(rects_str)
    #     for rect in rects:
    #         all_rects.append(rect)
    #
    #
    # aspects = map(lambda rect: rect.h/float(rect.w), all_rects)

    kitti_base = '/Users/mitchell/data/kitti/'
    category_types = ['Car', 'Van']
    pos_labels = kitti.getPositiveImageLabels(kitti_base, category_types)

    aspects = map(lambda l: l.aspect, pos_labels)
    saveHistogram('aspects.pdf', aspects)
    plt.close()

    # angles = map(lambda l: l.alpha*180.0/np.pi, pos_labels)
    angles = map(lambda l: l.ry*180.0/np.pi, pos_labels)
    # angles = map(lambda l: l.ry, pos_labels)
    saveHistogram('angles.pdf', angles)

    shape = (64, 64)
    aspect = shape[0]/float(shape[1])
    angle = -90
    angleRange = 5
    aspectRange = 0.5

    filtered = pos_labels
    filtered = filter(lambda l: abs(l.ry*180.0/np.pi - angle) < angleRange/2.0, filtered)