Current location - Health Preservation Learning Network - Healthy weight loss - Core image user's guide
Core image user's guide
Core Image is a library for image processing and analysis, which encapsulates a very easy-to-use API, such as a large number of commonly used filters. Because it is GPU or CPU rendering, it can process still pictures and video pictures at near real-time speed, and the pictures can come from core graphics, core video and I/O framework.

The functions provided by Core Image include:

A filter semantically represents a certain ability. When it acts on a picture, it can transform to get another picture.

As we all know, a picture is a pixel matrix stored in a computer with pixels as the basic unit, which can only be displayed on the screen through the image processing unit GPU. Mathematically, the filter is actually a matrix, also called convolution kernel, which is usually much smaller than the pixel matrix dimension of a picture. When actually processing a picture, the pixel matrix and convolution kernel of the picture do convolution operation, and finally a "new" picture is output.

As the name implies, a filter chain is to link multiple filters together, and the output of the previous filter is used as the input of the next filter. Just like the assembly line, the picture enters from the first filter, and after processing, it enters the next filter until the last filter. In this way, you can create more demanding effects.

But in fact, the processing logic of core images is slightly different. It doesn't make a picture go through multiple processes. For the sake of performance, Core Image will first synthesize the convolution kernels of multiple filters into one, and then get the final result at one time.

Simply put, image processing is the process of applying an image to a filter.

In the core image, the picture is CIImage and the filter is CIFilter. The parameter setting of the filter should be realized through KVC. At the same time, you also need a context object CIContext, which holds all relevant details. Because there are so many details, it is best to create a reusable CIContext object at the right time.

The most basic usage is to use only one filter, as shown below.

CIImage can only be used for all related operations in CoreImage, and cannot be directly presented to users, because CIImage is just a "recipe" for making pictures, which is actually an operation process, such as reading picture files from URL and outputting a filter operation. , which will only be executed when rendering or outputting. To sum up, CIImage can be created by the following methods:

There are a large number of filters in Core Image, and with the continuous upgrading of the system, new filters are constantly added. The system divides it into the following categories:

By combining these functions, you can basically realize a Photoshop.

As mentioned above, when processing multiple filters, CoreImage will combine multiple filters into one to improve performance and complete the processing at an appropriate time.

For example, if it is handled step by step, the process is as follows:

But if it is synthesized into a filter, the process is as follows:

In addition to using CFilter to process pictures, Core Image can also directly process pictures through some predefined methods, which will be more convenient. For example:

In the process of image recognition, if you want to recognize a specific object, it is generally necessary to detect the contour first, and then identify the object according to the contour clipping, which will be more efficient and accurate. Such as faces, rectangles and other objects. In Core Image, the out-of-the-box contour detection function is provided, in which only three operations can be performed: face, rectangle and text. Let's look at the use of face detection:

After use, it is found that as long as there are few people in the picture, the result is more accurate, the picture clarity is reduced, and the result is not necessarily accurate.

In order to improve the performance of the application, please pay attention to the following details when using the core image: