Comments (5)
Closed! I'm forgot to add gpupixel.framework
, vnn_core_osx.framework
, vnn_face_osx.framework
,vnn_kit_osx.framework
in Frameworks and Libraries
. Btw, this is full my code:
//
// RTCBeautyFilter.mm
// flutter_webrtc
//
// Created by lambiengcode on 19/03/2024.
//
#import "RTCBeautyFilter.h"
#import "gpupixel/gpupixel.h"
using namespace gpupixel;
@interface RTCBeautyFilter () {
std::shared_ptr<SourceRawDataInput> gpuPixelRawInput;
std::shared_ptr<BeautyFaceFilter> beauty_face_filter_;
std::shared_ptr<TargetRawDataOutput> targetRawOutput_;
std::shared_ptr<FaceReshapeFilter> face_reshape_filter_;
std::shared_ptr<gpupixel::FaceMakeupFilter> lipstick_filter_;
std::shared_ptr<gpupixel::FaceMakeupFilter> blusher_filter_;
}
@end
@implementation RTCBeautyFilter
@synthesize delegate = _delegate;
- (instancetype)initWithDelegate:(id<RTCBeautyFilterDelegate>)delegate {
self = [super init];
if (self) {
self.delegate = delegate;
[self setup];
}
return self;
}
- (void)setup {
// Init video filter
[self initVideoFilter];
}
- (void)initVideoFilter {
gpupixel::GPUPixelContext::getInstance()->runSync([&] {
gpuPixelRawInput = SourceRawDataInput::create();
// Create filters
lipstick_filter_ = LipstickFilter::create();
blusher_filter_ = BlusherFilter::create();
face_reshape_filter_ = FaceReshapeFilter::create();
gpuPixelRawInput->RegLandmarkCallback([=](std::vector<float> landmarks) {
lipstick_filter_->SetFaceLandmarks(landmarks);
blusher_filter_->SetFaceLandmarks(landmarks);
face_reshape_filter_->SetFaceLandmarks(landmarks);
});
// Create filter
targetRawOutput_ = TargetRawDataOutput::create();
beauty_face_filter_ = BeautyFaceFilter::create();
id<RTCBeautyFilterDelegate> delegatePtr = _delegate;
RawOutputCallback callback = [delegatePtr](const uint8_t* data, int width, int height, int64_t ts) {
CVPixelBufferRef pixelBuffer = NULL;
size_t stride = width * 4;
#if TARGET_OS_IOS || TARGET_OS_SIMULATOR
// iOS: Use original data directly for BGRA format
// Create pixel buffer attributes
NSDictionary *options = @{
(NSString *)kCVPixelBufferCGImageCompatibilityKey: @YES,
(NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey: @YES
};
// Create pixel buffer
CVReturn result = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,
width,
height,
kCVPixelFormatType_32BGRA,
(void *)data,
stride,
NULL,
NULL,
(__bridge CFDictionaryRef)options,
&pixelBuffer);
#else
// macOS: Convert ABGR or BGRA to ARGB
// Create a new buffer to store ARGB pixel data
uint8_t* argbData = (uint8_t*)malloc(stride * height);
if (!argbData) {
NSLog(@"Error: Unable to allocate memory for ARGB pixel data");
return;
}
// Convert ABGR or BGRA to ARGB
for (int i = 0; i < width * height; ++i) {
argbData[i * 4 + 0] = data[i * 4 + 3]; // Alpha
argbData[i * 4 + 1] = data[i * 4 + 0]; // Red
argbData[i * 4 + 2] = data[i * 4 + 1]; // Green
argbData[i * 4 + 3] = data[i * 4 + 2]; // Blue
}
// Create pixel buffer attributes
NSDictionary *options = @{
(NSString *)kCVPixelBufferCGImageCompatibilityKey: @YES,
(NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey: @YES
};
// Create pixel buffer
CVReturn result = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,
width,
height,
kCVPixelFormatType_32ARGB,
(void *)argbData,
stride,
NULL,
NULL,
(__bridge CFDictionaryRef)options,
&pixelBuffer);
free(argbData); // Free the memory allocated for ARGB data
#endif
if (result != kCVReturnSuccess) {
NSLog(@"Error: Unable to create CVPixelBuffer");
return;
}
if (delegatePtr) {
[delegatePtr didReceivePixelBuffer:pixelBuffer width:width height:height timestamp:ts];
}
CVPixelBufferRelease(pixelBuffer);
};
targetRawOutput_->setPixelsCallbck(callback);
gpuPixelRawInput->addTarget(lipstick_filter_)
->addTarget(blusher_filter_)
->addTarget(face_reshape_filter_)
->addTarget(beauty_face_filter_)
->addTarget(targetRawOutput_);
});
}
#pragma mark - Property assignment
- (void)setBeautyValue:(CGFloat)value {
_beautyValue = value;
beauty_face_filter_->setBlurAlpha(value);
}
- (void)setWhithValue:(CGFloat)value {
_whithValue = value;
beauty_face_filter_->setWhite(value);
}
- (void)setThinFaceValue:(CGFloat)value {
_thinFaceValue = value;
face_reshape_filter_->setFaceSlimLevel(value);
}
- (void)setEyeValue:(CGFloat)value {
_eyeValue = value;
face_reshape_filter_->setEyeZoomLevel(value);
}
- (void)setLipstickValue:(CGFloat)value {
_lipstickValue = value;
lipstick_filter_->setBlendLevel(value);
}
- (void)setBlusherValue:(CGFloat)value {
_blusherValue = value;
blusher_filter_->setBlendLevel(value);
}
- (void)processVideoFrame:(CVPixelBufferRef)imageBuffer {
CVPixelBufferLockBaseAddress(imageBuffer, 0);
auto width = CVPixelBufferGetWidth(imageBuffer);
auto height = CVPixelBufferGetHeight(imageBuffer);
auto stride = CVPixelBufferGetBytesPerRow(imageBuffer)/4;
auto pixels = (const uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
gpuPixelRawInput->uploadBytes(pixels, width, height, stride);
CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
}
size_t getBufferSizeFromPixelBuffer(CVPixelBufferRef pixelBuffer) {
// Get the bytes per row and height of the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);
// Calculate the buffer size
size_t bufferSize = bytesPerRow * height;
return bufferSize;
}
NSString* getPixelFormatName(CVPixelBufferRef pixelBuffer) {
OSType p = CVPixelBufferGetPixelFormatType(pixelBuffer);
switch (p) {
case kCVPixelFormatType_1Monochrome: return @"kCVPixelFormatType_1Monochrome";
case kCVPixelFormatType_2Indexed: return @"kCVPixelFormatType_2Indexed";
case kCVPixelFormatType_4Indexed: return @"kCVPixelFormatType_4Indexed";
case kCVPixelFormatType_8Indexed: return @"kCVPixelFormatType_8Indexed";
case kCVPixelFormatType_1IndexedGray_WhiteIsZero: return @"kCVPixelFormatType_1IndexedGray_WhiteIsZero";
case kCVPixelFormatType_2IndexedGray_WhiteIsZero: return @"kCVPixelFormatType_2IndexedGray_WhiteIsZero";
case kCVPixelFormatType_4IndexedGray_WhiteIsZero: return @"kCVPixelFormatType_4IndexedGray_WhiteIsZero";
case kCVPixelFormatType_8IndexedGray_WhiteIsZero: return @"kCVPixelFormatType_8IndexedGray_WhiteIsZero";
case kCVPixelFormatType_16BE555: return @"kCVPixelFormatType_16BE555";
case kCVPixelFormatType_16LE555: return @"kCVPixelFormatType_16LE555";
case kCVPixelFormatType_16LE5551: return @"kCVPixelFormatType_16LE5551";
case kCVPixelFormatType_16BE565: return @"kCVPixelFormatType_16BE565";
case kCVPixelFormatType_16LE565: return @"kCVPixelFormatType_16LE565";
case kCVPixelFormatType_24RGB: return @"kCVPixelFormatType_24RGB";
case kCVPixelFormatType_24BGR: return @"kCVPixelFormatType_24BGR";
case kCVPixelFormatType_32ARGB: return @"kCVPixelFormatType_32ARGB";
case kCVPixelFormatType_32BGRA: return @"kCVPixelFormatType_32BGRA";
case kCVPixelFormatType_32ABGR: return @"kCVPixelFormatType_32ABGR";
case kCVPixelFormatType_32RGBA: return @"kCVPixelFormatType_32RGBA";
case kCVPixelFormatType_64ARGB: return @"kCVPixelFormatType_64ARGB";
case kCVPixelFormatType_48RGB: return @"kCVPixelFormatType_48RGB";
case kCVPixelFormatType_32AlphaGray: return @"kCVPixelFormatType_32AlphaGray";
case kCVPixelFormatType_16Gray: return @"kCVPixelFormatType_16Gray";
case kCVPixelFormatType_30RGB: return @"kCVPixelFormatType_30RGB";
case kCVPixelFormatType_422YpCbCr8: return @"kCVPixelFormatType_422YpCbCr8";
case kCVPixelFormatType_4444YpCbCrA8: return @"kCVPixelFormatType_4444YpCbCrA8";
case kCVPixelFormatType_4444YpCbCrA8R: return @"kCVPixelFormatType_4444YpCbCrA8R";
case kCVPixelFormatType_4444AYpCbCr8: return @"kCVPixelFormatType_4444AYpCbCr8";
case kCVPixelFormatType_4444AYpCbCr16: return @"kCVPixelFormatType_4444AYpCbCr16";
case kCVPixelFormatType_444YpCbCr8: return @"kCVPixelFormatType_444YpCbCr8";
case kCVPixelFormatType_422YpCbCr16: return @"kCVPixelFormatType_422YpCbCr16";
case kCVPixelFormatType_422YpCbCr10: return @"kCVPixelFormatType_422YpCbCr10";
case kCVPixelFormatType_444YpCbCr10: return @"kCVPixelFormatType_444YpCbCr10";
case kCVPixelFormatType_420YpCbCr8Planar: return @"kCVPixelFormatType_420YpCbCr8Planar";
case kCVPixelFormatType_420YpCbCr8PlanarFullRange: return @"kCVPixelFormatType_420YpCbCr8PlanarFullRange";
case kCVPixelFormatType_422YpCbCr_4A_8BiPlanar: return @"kCVPixelFormatType_422YpCbCr_4A_8BiPlanar";
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: return @"kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange";
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange: return @"kCVPixelFormatType_420YpCbCr8BiPlanarFullRange";
case kCVPixelFormatType_422YpCbCr8_yuvs: return @"kCVPixelFormatType_422YpCbCr8_yuvs";
case kCVPixelFormatType_422YpCbCr8FullRange: return @"kCVPixelFormatType_422YpCbCr8FullRange";
case kCVPixelFormatType_OneComponent8: return @"kCVPixelFormatType_OneComponent8";
case kCVPixelFormatType_TwoComponent8: return @"kCVPixelFormatType_TwoComponent8";
case kCVPixelFormatType_30RGBLEPackedWideGamut: return @"kCVPixelFormatType_30RGBLEPackedWideGamut";
case kCVPixelFormatType_OneComponent16Half: return @"kCVPixelFormatType_OneComponent16Half";
case kCVPixelFormatType_OneComponent32Float: return @"kCVPixelFormatType_OneComponent32Float";
case kCVPixelFormatType_TwoComponent16Half: return @"kCVPixelFormatType_TwoComponent16Half";
case kCVPixelFormatType_TwoComponent32Float: return @"kCVPixelFormatType_TwoComponent32Float";
case kCVPixelFormatType_64RGBAHalf: return @"kCVPixelFormatType_64RGBAHalf";
case kCVPixelFormatType_128RGBAFloat: return @"kCVPixelFormatType_128RGBAFloat";
case kCVPixelFormatType_14Bayer_GRBG: return @"kCVPixelFormatType_14Bayer_GRBG";
case kCVPixelFormatType_14Bayer_RGGB: return @"kCVPixelFormatType_14Bayer_RGGB";
case kCVPixelFormatType_14Bayer_BGGR: return @"kCVPixelFormatType_14Bayer_BGGR";
case kCVPixelFormatType_14Bayer_GBRG: return @"kCVPixelFormatType_14Bayer_GBRG";
default: return @"UNKNOWN";
}
}
@end
from gpupixel.
The product is excellent
from gpupixel.
Background removal is being implemented, but the Disney face effect doesn't feel quite good. Currently, there are no plans to implement it.
from gpupixel.
Thank you very much @gezhaoyou. Do you intend to add features such as background removal or disney face? It would be very interesting to apply it to a video conferencing app. I bet many people will be interested in this feature.
from gpupixel.
Hi, @gezhaoyou,
I'm implement for Android now, when I uploadBytes
, it will execute genTextureWithRGBA
but can't set framebuffer.
this->setFramebuffer(_framebuffer, NoRotation);
and as the result, when call this->getFramebuffer()->active();
it's crash because nullptr. So I decided to change:
this->setFramebuffer(_framebuffer, NoRotation);
to this->Source::setFramebuffer(_framebuffer, _rotation);
but when call Source::proceed(true, ts);
, the _framebuffer null and it crash when call:
target->setInputFramebuffer(_framebuffer, _outputRotation,
_targets[target]);
Thank you for take your time in my issue.
from gpupixel.
Related Issues (20)
- 我在linux上运行,想把结果保存到本地,怎么实现? HOT 2
- 我在linux上运行,想把结果保存到本地,发现问题
- [BUG] hue_filter出错
- [BUG]centos上无法安装对应的依赖库 HOT 1
- 使用windows自带的测试,换了一个demo.png就闪退了。是图片有什么特别的要求吗 HOT 3
- [BUG]在iOS工程中导入相关framework后,图片出现反色现象 HOT 3
- A simple python wrapper for gpupixel using SourceRawDataInput and TargetRawDataOutput. HOT 1
- 这么好的东西,大佬能发布成flutter插件吗?一定很受欢迎 HOT 2
- [Feature Request] HOT 3
- msvc编译器如何编译 HOT 6
- glad问题 HOT 1
- Filters flickering
- [BUG] 任何一张其他的图片都会在这里报错,是图片格式问题吗,图片美颜功能在iOS上无法使用 HOT 1
- linux demo cmake failed HOT 4
- [BUG]编译报错 HOT 1
- [Feature Request] API Only HOT 4
- 处理视频数据报错!
- [BUG] 在android7.1的手机上预览图象是黑白的,应该怎么解决
- Python support [Feature Request]
- [Feature Request] 请问 WebAssembly 接下来有何计划吗?我们我看到 wasm.toolchain.cmake 已经存在了,但是还没对外发布。 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpupixel.