-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpc_error.py
75 lines (57 loc) · 2.26 KB
/
pc_error.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import numpy as np
import os, time
import pandas as pd
import subprocess
rootdir = os.path.split(__file__)[0]
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(rootdir+'/pc_error_d' +
' -a '+infile1+
' -b '+infile2+
# ' -n '+infile1+
' --hausdorff=1 '+
' --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])