頂点座標を空のnumpy.ndarrayに追加する操作。
よくやるのでメモ。
—(sample code)—–
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 |
import cv2 import numpy as np ## cat pol_int (x-y point list) ## -126 133 ## -126 131 ## -117 131 ## -117 134 in_data = open("./plist") lines = in_data.readlines() arr = np.empty((0,2), int) for i in range(len(lines)): lines[i].strip() jj = lines[i].split() xx = int(jj[0]) yy = int(jj[1]) arr = np.append(arr, np.array([[xx, yy]]), axis=0) i = i + 1 print(arr) |
—(exec result)—–
[[-126 133]
[-126 131]
[-117 131]
[-117 134]]
—(memo)—-
initialize ndarray for x-y point list.
at first array is empty(no entry) and add_type is [x,y].
so initialize parameter is (0,2).
1 |
arr = np.empty((0,2), int) |
if append for ndarray, append element must ndarray.
we use only 1 axis, so axis = 0(axis memo)
1 |
arr = np.append(arr, np.array([[xx, yy]]), axis=0) |