The wave is quite simple, so we put the polynomial curve in the primary edge defined by the output cv2 . First we want to get the points of of this main edge. Suppose your origin is like in the image in the upper left corner. If you look at the original image, I think that we will have a good approximation for our points of interest, if we just take the points with the largest y in the range (750, 1500).
import cv2 import numpy as np from matplotlib import pyplot as plt from numba import jit
If we draw these points, we will see that they are very close to those to which we aspired.
plt.figure(1, figsize=(8, 16)) ax1 = plt.subplot(211) ax1.imshow(edges,cmap = 'gray') ax2 = plt.subplot(212) ax2.axis([0, edges.shape[1], edges.shape[0], 0]) ax2.plot(data[:,1]) plt.show()

And now that we have an array of coordinate pairs, we can use numpy.polyfit to generate coefficients to best match the polynomial and numpy.poly1d to generate a function from these coefficients.
xdata = data[:,0] ydata = data[:,1] z = np.polyfit(xdata, ydata, 5) f = np.poly1d(z)
and then schedule to check
t = np.arange(0, edges.shape[1], 1) plt.figure(2, figsize=(8, 16)) ax1 = plt.subplot(211) ax1.imshow(edges,cmap = 'gray') ax2 = plt.subplot(212) ax2.axis([0, edges.shape[1], edges.shape[0], 0]) ax2.plot(t, f(t)) plt.show()
