Skip to content

Commit

Permalink
other: remove face detect from demo and fix demo build error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaaronkot committed Jan 15, 2025
1 parent 12ff9f3 commit 20d9b83
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 387 deletions.
3 changes: 1 addition & 2 deletions examples/app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ IF(${CURRENT_OS} STREQUAL "linux")
gpupixel
GL
glfw)
SET(GPUPIXEL_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libgpupixel.so)
)
SET(GPUPIXEL_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libgpupixel.so)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-rpath,./")
ELSEIF(${CURRENT_OS} STREQUAL "windows")
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
Expand Down
255 changes: 92 additions & 163 deletions examples/desktop/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
#include "gpupixel.h"
using namespace gpupixel;


std::shared_ptr<BeautyFaceFilter> beauty_face_filter_;
std::shared_ptr<FaceReshapeFilter> face_reshape_filter_;
std::shared_ptr<gpupixel::LipstickFilter> lipstick_filter_;
std::shared_ptr<gpupixel::BlusherFilter> blusher_filter_;
std::shared_ptr<SourceImage> gpuSourceImage;
std::shared_ptr<TargetRawDataOutput> output_;
std::shared_ptr<TargetView> target_view;
Expand All @@ -22,181 +18,114 @@ float lipstickValue = 0;
float blusherValue = 0;

void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);
void processInput(GLFWwindow* window);

void error_callback( int error, const char *msg ) {
std::string s;
s = " [" + std::to_string(error) + "] " + msg + '\n';
std::cerr << s << std::endl;
void error_callback(int error, const char* msg) {
std::string s;
s = " [" + std::to_string(error) + "] " + msg + '\n';
std::cerr << s << std::endl;
}

int main()
{
glfwInit();
GLFWwindow* window = GPUPixelContext::getInstance()->GetGLContext();

if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
int main() {
glfwInit();
GLFWwindow* window = GPUPixelContext::getInstance()->GetGLContext();

gladLoadGL();
glfwMakeContextCurrent(window);

glfwShowWindow(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

// create filter
// ----
lipstick_filter_ = LipstickFilter::create();
blusher_filter_ = BlusherFilter::create();
face_reshape_filter_ = FaceReshapeFilter::create();

// filter pipline
// ----
gpuSourceImage = SourceImage::create("demo.png");
target_view = std::make_shared<TargetView>();

gpuSourceImage->RegLandmarkCallback([=](std::vector<float> landmarks) {
lipstick_filter_->SetFaceLandmarks(landmarks);
blusher_filter_->SetFaceLandmarks(landmarks);
face_reshape_filter_->SetFaceLandmarks(landmarks);
});

beauty_face_filter_ = BeautyFaceFilter::create();


// gpuSourceImage->addTarget(beauty_face_filter_)
// ->addTarget(target_view);

gpuSourceImage->addTarget(lipstick_filter_)
->addTarget(blusher_filter_)
->addTarget(face_reshape_filter_)
->addTarget(beauty_face_filter_)
->addTarget(target_view);

//
target_view->onSizeChanged(1280, 720);

// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
// input
// -----
processInput(window);

//
// -----
gpuSourceImage->Render();

// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}


// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return 0;
}

// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow *window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);

if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
beautyValue++;
if(beautyValue > 10.0) beautyValue = 10.0;
beauty_face_filter_->setBlurAlpha(beautyValue/10);
}

if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
beautyValue--;
if(beautyValue < 0.0) beautyValue = 0.0;
beauty_face_filter_->setBlurAlpha(beautyValue/10);
}


if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
whithValue++;
if(whithValue > 10.0) whithValue = 10.0;
beauty_face_filter_->setWhite(whithValue/20);
}

if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) {
whithValue--;
if(whithValue < 0.0) whithValue = 0.0;
beauty_face_filter_->setWhite(whithValue/20);
}
return -1;
}

if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
thinFaceValue++;
if(thinFaceValue > 10.0) thinFaceValue = 10.0;
face_reshape_filter_->setFaceSlimLevel(thinFaceValue/200);
}

if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS) {
thinFaceValue--;
if(thinFaceValue < 0.0) thinFaceValue = 0.0;
face_reshape_filter_->setFaceSlimLevel(thinFaceValue/200);
}
gladLoadGL();
glfwMakeContextCurrent(window);

if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) {
bigeyeValue++;
if(bigeyeValue > 10.0) bigeyeValue = 10.0;
face_reshape_filter_->setEyeZoomLevel(bigeyeValue/100);
}

if (glfwGetKey(window, GLFW_KEY_V) == GLFW_PRESS) {
bigeyeValue--;
if(bigeyeValue < 0.0) bigeyeValue = 0.0;
face_reshape_filter_->setEyeZoomLevel(bigeyeValue/100);
}

