简体   繁体   English

numpy的python openCv重新映射

[英]numpy python openCv remap

I need to switch a function from opencv c++ to opencv python. 我需要将功能从opencv c ++切换到opencv python。 The c++ version is: (just the part i am having problems with) C ++版本是:(只是我遇到问题的部分)

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: 在python中,我有:

    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. 谢谢。

在python中,OpenCV Mats实际上是numpy数组,因此您可以使用map_x[j,i] = pc.x

Solved, thanks. 解决了,谢谢。 I needed itemset. 我需要项集。

map_x.itemset((j,i),p1_a[0])
map_y.itemset((j,i),p1_a[1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM