Skip to content Skip to sidebar Skip to footer

Converting Opencv Remap Code From C++ To Python

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 int main() { Mat img = i

Solution 1:

This is my result:

enter image description here

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)

Post a Comment for "Converting Opencv Remap Code From C++ To Python"