Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering OpenCV 3

You're reading from   Mastering OpenCV 3 Get hands-on with practical Computer Vision using OpenCV 3

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher
ISBN-13 9781786467171
Length 250 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Authors (6):
Arrow left icon
Shervin Emami Shervin Emami
Author Profile Icon Shervin Emami
Shervin Emami
David Millán Escrivá David Millán Escrivá
Author Profile Icon David Millán Escrivá
David Millán Escrivá
Eugene Khvedchenia Eugene Khvedchenia
Author Profile Icon Eugene Khvedchenia
Eugene Khvedchenia
Daniel Lelis Baggio Daniel Lelis Baggio
Author Profile Icon Daniel Lelis Baggio
Daniel Lelis Baggio
Roy Shilkrot Roy Shilkrot
Author Profile Icon Roy Shilkrot
Roy Shilkrot
Jason Saragih Jason Saragih
Author Profile Icon Jason Saragih
Jason Saragih
+2 more Show less
Arrow right icon
View More author details
Toc

Cartoonifier and Skin Changer for Raspberry Pi

This chapter will show how to write some image processing filters for desktop and for small embedded systems such as Raspberry Pi. First, we develop it for the desktop (in C/C++) and then port the project to Raspberry Pi, since this is the recommended scenario when developing for embedded devices. This chapter will cover the following topics:

  • How to convert a real-life image to a sketch drawing
  • How to convert to a painting and overlay the sketch to produce a cartoon
  • A scary evil mode to create bad characters instead of good characters
  • A basic skin detector and skin color changer, to give someone green alien skin
  • Finally, how to create an embedded system based on our desktop application

Note that an embedded system is basically a computer motherboard placed inside a product or device, designed to perform specific tasks, and Raspberry Pi is a very low-cost and popular motherboard for building an embedded system:

The preceding picture shows what you could make after this chapter: a battery-powered Raspberry Pi + screen you could wear to Comic Con, turning everyone into a cartoon!

We want to make the real-world camera frames automatically look like they are from a cartoon. The basic idea is to fill the flat parts with some color and then draw thick lines on the strong edges. In other words, the flat areas should become much more flat and the edges should become much more distinct. We will detect edges, smooth the flat areas, and draw enhanced edges back on top, to produce a cartoon or comic-book effect.

When developing an embedded computer vision system, it is a good idea to build a fully working desktop version first before porting it to an embedded system, since it is much easier to develop and debug a desktop program than an embedded system! So this chapter will begin with a complete Cartoonifier desktop program that you can create using your favorite IDE (for example, Visual Studio, XCode, Eclipse, QtCreator). After it is working properly on your desktop, the last section shows how to create an embedded system based on the desktop version. Many embedded projects require some custom code for the embedded system, such as to use different inputs and outputs or use some platform-specific code optimizations. However, for this chapter, we will actually be running identical code on the embedded system and the desktop, so we only need to create one project.

The application uses an OpenCV GUI window, initializes the camera, and with each camera frame it calls the function cartoonifyImage(), containing most of the code in this chapter. It then displays the processed image on the GUI window. This chapter will explain how to create the desktop application from scratch using a USB webcam, and the embedded system-based on the desktop application using a Raspberry Pi Camera Module. So first you would create a desktop project in your favorite IDE, with a main.cpp file to hold the GUI code given in the following sections such as the main loop, webcam functionality, and keyboard input, and you would create a cartoon.cpp file with the image processing operations with most of this chapter's code in a function called cartoonifyImage().

The full source code of this book is available at http://github.com/MasteringOpenCV/code.
You have been reading a chapter from
Mastering OpenCV 3 - Second Edition
Published in: Apr 2017
Publisher:
ISBN-13: 9781786467171
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime