Converting opencv remap code from c++ to python

匆匆过客 提交于 2019-12-02 08:11:22

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!