Reputation: 2171
I am trying to get information (coordinates) that is within a numpy array and I am having a difficult time extracting information from it.
The numpy array was returned by an openCV method, cv2.calcOpticalFlowPyrLK, which produced coordinates of each point in a numpy array.
This is the output for a single point:
[[[ 292.61154175 264.74569702]]]
Small sample of the code:
p1, st, err = cv2.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)
good_new = p1[st==1]
good_old = p0[st==1]
How do I extract those numbers individually from that type of numpy array?
Upvotes: 1
Views: 812
Reputation: 8982
import numpy
# create such a nested array
d = numpy.array([[[1, 2]]])
# test that we can access individual elements
assert d[0, 0, 0] == 1
assert d[0, 0, 1] == 2
UPDATE:
Please note that the above indexing works only with numpy arrays. The standard Python nested lists like e = [[[1, 2]]]
must be indexed in the standard Python way: e[0][0][0]
.
Upvotes: 2