A python implementation of the CvPlot library from PROFACTOR. I needed a fast drawing library as using matplotlib within an application is cumbersome and slow. So I searched for another opportunity using pure OpenCV and found this... So I reimplemented it in python using the Gemini Flash 2.5 Model from Google.
In this library you must basically build the whole plot yourself. You have to add the Axis, the grid and of course the actual plot. There are some basic helper methods found in cv_plot.plot. You can create a LinePlot and a ScatterPlot (with the Series class) and can show Images as well as HorizontalLines and VerticalLines. You can use this as follows:
import cv_plot.plot as cvplt
import cv2
ax = cvplt.makePlotAxes()
s = ax.create(cvplt.Series, x=[0,1,2,3,4], y=[2,3,1,5,6], lineSpec="r-") # this would be a red LinePlot, to create a green ScatterPlot just replace 'r-' with 'g.'
img = ax.render(600,400) # now you have an standard OpenCV image (which is a np.ndarray with type np.uint8)
# show it in a window
plt.show(img)To use alpha blending you have to set the alpha value AFTER creating the Drawable, like so:
# Can also now fill a polygon
s = ax.create(cvplt.Series, x=[0,1,2,3,2,1], y=[2,3,1,5,6,-2], lineSpec="r-", fill=True)
s.alpha=0.3You can do a little bit more in the sense of styling and setting y and x limits but thats basically it.
As I had some circular import errors to use a Legend (as it imports Axes from core) you have to import it after import cv_plot.plot as cvplt with something like:
from cv_plot.drawables.legend import Legend
You can add additionaly drawables by inheriting from cv_plot.core.Drawable. There you must especially implement the render(RawProjection) function and the getBoundingRect() function (to automatical determine the axis limits). With the RawProjection you can project points from data space into display space and reverse with unproject. The RawProjection contains an inner_rect which is the inside of the axis boundaries (and mainly the drawing area).
I removed the cv_plot.gui part as it has its flaws and also didn't work correctly in the cpp version (at least with the Qt backend I was not able to zoom into the axis). But I added the cv_plot.plot.show function to allow easy showing of the plot.
---- ORIGINAL README BELOW ----
Yes, another C++ plotting library. Because CvPlot is
- Purely OpenCV based
- Highly adaptable and extendable
- Fast
- Easy to integrate
CvPlot was developed at PROFACTOR for realtime image plotting. It comes with some basic "Drawables", including Series, Image, Axis, Grid, Titles, etc. Drawables can easily be modified, replaced and extended, using standard OpenCV drawing functions. CvPlot comes with an interactive viewer, based on cv::imshow(). The viewer can easily be integrated into any C++ GUI framework (e.g. Qt/Qml in CvPlotQt).
CvPlot is NOT and will never be a full featured plotting library. Many features are missing, but you can easily add them using custom drawables.