Connect with us

Code

GPUPixel – Cross-Platform Real-Time Beauty Effects Library

GPUPixel is a high-performance image and video beauty effect library written in C++11. Achieving Commercial-Grade beauty effects. Extremely easy to compile and integrate, with a very small library size.

It is GPU-based and comes with built-in beauty effects filters that can achieve commercial-grade results.

It supports platforms including iOS, Mac, Android, and it can theoretically be ported to any platform that supports OpenGL/ES.

The face key points detection currently utilizes the Face++ library, but it will be replaced with either VNN in the future.

GPUPixel Architecture

Compilation

iOS

  1. Open objc/gpupixel.xcodeproj or objc/demo/PixDemo.xcodeproj Xcode project ;

  2. Select the corresponding platform for compilation;

Android

  1. Open the directory ./android in Android Studio

  2. Configure NDK r21+

Library Size

iOS(.framework) MacOS(.framework) Android(.aar)
Size 2.4 MB 2.6 MB 2.1 MB

Usage

Refer to ./objc/demo or ./android demo

.h file

// video data input
std::shared_ptr<SourceRawDataInput> source_raw_input_;
// beauty filter
std::shared_ptr<FaceBeautyFilter> face_beauty_filter_;
// video data output 
std::shared_ptr<TargetRawDataOutput> target_raw_output_;

Create Filter, .cpp file

 GPUPixel::GPUPixelContext::getInstance()->runSync([&] {
    // Create filter
    source_raw_input_ = SourceRawDataInput::create();
    target_raw_output_ = TargetRawDataOutput::create();
    // Face Beauty Filter
    face_beauty_filter_ = FaceBeautyFilter::create();
    
    // Add filter
    source_raw_input_->addTarget(face_beauty_filter_)->addTarget(target_raw_output_);
 }

Input Image Data I420 or RGBA

// ...
// YUVI420
 source_raw_input_->uploadBytes(width,
                                height, 
                                bufferY,
                                strideY, 
                                bufferU, 
                                strideU,
                                bufferV, 
                                strideV);
// ...
// bytes: RGBA data
 source_raw_input_->uploadBytes(bytes,
                                width, 
                                height, 
                                stride);

Output Data Callback

// I420 callback
target_raw_output_->setI420Callbck([=](const uint8_t *data, 
                                        int width, 
                                        int height, 
                                        int64_t ts) {
    size_t y_size = width * height;
    const uint8_t *uData = data + y_size;
    const uint8_t *vData = data + y_size + y_size / 4;
    // Do something you want
});

// RGBA callback->
target_raw_output_->setPixelsCallbck([=](const uint8_t *data, 
                                        int width, 
                                        int height, 
                                        int64_t ts) {
    size_t rgba_size = width * height*4;
    // Do something you want
});

// Output data callbck
GPUPixel on GitHub: https://github.com/pixpark/gpupixel
Platform: Cross-platform
⭐️: 16
Advertisement

Trending