Converting images to vector graphics
In this recipe, we will try to convert simple, hand-drawn sketches to vector graphics using image processing functions from the OpenCV library and Cairo library for vector drawing and exporting.
Getting started
We will be using the OpenCV library, so please refer to the Integrating with OpenCV recipe earlier in this chapter for information on how to set up your project. You may want to prepare your own drawing to be processed. In this example we are using a photo of some simple geometric shapes sketched on paper.
How to do it…
We will create an application to illustrate the conversion to vector shapes. Perform the following steps to do so:
Include necessary headers:
#include "cinder/gl/Texture.h" #include "cinder/Surface.h" #include "cinder/ImageIo.h" #include "cinder/cairo/Cairo.h"
Add the following declarations to your main class:
void renderDrawing( cairo::Context&ctx ); Surface mImage, mIPImage; std::vector<std::vector<cv::Point> >mContours...