Skip to content

Instantly share code, notes, and snippets.

@stefanocoding
Created October 5, 2017 12:50
Show Gist options
  • Save stefanocoding/eb4e816cb0f41b67b5f47bd19445de11 to your computer and use it in GitHub Desktop.
Save stefanocoding/eb4e816cb0f41b67b5f47bd19445de11 to your computer and use it in GitHub Desktop.
Plot curve using OpenCV instead of Matplotlib's plot().
# If you have something like this
matplotlib.pyplot.plot(x_values, y_values, color='yellow')
# You can do the same on OpenCV like this
curve = numpy.column_stack((x_values.astype(numpy.int32), y_values.astype(numpy.int32)))
cv2.polylines(image, [curve], False, (0,255,255))
# And if you need to plot more curves just add them as an element to the array of polygonal curves
curve1 = numpy.column_stack((x1.astype(numpy.int32), y1.astype(numpy.int32)))
curve2 = numpy.column_stack((x2.astype(numpy.int32), y2.astype(numpy.int32)))
cv2.polylines(image, [curve1, curve2], False, (0,255,255))
# More information http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#polylines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment