I have a csv file with columns containing pixel values as shown in the image. I want to read/access each value, I tried using numpy.genfromtxt but cudn't access the values.
csv file snapshot
I have a csv file with columns containing pixel values as shown in the image. I want to read/access each value, I tried using numpy.genfromtxt but cudn't access the values.
csv file snapshot
It depends how you want to access them, the following shows how it could be done using Python's CSV library:
import csv
with open('corners_topsingle.csv', 'rb') as f_input:
csv_input = csv.reader(f_input)
data = []
for row in csv_input:
values = []
for value in row[2:]:
x, y = value.strip('()').split(',')
values.append((int(x), int(y)))
data.append(row[:2] + values)
print data
This would give you data
looking like:
[['1', '02.jpg', (86, 54), (89, 454), (321, 76), (309, 418)],
['2', '03.jpg', (86, 54), (89, 454), (321, 76), (309, 418)],
['3', '04.jpg', (86, 54), (89, 454), (321, 76), (309, 418)]]
This assumes you are using Python 2.x and a row of your CSV file looks something like:
1,02.jpg,"(86,54)","(89,454)","(321,76)","(309,418)"
For Python 3.x, use:
with open('corners_topsingle.csv', 'r', newline='') as f_input:
and change to print(data)