O'Reilly logo

OpenCV By Example by Vinícius Godoy, David Millán Escrivá, Prateek Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The cartoonize effect

In the last section of this chapter, we create another effect called cartoonize. The purpose of this effect is to create an image that looks like a cartoon. To do this, we divide the algorithm into two steps: edge detection and color filtering.

The cartoonCallback functions define this effect with the following code:

void cartoonCallback(int state, void* userData) { /** EDGES **/ // Apply median filter to remove possible noise Mat imgMedian; medianBlur(img, imgMedian, 7); // Detect edges with canny Mat imgCanny; Canny(imgMedian, imgCanny, 50, 150); // Dilate the edges Mat kernel= getStructuringElement(MORPH_RECT, Size(2,2)); dilate(imgCanny, imgCanny, kernel); // Scale edges values to 1 and invert values imgCanny= imgCanny/255; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required