def get_psnr(self, line): yuv = YCbCr(filename=line.input_url, filename_diff=line.output, width=int(line.width), height=int(line.height), yuv_format_in=line.type, bitdepth=int(line.bit_depth)) time_b = time.time() for infile in range(len(line.input_url)): p_pool = [] for diff_file in range(len(line.output)): if not os.path.exists(line.output[diff_file]): print >> sys.stderr, '%s decode failed' % self.codec_name psnr = yuv.psnr_all(diff_file, infile) if 0 in psnr: print ' psnr calculate wrong!\n' line.psnr.append(psnr[0]) line.psnr_luam.append(psnr[1]) line.psnr_charm_cb.append(psnr[2]) line.psnr_charm_cr.append(psnr[3]) if len(psnr) == 0: print 'calculate psnr failed!\n' # com_psnr = Array('d', len(line.output) * 4) # for diff_file in range(len(line.output)): # p = Process(target=yuv.psnr_all, args=(diff_file, infile, com_psnr)) # p.start() # p_pool.append(p) # for p in p_pool: # p.join() # for num in range(len(line.output)): # line.psnr.append(com_psnr[num * 4]) # line.psnr_luam.append(com_psnr[num * 4 + 1]) # line.psnr_charm_cb.append(com_psnr[num * 4 + 2]) # line.psnr_charm_cr.append(com_psnr[num * 4 + 3]) elapsed = (time.time() - time_b) m, s = divmod(elapsed, 60) h, m = divmod(m, 60) print("calculate psnr time used : %d:%02d:%02d" % (h, m, s)) line.set_average_fps() # line.set_bd_psnr(BD.BD_PSNR_Average(line.bit_rate, line.psnr)) line.sort()
def plot_psnr_frames(contain): """ PSNR, all planes """ # ind = arg.Bit_rate # the x locations for the groups fig = plt.figure(figsize=[16, 6], constrained_layout=True) gs = GridSpec(1, 2, figure=fig) plt.suptitle('yuv Quality plot') # frames_psnr = fig.add_subplot(gs[:, 0]) bits_psnr = fig.add_subplot(gs[0, 0]) DBDR = fig.add_subplot(gs[0, 1]) DBDR.set_axis_off() # frames_psnr.set_title('Psnr-Y vs Frames') # frames_psnr.set_xlabel('frames') # frames_psnr.set_ylabel('Psnr-y') bits_psnr.set_title('Psnr vs Bitrate') bits_psnr.set_xlabel('bitrate') bits_psnr.set_ylabel('psnr-y') BD_contain = [] for i in range(len(contain)): yuv = YCbCr(filename=contain[i][0], filename_diff=contain[i][1], width=int(contain[i][5]), height=int(contain[i][6]), yuv_format_in=contain[i][7], bitdepth=contain[i][4]) for infile in range(len(contain[i][0])): point = [] xax = [] for diff_file in range(len(contain[i][1])): temp = [p for p in yuv.psnr_all(diff_file, infile)] ind = np.arange(len(temp)) frame = [frame_order[0] for frame_order in temp] point.append(temp[-1][0]) xax.append(contain[i][2][diff_file]) # frames_psnr.plot(ind[0:-1], frame[0:-1], 'o-', label=contain[i][3]+'_'+str(contain[i][2][diff_file])) temp_sort = sort_point(xax, point) bits_psnr.plot(temp_sort[0], temp_sort[1], 'o-', label=contain[i][3]) BD_contain.append( [temp_sort[0], temp_sort[1], contain[i][3], contain[i][0]]) celltext = [] rowname = [] tag = 0 while tag < len(BD_contain): x265_rate = BD.BD_RATE(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 1][0], BD_contain[tag + 1][1]) svt_rate = BD.BD_RATE(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 2][0], BD_contain[tag + 2][1]) x265_psnr = BD.BD_PSNR(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 1][0], BD_contain[tag + 1][1]) svt_psnr = BD.BD_PSNR(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 2][0], BD_contain[tag + 2][1]) rowname.append(BD_contain[tag][3][0].split('/')[-1] + '_' + BD_contain[tag][2]) rowname.append(BD_contain[tag + 1][3][0].split('/')[-1] + '_' + BD_contain[tag + 1][2]) rowname.append(BD_contain[tag + 2][3][0].split('/')[-1] + '_' + BD_contain[tag + 2][2]) celltext.append(['HM base line', 'HM base line']) celltext.append([x265_rate, x265_psnr]) celltext.append([svt_rate, svt_psnr]) tag += 3 DBDR.table(cellText=celltext, colLabels=['BDBR', 'BD-PSNR'], rowLabels=rowname, loc='center', colWidths=[0.2, 0.2]) # frames_psnr.legend() bits_psnr.legend() # fig.align_labels() plt.show()