|
- import numpy as np
- import os, time
- import pandas as pd
- import subprocess
- import argparse
-
- def get_points_number(filedir):
- plyfile = open(filedir)
-
- line = plyfile.readline()
- while line.find("element vertex") == -1:
- line = plyfile.readline()
- number = int(line.split(' ')[-1][:-1])
-
- return number
-
- def number_in_line(line):
- wordlist = line.split(' ')
- for _, item in enumerate(wordlist):
- try:
- number = float(item)
- except ValueError:
- continue
-
- return number
-
- def pc_error(infile1, infile2, res, normal=False, show=False):
- # Symmetric Metrics. D1 mse, D1 hausdorff.
- headers1 = ["mse1 (p2point)", "mse1,PSNR (p2point)",
- "h. 1(p2point)", "h.,PSNR 1(p2point)" ]
-
- headers2 = ["mse2 (p2point)", "mse2,PSNR (p2point)",
- "h. 2(p2point)", "h.,PSNR 2(p2point)" ]
-
- headersF = ["mseF (p2point)", "mseF,PSNR (p2point)",
- "h. (p2point)", "h.,PSNR (p2point)" ]
-
- haders_p2plane = ["mse1 (p2plane)", "mse1,PSNR (p2plane)",
- "mse2 (p2plane)", "mse2,PSNR (p2plane)",
- "mseF (p2plane)", "mseF,PSNR (p2plane)"]
-
- headers = headers1 + headers2 + headersF + haders_p2plane
-
- command = str('/userhome/PCGCv2/PCGCv2-8.3/PCGCv2-master/pc_error_d' +
- ' -a '+infile1+
- ' -b '+infile2+
- # ' -n '+infile1+
- ' --hausdorff=1 '+
- # ' --knn='+str(knn)+ 不支持
- ' --resolution='+str(res-1))
-
- if normal:
- headers += haders_p2plane
- command = str(command + ' -n ' + infile1)
-
- results = {}
-
- start = time.time()
- subp=subprocess.Popen(command,
- shell=True, stdout=subprocess.PIPE)
-
- c=subp.stdout.readline()
- while c:
- line = c.decode(encoding='utf-8')# python3.
- if show:
- print(line)
- for _, key in enumerate(headers):
- if line.find(key) != -1:
- value = number_in_line(line)
- results[key] = value
-
- c=subp.stdout.readline()
- # print('===== measure PCC quality using `pc_error` version 0.13.4', round(time.time() - start, 4))
-
- return pd.DataFrame([results])
-
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(
- prog='eval.py',
- description='Outputs evaluation results from original, compressed and decompressed point cloud folders.',
- formatter_class=argparse.ArgumentDefaultsHelpFormatter
- )
- parser.add_argument(
- 'ori_file',
- help='Original file.')
- parser.add_argument(
- 'dec_file',
- help='Decompressed file.')
- parser.add_argument(
- '--res',
- type=int,
- help='resolution.',
- default=512)
- parser.add_argument(
- '--normal', '-n', action='store_true',
- help='Report bitrate and distortion when training.')
-
- args = parser.parse_args()
- pc_error(args.ori_file, args.dec_file, args.res, normal=args.normal, show=True)
|