Converting opencv remap code from c++ to python

后端 未结 1 1938
挽巷
挽巷 2021-01-29 00:31

I am trying to convert c++ opencv cv2.remap code to python. I am not getting any error but result is not as expected.I am getting zoomed image

c++ code

i         


        
相关标签:
1条回答
  • 2021-01-29 00:58

    This is my result:

    Generaly, I prefer the the vectorized implementation to the for-loop implementation in Python. Here is my code:

    #!/usr/bin/python3
    # 2018.09.23 12:24 (CST)
    import cv2 
    import numpy as np 
    
    fname = "remap.jpg"
    img = cv2.imread(fname)
    nh, nw = img.shape[:2]
    
    PI = 3.141592653589793
    phase = -0.8 * PI
    omega = 2.0 * PI / nw
    amp = 15
    
    xs, ys = np.meshgrid(np.arange(0, nw), np.arange(0, nh))
    ys = np.sin(phase+xs*omega)*amp + ys
    xs = np.float32(xs)
    ys = np.float32(ys)
    
    dst= cv2.remap(img, xs, ys, cv2.INTER_CUBIC)
    cv2.imwrite("dst.png", dst)
    
    0 讨论(0)
提交回复
热议问题