Example: Application of OpenCV non-photorealistic rendering module in image processing

Example: Application of OpenCV non-photorealistic rendering module in image processing

OpenCV is an open source library widely used in the fields of computer vision and image processing, with a wealth of functions and tools available. The non-photorealistic rendering module in OpenCV is deeply loved by users for its unique style and artistry. This article will introduce how to realize the non-realistic rendering of images through the OpenCV library, and provide the corresponding source code.

First, we need to import the OpenCV library and associated header files:

#include <opencv2/opencv.hpp>
#include <opencv2/ximgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

After that, we read a picture to be processed and perform basic image preprocessing:

Mat image = imread("input.jpg");
if (image.empty()) {
    cout << "Cannot read image" << endl;
    return -1;
}
Mat gray, edge;
cvtColor(image, gray, COLOR_BGR2GRAY);
blur(gray, edge, Size(3, 3));
Canny(edge, edge, 30, 90);

Here, we have used the Canny algorithm to detect image edges. By detecting the edges, the shape outline of the image to be processed can be well highlighted. Next, we use the non-photorealistic rendering module to add an artistic style to the image:

Mat stylized;
stylization(image, stylized, 60.0f, 0.45f);

Among them, the stylization function is the non-realistic rendering in the OpenCV library

Guess you like

Origin blog.csdn.net/Jack_user/article/details/132285899