-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_point_data.py
41 lines (35 loc) · 1.14 KB
/
get_point_data.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
import numpy as np
import cv2
import argparse
import os
os.environ["OPENCV_IO_ENABLE_OPENEXR"]="1"
#main()
#input the location of CSV files
parser = argparse.ArgumentParser(description='Code for pick up RGB values.')
parser.add_argument('--input', type=str, help='Path to the RGB csv file.')
args = parser.parse_args()
if not args.input:
parser.print_help()
exit(0)
#Load RGB CSV files
with open(os.path.join(args.input, 'point.csv')) as f:
content = f.readlines()
print(len(content))
rgb_vals = []
hdrImg = cv2.imread(os.path.join(args.input, 'dataRGB.exr'), cv2.IMREAD_UNCHANGED)
matB, matG, matR = cv2.split(hdrImg)
#matR = hdrImg[:,:,2]
#matG = hdrImg[:,:,1]
#matB = hdrImg[:,:,0]
#getting RGB values
for line in content:
tokens = line.split(',')
row = int(tokens[0])
col = int(tokens[1])
step = int(tokens[2])
r = matR[col-step:col+step, row-step:row+step].mean()
g = matG[col-step:col+step, row-step:row+step].mean()
b = matB[col-step:col+step, row-step:row+step].mean()
rgb = (r, g, b)
rgb_vals.append(rgb)
np.savetxt(os.path.join(args.input,'rgb_vals.csv'), rgb_vals, delimiter=",", fmt='%f')