Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Got empty output when first calling SourceRawDataInput-> uploadBytes. #66

Closed
quqixun opened this issue May 27, 2024 · 6 comments
Closed

Comments

@quqixun
Copy link

quqixun commented May 27, 2024

I have read "How to Use" section in README, desktop app and #54 :

I tried to demo a simple example using SourceRawDataInput and TargetRawDataOutput in C++.
However, empty output data was obtained in target_raw_output->setPixelsCallbck when first calling source_raw_input->uploadBytes.
What is going on here? How to fix it?
Thanks.

#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <iostream>
#include "gpupixel.h"
using namespace gpupixel;

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"


std::shared_ptr<SourceRawDataInput> source_raw_input;
std::shared_ptr<TargetRawDataOutput> target_raw_output;
std::shared_ptr<BeautyFaceFilter> beauty_face_filter;
std::shared_ptr<FaceReshapeFilter> face_reshape_filter;
std::shared_ptr<LipstickFilter> lipstick_filter;
std::shared_ptr<BlusherFilter> blusher_filter;


// check values of first row of image
void checkImageDataValue(const uint8_t* imageData, int width, int height, int channels) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            for (int c = 0; c < channels; ++c) {
                std::cout << y << " " << x << " " << c << " " << imageData[(y * width + x) * channels + c] << std::endl;
                break;
            }
            break;
        }
    }
}


int main(int argc, char* argv[])
{

    std::string imagePath = "demo.png";
    float beautyValue = 0.0;
    float whithValue = 0.0;
    float thinFaceValue = 0.0;
    float bigeyeValue = 0.0;
    float lipstickValue = 0.0;
    float blusherValue = 0.0;

    // read input image
    int width, height, channel;
    uint8_t* imageData = stbi_load(imagePath.c_str(), &width, &height, &channel, 0);
    if(imageData == nullptr) {
        std::cerr << "Failed to read image" << std::endl;
        return -1;
    }

    GLFWwindow* window = GPUPixelContext::getInstance()->GetGLContext();
    if (window == NULL) {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    // glad: load all OpenGL function pointers
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;
    }

    GPUPixelContext::getInstance()->runSync([&] {
        source_raw_input = SourceRawDataInput::create();
        face_reshape_filter = FaceReshapeFilter::create();
        lipstick_filter = LipstickFilter::create();
        blusher_filter = BlusherFilter::create();
        beauty_face_filter = BeautyFaceFilter::create();
        target_raw_output = TargetRawDataOutput::create();        

        source_raw_input->RegLandmarkCallback([=](std::vector<float> landmarks) {

            // check landmarks, correct
            // std::cout << "landmarks:" << std::endl;
            // for (size_t i = 0; i < landmarks.size(); ++i) {
            //     std::cout << landmarks[i] << " ";
            // }
            // std::cout << std::endl;

            lipstick_filter->SetFaceLandmarks(landmarks);
            blusher_filter->SetFaceLandmarks(landmarks);
            face_reshape_filter->SetFaceLandmarks(landmarks);
        });

        target_raw_output->setPixelsCallbck([=](const uint8_t* outputData,
                                                int outputWidth,
                                                int outputHeight,
                                                int64_t ts) {
            std::cout << "channel: " << channel << std::endl;
            std::cout << "outputWidth: " << outputWidth << std::endl;
            std::cout << "outputHeight: " << outputHeight << std::endl;

            // ------------------------------------------------------------------------------
            // empty outputData when first calling source_raw_input->uploadBytes
            checkImageDataValue(outputData, outputWidth, outputHeight, channel);
            // ------------------------------------------------------------------------------
        });

        source_raw_input->addTarget(lipstick_filter)
                    ->addTarget(blusher_filter)
                    ->addTarget(face_reshape_filter)
                    ->addTarget(beauty_face_filter)
                    ->addTarget(target_raw_output);
    });

    beauty_face_filter->setBlurAlpha(beautyValue / 10);
    beauty_face_filter->setWhite(whithValue / 20);
    face_reshape_filter->setFaceSlimLevel(thinFaceValue / 200);
    face_reshape_filter->setEyeZoomLevel(bigeyeValue / 100);
    lipstick_filter->setBlendLevel(lipstickValue / 10);
    blusher_filter->setBlendLevel(blusherValue / 10);

    source_raw_input->uploadBytes(imageData, width, height, width);  // got empty outputData
    source_raw_input->uploadBytes(imageData, width, height, width);  // got correct outputData

    stbi_image_free(imageData);
    return 0;
}
@qwonderkid
Copy link

I've met similar issues. Try continously uploadbytes.
while(true)
{
source_raw_input->uploadBytes(imageData, width, height, width);
}
Then get the correct output

@quqixun
Copy link
Author

quqixun commented May 28, 2024

I've met similar issues. Try continously uploadbytes. while(true) { source_raw_input->uploadBytes(imageData, width, height, width); } Then get the correct output

Thanks. It works.
The while loop is not necessary. I tried to run uploadBytes two times :

source_raw_input->uploadBytes(imageData, width, height, width);  // got empty outputData
source_raw_input->uploadBytes(imageData, width, height, width);  // got correct outputData

I think it is a bug.

@quqixun quqixun changed the title Try to make a simple example using SourceRawDataInput and TargetRawDataOutput in C++ work. [Bug] Got wrong output when first call SourceRawDataInput-> uploadBytes. May 28, 2024
@quqixun quqixun changed the title [Bug] Got wrong output when first call SourceRawDataInput-> uploadBytes. [Bug] Got empty output when first calling SourceRawDataInput-> uploadBytes. May 28, 2024
@tu461987807
Copy link

i've get similar issues.

@tu461987807
Copy link

in TargetRawDataOutput::readPixelsWithPBO function ,when I annotated these two sentences, it was fine
//index = (index + 1) % 2;
//nextIndex = (index + 1) % 2;

@quqixun
Copy link
Author

quqixun commented Jun 3, 2024

in TargetRawDataOutput::readPixelsWithPBO function ,when I annotated these two sentences, it was fine //index = (index + 1) % 2; //nextIndex = (index + 1) % 2;

Thanks. It works.

@quqixun quqixun closed this as completed Jun 5, 2024
@VictorQiuYY
Copy link

image
怎么编译动态链接库啊。 需要改什么?。 现在编译后一直提示 无法解析的外部符号。 我试了很多编译方式都没有成功

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants