This chapter presents some techniques for altering images. Our goal is to achieve artistic effects, similar to the filters that can be found in image editing applications, such as Photoshop or Gimp.
As we proceed with implementing filters, you can try applying them to any BGR image and then saving or displaying the result. To fully appreciate each effect, try it with various lighting conditions and subjects. By the end of this chapter, we will integrate filters into the Cameo application.
All the finished code for this chapter can be downloaded from my website: http://nummist.com/opencv/3923_03.zip.
Like our CaptureManager
and WindowManager
classes, our filters should be reusable outside Cameo. Thus, we should separate the filters into their own Python module or file.
Let's create a file called filters.py
in the same directory as cameo.py
. We need the following import statements in filters.py
:
import cv2 import numpy import utils
Let's also create a file called utils.py
in the same directory. It should contain the following import statements:
import cv2 import numpy import scipy.interpolate
We will be adding filter functions and classes to filters.py
, while more general-purpose math functions will go in utils.py
.