Exemple #1
0
    def split_func(split_id):
        # -------- choose a whole part ------------------ #
        each_split_sample_num = samples.shape[0] // split_num
        my_samples = samples[split_id * each_split_sample_num: (split_id + 1) * each_split_sample_num]
        my_labels = labels[split_id * each_split_sample_num: (split_id + 1) * each_split_sample_num]

        utility.save_to_file(save_prefix + str(split_id) + ".file", my_samples, my_labels)
Exemple #2
0
def generate_datas(args):
    counts = args.iter_num // 10

    total_samples, total_labels = None, None

    for _ in range(counts):
        random_samples, random_labels = utility.generate_random_samples(
            num_of_samples=args.global_batch_size * 10,
            vocabulary_size=args.vocabulary_size,
            slot_num=args.slot_num,
            max_nnz=args.nnz_per_slot,
            use_sparse_mask=False)
        if total_samples is None:
            total_samples = random_samples
            total_labels = random_labels
        else:
            total_samples = np.concatenate([total_samples, random_samples],
                                           axis=0)
            total_labels = np.concatenate([total_labels, random_labels],
                                          axis=0)

    utility.save_to_file(args.filename, total_samples, total_labels)
                        'block_coords': (block_x, block_y),
                        'key': zigzag[i],
                        'val': transform[zigzag[i]]
                    })
    return result

if __name__ == '__main__':
    if len(sys.argv) == 1:
        root_dir = util.safeGetDirectory()
        all_files = [f for f in listdir(root_dir) if path.isfile(path.join(root_dir, f))]
        input_file = util.getVideoFile(all_files)
        n = util.getConstant('n')
        filename = path.join(root_dir, input_file)
    elif len(sys.argv) == 3:
        filename = path.realpath(sys.argv[2])
        n = int(sys.argv[1])
    else:
        print 'Usage: python block_dct.py 6 ../path/to/file.mp4'
        exit()

    # Read the video data
    video = cv2.VideoCapture(filename)
    frame_data = util.getContent(video)

    # Calculate the significant components
    significant_components = FindDiscreteCosineTransform(frame_data, n)

    # Write the data to the file
    output_filename = filename.replace('.mp4', '_blockdct_' + str(n) + '.bct')
    util.save_to_file(significant_components, output_filename)
'''
if __name__ == '__main__':
    if len(sys.argv) == 1:
        root_dir = util.safeGetDirectory()
        all_files = [f for f in listdir(root_dir) if path.isfile(path.join(root_dir, f))]
        input_file = util.getVideoFile(all_files)
        n = util.getConstant('n')
        filename = path.join(root_dir, input_file)
    elif len(sys.argv) == 3:
        filename = path.realpath(sys.argv[2])
        n = int(sys.argv[1])
    else:
        print 'Usage: python block_quantize.py 6 ../path/to/file.mp4'
        exit()


    # Read video data
    video = cv2.VideoCapture(filename)
    frame_data = util.getContent(video)

    # Quantize the blocks of the video
    quantized_values, frame_block_list = quantize(frame_data, n)

    # Write the data to the file
    output_filename = filename.replace('.mp4', '_hist_' + str(n) + '.hst')
    util.save_to_file(quantized_values, output_filename)

    # Display histogram of quantized regions
    image_filename = output_filename.replace('.hst', '.png')
    display_histogram(quantized_values, n, image_filename=image_filename)
'''
Main Method
Given a video file `video_filename.mp4` and an `m` value, will output a text file video_filename_blockdwt_n.bwt in the same directory.
Pass the parameters in via command line parameters.
'''
if __name__ == '__main__':
    if len(sys.argv) == 1:
        root_dir = util.safeGetDirectory()
        all_files = [f for f in listdir(root_dir) if path.isfile(path.join(root_dir, f))]
        input_file = util.getVideoFile(all_files)
        m = util.getConstant('m')
        filename = path.join(root_dir, input_file)
    elif len(sys.argv) == 3:
        filename = path.realpath(sys.argv[2])
        m = int(sys.argv[1])
    else:
        print 'Usage: python frame_dwt.py 6 ../path/to/file.mp4'
        exit()

    # Read the video data
    video = cv2.VideoCapture(filename)
    frame_data = util.getContent(video)

    # Calculate the wavelet components of each frameblock
    significant_wavelets = video_framedwt(frame_data, m)

    # Write the data to the file
    output_filename = filename.replace('.mp4', '_framedwt_' + str(m) + '.fwt')
    util.save_to_file(significant_wavelets, output_filename)