- Mastering OpenCV 4
- Roy Shilkrot David Millán Escrivá
- 300字
- 2021-07-02 14:47:35
Generating an evil mode using edge filters
Cartoons and comics always have both good and bad characters. With the right combination of edge filters, a scary image can be generated from the most innocent looking people! The trick is to use a small edge filter that will find many edges all over the image, then merge the edges using a small median filter.
We will perform this on a grayscale image with some noise reduction, so the preceding code for converting the original image to grayscale and applying a 7 x 7 median filter should still be used (the first image in the following diagram shows the output of the grayscale median blur). Instead of following it with a Laplacian filter and Binary threshold, we can get a scarier look if we apply a 3 x 3 Scharr gradient filter along x and y (second image in the diagram), then a binary threshold with a very low cutoff (third image in the diagram), and a 3 x 3 median blur, producing the final evil mask (fourth image in the diagram):
Mat gray;
cvtColor(srcColor, gray, CV_BGR2GRAY);
const int MEDIAN_BLUR_FILTER_SIZE = 7;
medianBlur(gray, gray, MEDIAN_BLUR_FILTER_SIZE);
Mat edges, edges2;
Scharr(srcGray, edges, CV_8U, 1, 0);
Scharr(srcGray, edges2, CV_8U, 1, 0, -1);
edges += edges2;
// Combine the x & y edges together.
const int EVIL_EDGE_THRESHOLD = 12
threshold(edges, mask, EVIL_EDGE_THRESHOLD, 255,
THRESH_BINARY_INV);
medianBlur(mask, mask, 3)
The following diagram shows the evil effect applied in the fourth image:

Now that we have an evil mask, we can overlay this mask onto the cartoonified painting image as we did with the regular sketch edge mask. The final result is shown on the right-hand side of the following diagram:

- Google Apps Script for Beginners
- Groovy for Domain:specific Languages(Second Edition)
- 嚴(yán)密系統(tǒng)設(shè)計(jì):方法、趨勢(shì)與挑戰(zhàn)
- Mastering KnockoutJS
- Learning Three.js:The JavaScript 3D Library for WebGL
- Spring Boot進(jìn)階:原理、實(shí)戰(zhàn)與面試題分析
- Learning YARN
- Access 2010中文版項(xiàng)目教程
- iPhone應(yīng)用開發(fā)從入門到精通
- Python爬蟲、數(shù)據(jù)分析與可視化:工具詳解與案例實(shí)戰(zhàn)
- Python從入門到精通
- 創(chuàng)意UI Photoshop玩轉(zhuǎn)移動(dòng)UI設(shè)計(jì)
- C++17 By Example
- Clojure for Finance
- 產(chǎn)品架構(gòu)評(píng)估原理與方法