for i in range(n): result.append({ 'frame_num': frame_num, '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)
rgb_target = cv2.cvtColor(frame_data[index-1].astype(np.uint8), cv2.COLOR_GRAY2BGR) frame_description = description + ' #' + str(i + 1) + ': frame ' + str(index) + '. Score: ' + str(score) print frame_description cv2.imshow(frame_description, rgb_target) cv2.waitKey(0) cv2.destroyAllWindows() return 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) f = util.getConstant('the frame number') n = util.getConstant('n (for block-level quantization)') m = util.getConstant('m (for frame-level dwt)') filename = path.join(root_dir, input_file) elif len(sys.argv) == 5: f = int(sys.argv[1]) n = int(sys.argv[2]) m = int(sys.argv[3]) filename = path.realpath(sys.argv[4]) else: print 'Usage: python match_frame.py <f> <n> <m> <../path/to/file.mp4>' exit() # Read the video data video = cv2.VideoCapture(filename) frame_data = util.getContent(video)
from block_quantize import quantize, display_histogram def diff_quantize(frame_data, n): diff_frame_data = np.diff(frame_data, axis=0) # Quantize the blocks of the video quantized_values, frame_block_dict = quantize(diff_frame_data, n) return quantized_values, frame_block_dict 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 diff_quantize.py 6 ../path/to/file.mp4" exit() video = cv2.VideoCapture(filename) frame_data = util.getContent(video) # Quantize the blocks of the video quantized_values, frame_block_dict = diff_quantize(frame_data, n) # Write the data to the file
'val': frame_wavelets[zigzag[i]] }) return result ''' 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)