Python util.load_image() Examples

The following are 4 code examples of util.load_image(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module util , or try the search function .
Example #1
Source File: get_centers.py    From region-ensemble-network with GNU General Public License v2.0 6 votes vote down vote up
def main():
    if len(sys.argv) < 4:
        print_usage()

    dataset = sys.argv[1]
    base_dir = sys.argv[2]
    out_file = sys.argv[3]
    names = util.load_names(dataset)
    centers = []
    for idx, name in enumerate(names):
        if dataset == 'nyu':  # use synthetic image to compute center
            name = name.replace('depth', 'synthdepth')
        img = util.load_image(dataset, os.path.join(base_dir, name))
        if dataset == 'icvl':
            center = util.get_center(img, upper=500, lower=0)
        elif dataset == 'nyu':
            center = util.get_center(img, upper=1300, lower=500)
        elif dataset == 'msra':
            center = util.get_center(img, upper=1000, lower=10)
        centers.append(center.reshape((1, 3)))
        if idx % 500 == 0:
            print('{}/{}'.format(idx + 1, len(names)))
    util.save_results(centers, out_file) 
Example #2
Source File: show_result.py    From region-ensemble-network with GNU General Public License v2.0 6 votes vote down vote up
def show_pose(dataset_model, dataset_image, base_dir, outputs, list_file, save_dir,
        is_flip, gif):
    if list_file is None:
        names = util.load_names(dataset_image)
    else:
        with open(list_file) as f:
            names = [line.strip() for line in f]
    assert len(names) == outputs.shape[0]

    for idx, (name, pose) in enumerate(zip(names, outputs)):
        img = util.load_image(dataset_image, os.path.join(base_dir, name),
                is_flip=is_flip)
        img = img.astype(np.float32)
        img = (img - img.min()) / (img.max() - img.min()) * 255
        img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
        img = util.draw_pose(dataset_model, img, pose) 
        cv2.imshow('result', img / 255)
        if save_dir is not None:
            cv2.imwrite(os.path.join(save_dir, '{:>06d}.png'.format(idx)), img)
        ch = cv2.waitKey(25)
        if ch == ord('q'):
            break

    if gif and save_dir is not None:
        os.system('convert -loop 0 -page +0+0 -delay 25 {0}/*.png {0}/output.gif'.format(save_dir)) 
Example #3
Source File: data.py    From DeepIllumination with MIT License 5 votes vote down vote up
def __getitem__(self, index):
        albedo = load_image(join(self.albedo_path, self.image_filenames[index]))
        depth = load_image(join(self.depth_path, self.image_filenames[index]))
        direct = load_image(join(self.direct_path, self.image_filenames[index]))
        normal = load_image(join(self.normal_path, self.image_filenames[index]))
        gt = load_image(join(self.gt_path, self.image_filenames[index]))
        return albedo, direct, normal, depth, gt 
Example #4
Source File: hand_model.py    From region-ensemble-network with GNU General Public License v2.0 5 votes vote down vote up
def detect_files(self, base_dir, names, centers=None, dataset=None, max_batch=64, is_flip=False):
        assert max_batch > 0
        if dataset is None:
            dataset = self._dataset

        batch_imgs = []
        batch_centers = []
        results = []
        for idx, name in enumerate(names):
            img = util.load_image(dataset, os.path.join(base_dir, name),
                    is_flip=is_flip)
            batch_imgs.append(img)
            if centers is None:
                batch_centers.append(self._center_loader(img))
            else:
                batch_centers.append(centers[idx, :])

            if len(batch_imgs) == max_batch:
                for line in self.detect_images(batch_imgs, batch_centers):
                    results.append(line)
                del batch_imgs[:]
                del batch_centers[:]
                print('{}/{}'.format(idx + 1, len(names)))
        if batch_imgs:
            for line in self.detect_images(batch_imgs, batch_centers):
                results.append(line)
        print('done!')
        return np.array(results)