Reputation: 3125
I need to switch a function from opencv c++ to opencv python. The c++ version is: (just the part i am having problems with)
map_x.at<float>(j,i) = pc.x;
map_y.at<float>(j,i) = pc.y;
remap(frame, unDistFrame, map_x, map_y, CV_INTER_LINEAR, 0, Scalar(0, 0, 0));
In python, I have:
rows,cols,channels = frame.shape
map_x = np.array((rows,cols, channels), np.uint8) # (that is: height, width,numchannels)
map_y = np.array((rows,cols, channels), np.uint8)
frameUnDist = np.array((rows,cols, channels), np.uint8)
for i in xrange(rows):
for j in xrange(cols):
p1 = [i, j]
p1_a = sendToFunction(params, p1)
np.insert(map_x, p1_a[0])
np.insert(map_y, p1_a[1])
cv2.remap(frame, frameUndist, map_x, map_y, flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, fillval=(0, 0, 0, 0))
The insert line is clearly wrong, as I don't specify where to insert the value. How should I be doing this?
Thanks.
Upvotes: 0
Views: 971
Reputation: 3125
Solved, thanks. I needed itemset.
map_x.itemset((j,i),p1_a[0])
map_y.itemset((j,i),p1_a[1])
Upvotes: 0
Reputation: 1911
In python OpenCV Mats are actually numpy arrays so you can just use map_x[j,i] = pc.x
Upvotes: 1