示例#1
0
def get_img(src, img_size=False):
    img = imageio.imread(src)  # misc.imresize(, (256, 256, 3))
    if not (len(img.shape) == 3 and img.shape[2] == 3):
        img = np.dstack((img, img, img))
    if img_size != False:
        img = imageio.imresize(img, img_size)
    return img
示例#2
0
def compile_frames_to_gif(frame_dir, gif_file):
    frames = sorted(glob.glob(os.path.join(frame_dir, "*.png")))
    print(frames)
    images = [
        imageio.imresize(imageio.imread(f), interp='nearest', size=0.33)
        for f in frames
    ]
    imageio.imsave(gif_file, images, duration=0.2)
    return gif_file
示例#3
0
    def __call__(self, image, boxes=None, tags=None):
        ori_h, ori_w, _ = image.shape

        new_image = imageio.imresize(image.copy(), (self.width, self.heigth))
        if boxes is not None:
            boxes[:, :, 0] *= self.width * 1.0 / ori_w
            boxes[:, :, 1] *= self.heigth * 1.0 / ori_h
            boxes[:, :, 0] = np.clip(boxes[:, :, 0], 0, self.width)
            boxes[:, :, 1] = np.clip(boxes[:, :, 1], 0, self.heigth)
        return new_image, boxes, tags
示例#4
0
def split(path):
    x = []
    y = []
    count = 0
    output = 0

    owd = os.getcwd()
    os.chdir(path)

    for video_class in os.listdir(os.getcwd()):
        print(video_class)
        gesture = os.listdir(os.path.join(path, video_class))
        for class_i in gesture:
            sub_child = os.listdir(os.path.join(path, video_class, class_i))
            for file in sub_child:
                if video_class == 'beer':
                    if count % 4 == 0:
                        image = imread(
                            os.path.join(path, video_class, class_i, file))
                        image = imresize(image, (224, 224))
                        x.append(image)
                        y.append(output)
                        cv2.imwrite(
                            os.path.join(path, video_class,
                                         str(count) + '_' + file), image)

                else:
                    if count % 8 == 0:
                        image = imread(
                            os.path.join(path, video_class, class_i, file))
                        image = imresize(image, (224, 224))
                        x.append(image)
                        y.append(output)
                        cv2.imwrite(
                            path + '/' + video_class + '/' + str(count) + '_' +
                            file, image)
                count += 1
            output += 1
    x = np.array(x)
    y = np.array(y)
    print("x", len(x), "y", len(y))
    os.chdir(owd)
def save_lip_images(image_path, samples, out_dir):
    img_A = imageio.imread(image_path).astype(np.float)
    rows = img_A.shape[0]
    cols = img_A.shape[1]
    image = samples[0]
    img_split = image_path.split('/')
    img_id = img_split[-1][:-4]
    with open('{}/{}.txt'.format(out_dir, img_id), 'w') as f:
        for p in range(image.shape[2]):
            channel_ = image[:,:,p]
            if channel_.shape[0] != rows or channel_.shape[1] != cols:
                print ('sizes do not match...')
                channel_ = imageio.imresize(channel_, [rows, cols], interp='nearest')
            r_, c_ = np.unravel_index(channel_.argmax(), channel_.shape)
            f.write('%d %d ' % (int(c_), int(r_)))
示例#6
0
def load_image(filename, size=None):
    """Load and resize an image from disk.

    Inputs:
    - filename: path to file
    - size: size of shortest dimension after rescaling
    """
    img = imread(filename)
    if size is not None:
        orig_shape = np.array(img.shape[:2])
        min_idx = np.argmin(orig_shape)
        scale_factor = float(size) / orig_shape[min_idx]
        new_shape = (orig_shape * scale_factor).astype(int)
        img = imresize(img, scale_factor)
    return img
def _imresize(image_array, size):
    return imageio.imresize(image_array, size)
示例#8
0
def split(path):
    '''
    Returns two lists: a list of all images it can find in path,
    and their corresponding gesture_folder index.
    Resizes all images to 224x224.
    Selects every four images in the gesture_folder named "beer"
    and every eight in other gestures.
    Also writes every four/eight images to some file...

    File structure:
    - path
        - videoclass1
            - gesture1
                - file{1-100}.jpg  # 1 to 100 inclusive
            - gesture2
                - file{1-100}.jpg
        - videoclass2
            - ...

    Returns:
    input_list = [
        path/videoclass1/gesture1/file{8,16,24,...,96}.jpg, 
        path/videoclass1/gesture2/file{4,12,20,...,100}.jpg]
    output_list = [
        0,0,0,...,0,
        1,1,1,...,1]

    Writes:
    path/videoclass1/gesture1/file{8,16,24,...,96}.jpg -> path/videoclass1/{0,1,2,...,11}_file{8,16,24,...,96}.jpg
    path/videoclass1/gesture2/file{4,12,20,...,100}.jpg -> path/videoclass1/{12,13,...,24}_file{4,12,20,...,100}.jpg
    '''
    input_list = []
    output_list = []
    count = 0

    # Choose path as directory
    # rootpath = os.getcwd()
    # dataset = os.path.join(os.getcwd(), path)
    owd = os.getcwd()
    os.chdir(path)
    dataset = os.getcwd()

    for video_class in os.listdir(dataset):
        print(video_class)
        gesture_folders = os.listdir(os.path.join(dataset, video_class))

        for gesture_index, gesture_folder in enumerate(gesture_folders):
            gesture = os.listdir(
                os.path.join(dataset, video_class, gesture_folder))

            for count, image_filename in enumerate(gesture):
                if video_class == 'beer':  # Somehow this is a different case...?
                    if count % 4 == 0:
                        image = imread(
                            os.path.join(dataset, video_class, gesture_folder,
                                         image_filename))
                        image = imresize(image, (224, 224))
                        input_list.append(image)
                        output_list.append(gesture_index)
                        cv2.imwrite(
                            os.path.join(dataset, video_class,
                                         str(count) + '_' + image_filename),
                            image)

                else:
                    if count % 8 == 0:
                        image = imread(
                            os.path.join(dataset, video_class, gesture_folder,
                                         image_filename))
                        image = imresize(image, (224, 224))
                        input_list.append(image)
                        output_list.append(gesture_index)
                        cv2.imwrite(
                            os.path.join(dataset, video_class,
                                         str(count) + '_' + image_filename),
                            image)

    input_list = np.array(input_list)
    output_list = np.array(output_list)
    os.chdir(owd)

    return input_list, output_list