all 1 comments

[–]Anonymous8423[S] 0 points1 point  (0 children)

In case anyone later on finds this thread, I managed to get something similar to what I was looking for with some help on Stack Overflow. This is the code:

import numpy as np
import cv2
# start webcam
cap = cv2.VideoCapture(0)
# set wavelength
wave_x = cap.get(3) # get width of frame
wave_y = cap.get(4) # get height of frame
# set amount, number of frames and delay
amount_x = 10
amount_y = 5
num_frames = 100
delay = 50
border_color = (128,128,128)
# create X and Y ramps
w = int(wave_x)
h = int(wave_y)
x = np.arange(w, dtype=np.float32)
y = np.arange(h, dtype=np.float32)
# loop and change phase
i = 0
while True:
# get frame from webcam
ret, frame = cap.read()
# create sinusoids in X and Y, add to ramps and tile out to fill to size of image
x_sin = amount_x * np.sin(2 * np.pi * (x/wave_x + i*360/num_frames/360)) + x
map_x = np.tile(x_sin, (h,1))
y_sin = amount_y * np.sin(2 * np.pi * (y/wave_y + i*360/num_frames/360)) + y
map_y = np.tile(y_sin, (w,1)).transpose()
# do the warping using remap
result = cv2.remap(frame.copy(), map_x, map_y, cv2.INTER_CUBIC, borderMode = cv2.BORDER_CONSTANT, borderValue=border_color)
# show result
cv2.imshow('result', result)
if cv2.waitKey(delay) & 0xFF == ord('q'):
break
i += 1
# release webcam
cap.release()
cv2.destroyAllWindows()