def main(): fname = "./pics/sample_images/scene00001.jpg" fullPic = plt.imread(fname) pic = proto_mpeg.Frame(fullPic) v, h = pic.v_mblocks, pic.h_mblocks # 22,40 QF = 0.1 #encode.encode_pic(fname,QF=QF,output="output.bin") #decode.decode_pic(v,h,input="output.bin",QF=QF,output="./decoded_pics/night.jpg") img_list = ["./pics/sample_images/scene00%03d.jpg" % i for i in range(10)][1:] #print(img_list) encoder.encode_video(img_list, QF=QF, output="output.bin") decoder.decode_video(input="output.bin", output='decoded_movie.mp4') #fname = "./decoded_pics/output0001.jpg" #fullPic = plt.imread(fname) #print(fullPic.shape) #### Compare #comparer.compare_compress_rate('./pics/baboon.jpg') #for QF in [0.1,0.3,0.5,0.7,0.9,1.1,1.3,1.5]: comparer.compare_block(pic,0,0,QF) #for QF in [0.1,0.3,0.5,0.7,0.9,1.1,1.3,1.5]: comparer.compare_pics(pic,QF) """
def analyze(QF,n): t_start = time.time() encode_time = 0 decode_time = 0 for i in ["%03d" % i for i in range(n+1)][1:]: img_name = './pics/sample_images/scene00'+i+'.jpg' print("processing ",img_name) fullPic = plt.imread(img_name) pic = proto_mpeg.Frame(fullPic) v=pic.v_mblocks h=pic.h_mblocks # Encode start = time.time() encoded_dre = encoder.encode_pic_to_dre(pic,QF) # dre refers to DC_term,Run_level,EOB #print(encoded_dre) bits = encoder.dre_to_bit_1(encoded_dre,'out.bin') encode_time += time.time()-start # Decode start = time.time() decoded_dre = decoder.decode_bit_to_dre_1('out.bin') #print(decoded_dre) decoded = decoder.decode_dre_to_pic(v,h,decoded_dre,QF) decode_time += time.time()-start print("QF = ",QF) print("average total time: ", (time.time()-t_start)/n) print("average encode time: ",encode_time/n) print("average decode time: ",decode_time/n)
def compare_compress_rate(fname): fullPic = plt.imread(fname)[:32, :64] pic = proto_mpeg.Frame(fullPic) statinfo = os.stat('./pics/baboon.jpg') ori_size = statinfo.st_size for QF in [0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5]: encoded_dre = encoder.encode_pic_to_dre( pic, QF) # dre refers to DC_term,Run_level,EOB bits = encoder.dre_to_bit(encoded_dre) print('QF = ', QF, ', original size = ', ori_size, ', bitstream length = ', len(bits), ', compression rate = ', str(len(bits) * 100 / ori_size)[:4] + "%")
def main(): fname = "./pics/sample_images/scene00001.jpg" fullPic = plt.imread(fname) pic = proto_mpeg.Frame(fullPic) v, h = pic.v_mblocks, pic.h_mblocks # 22,40 compare_compress_rate('./pics/baboon.jpg')
X = v - j wrappedfm1[Y + i - hlfblksize:Y + i + hlfblksize, X + j - hlfblksize:X + j + hlfblksize, :] = frame1.getFrame()[i - hlfblksize:i + hlfblksize, j - hlfblksize:j + hlfblksize, :] frame1_mot[int((i - hlfblksize) / blksize), int((j - hlfblksize) / blksize), 0] = X frame1_mot[int((i - hlfblksize) / blksize), int((j - hlfblksize) / blksize), 1] = Y error = wrappedfm1 - frame2.getFrame() return frame1_mot, error, wrappedfm1 image1 = plt.imread('scene00001.jpg') image2 = plt.imread('scene00002.jpg') print(image1.shape) print(image2.shape) fr1 = proto_mpeg.Frame(image1) fr2 = proto_mpeg.Frame(image2) start = time.time() fr1mot, error, wrappedfm1 = blkmatch(fr1, fr2, blksize=16, scpsize=7) print(time.time() - start) plt.imshow(image1.getFrame()) plt.imshow(image2.getFrame()) plt.imshow(wrappedfm1)