def decompress_fullsearch(path, dest_path, macroblock_size=8): if path[-1] != "/": path += "/" info = pickle.load(open(path + "info.dat", "r")) is_key = 0 if not os.path.exists(dest_path): os.makedirs(dest_path) for c in range(info.frames): error = cv2.imread(path + str(c) + ".png", cv2.CV_LOAD_IMAGE_GRAYSCALE) if is_key == 0: if not cv2.imwrite(dest_path + str(c) + ".png", error, [cv2.cv.CV_IMWRITE_PNG_COMPRESSION, 0]): print "Failed to create: " + dest_path + str(c) + ".png" is_key = info.fixed_keyframe - 1 key_frame = error else: frame = intraframe.decode_motion_frame(error, info.motion_vectors[c], info.macroblock_size, key_frame) if not cv2.imwrite(dest_path + str(c) + ".png", frame, [cv2.cv.CV_IMWRITE_PNG_COMPRESSION, 0]): print "Failed to create: " + dest_path + str(c) + ".png" is_key -= 1 pickle.dump(info, open(dest_path + "info.dat", "w"))
import intraframe as ifr import numpy as np frame = np.ones((20, 20)) * 2 keyframe = np.ones((20, 20)) * 2 frame[0:3, 0:3] = 1 keyframe[2:5, 2:5] = 1 error, m_vs = ifr.encode_motion_frame(frame, keyframe, (2, 2)) deframe = ifr.decode_motion_frame(error, m_vs, (2, 2), keyframe) print deframe