if (glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS) {
lipstickValue++;
if(lipstickValue > 10.0) lipstickValue = 10.0;
glfwShowWindow(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

// ----
// filter pipline
// ----
gpuSourceImage = SourceImage::create("demo.png");
target_view = std::make_shared<TargetView>();

beauty_face_filter_ = BeautyFaceFilter::create();

gpuSourceImage->addTarget(beauty_face_filter_);
beauty_face_filter_->addTarget(target_view);

//
target_view->onSizeChanged(1280, 720);

// render loop
// -----------
while (!glfwWindowShouldClose(window)) {
// input
// -----
processInput(window);

//
// -----
gpuSourceImage->Render();

// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved
// etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}

// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}

lipstick_filter_->setBlendLevel(lipstickValue/10);
// process all input: query GLFW whether relevant keys are pressed/released this
// frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow* window) {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}

if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
beautyValue++;
if (beautyValue > 10.0) {
beautyValue = 10.0;
}
beauty_face_filter_->setBlurAlpha(beautyValue / 10);
}

if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS) {
lipstickValue--;
if(lipstickValue < 0.0) lipstickValue = 0.0;

lipstick_filter_->setBlendLevel(lipstickValue/10);
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
beautyValue--;
if (beautyValue < 0.0) {
beautyValue = 0.0;
}
beauty_face_filter_->setBlurAlpha(beautyValue / 10);
}

if (glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS) {
blusherValue++;
if(blusherValue > 10.0) blusherValue = 10.0;

blusher_filter_->setBlendLevel(blusherValue/10);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
whithValue++;
if (whithValue > 10.0) {
whithValue = 10.0;
}
beauty_face_filter_->setWhite(whithValue / 20);
}

if (glfwGetKey(window, GLFW_KEY_N) == GLFW_PRESS) {
blusherValue--;
if(blusherValue < 0.0) blusherValue = 0.0;

blusher_filter_->setBlendLevel(blusherValue/10);
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) {
whithValue--;
if (whithValue < 0.0) {
whithValue = 0.0;
}

beauty_face_filter_->setWhite(whithValue / 20);
}
}

// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// glfw: whenever the window size changed (by OS or user resize) this callback
// function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);

void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
// make sure the viewport matches the new window dimensions; note that width
// and height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
12 changes: 0 additions & 12 deletions examples/ios/GPUPixelApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
/* Begin PBXBuildFile section */
840CD3D42B88448900EEF7B0 /* gpupixel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840CD3D32B88448900EEF7B0 /* gpupixel.framework */; };
840CD3D52B88448900EEF7B0 /* gpupixel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840CD3D32B88448900EEF7B0 /* gpupixel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
840FD5CF2B82455100781FA6 /* vnn_kit_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CC2B82455100781FA6 /* vnn_kit_ios.framework */; };
840FD5D02B82455100781FA6 /* vnn_kit_ios.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CC2B82455100781FA6 /* vnn_kit_ios.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
840FD5D12B82455100781FA6 /* vnn_face_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CD2B82455100781FA6 /* vnn_face_ios.framework */; };
840FD5D22B82455100781FA6 /* vnn_face_ios.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CD2B82455100781FA6 /* vnn_face_ios.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
840FD5D32B82455100781FA6 /* vnn_core_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CE2B82455100781FA6 /* vnn_core_ios.framework */; };
840FD5D42B82455100781FA6 /* vnn_core_ios.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CE2B82455100781FA6 /* vnn_core_ios.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
8417C43A267F5AF10074DDEF /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8417C437267F5AF10074DDEF /* AVFoundation.framework */; };
8417C43C267F5B470074DDEF /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8417C43B267F5B470074DDEF /* CoreMedia.framework */; };
84307E91261F2CD9003EAC98 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84307E90261F2CD9003EAC98 /* AppDelegate.m */; };
Expand All @@ -38,9 +32,6 @@
dstSubfolderSpec = 10;
files = (
840CD3D52B88448900EEF7B0 /* gpupixel.framework in Embed Frameworks */,
840FD5D02B82455100781FA6 /* vnn_kit_ios.framework in Embed Frameworks */,
840FD5D42B82455100781FA6 /* vnn_core_ios.framework in Embed Frameworks */,
840FD5D22B82455100781FA6 /* vnn_face_ios.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -83,11 +74,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
840FD5CF2B82455100781FA6 /* vnn_kit_ios.framework in Frameworks */,
840FD5D32B82455100781FA6 /* vnn_core_ios.framework in Frameworks */,
840CD3D42B88448900EEF7B0 /* gpupixel.framework in Frameworks */,
8417C43C267F5B470074DDEF /* CoreMedia.framework in Frameworks */,
840FD5D12B82455100781FA6 /* vnn_face_ios.framework in Frameworks */,
8417C43A267F5AF10074DDEF /* AVFoundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Loading

0 comments on commit 20d9b83

Please sign in to comment.