pixpark / gpupixel

Real-time image and video processing library similar to GPUImage, with built-in beauty filters, achieving commercial-grade beauty effects. Written in C++11 and based on OpenGL/ES.

Home Page:https://gpupixel.pixpark.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Can you add sample use GPUPixelSourceRawInput, TargetRawDataOutput

buiduylinh opened this issue · comments

Can you build a sample using GPUPixelSourceRawInput, TargetRawDataOutput? I see the iOS sample is quite comprehensive, but for Android, there's only a sample using the camera.
In this sample i have to use GPUPixelView to make sure that renderer can call onDraw, when i try to replace with TargetRawDataOutput. onDraw can't invoke

Raw data can be obtained through readPixelsWithPBO and rawOutputCallback

Seems that the TargetRawOutput class has not been implemented yet, could you provide some reference or examples?

Raw data can be obtained through readPixelsWithPBO and rawOutputCallback

Seems that the TargetRawOutput class has not been implemented yet, could you provide some reference or examples?

sourceRawDataInput->uploadBytes(width, height, dataY, strideY, dataU, strideUV, dataV, strideUV, timestamp);
isExpect=true;
targetRawDataOutput->readPixelsWithPBO(width,height);
……
……
……
void rawOutputCallback(const uint8_t* data, int width, int height, int64_t ts)
{
     if(!isExpect){
     return;
     }
    //obtain yuv data
}

Yeah I know how to use it in c++, but not good at writing jni and android codes. The example provided by GPUPixel has not implemented targetrawdataoutput class in jni and java, that's the problem. Anyway, thanks for the answer.

public class GPUPixelSourceRawInput extends GPUPixelSource {
    public GPUPixelSourceRawInput() {
        if (mNativeClassID != 0) return;
        GPUPixel.getInstance().runOnDraw(new Runnable() {
            @Override
            public void run() {
                mNativeClassID = GPUPixel.nativeSourceRawInputNew();
            }
        });
    }

    public void SetRotation(int rotation)
    {
        GPUPixel.nativeSourceRawInputSetRotation(mNativeClassID, rotation);
    }

    public void uploadBytes(final int[] pixels, int width, int height, int stride) {
        GPUPixel.nativeSourceRawInputUploadBytes(mNativeClassID, pixels, width, height, stride);
        proceed(true, false);
    }

}

I think it should be

public class GPUPixelSourceRawInput extends GPUPixelSource {
    public GPUPixelSourceRawInput() {
        if (mNativeClassID != 0) return;
        mNativeClassID = GPUPixel.nativeSourceRawInputNew();
    }

    public void SetRotation(int rotation)
    {
        GPUPixel.nativeSourceRawInputSetRotation(mNativeClassID, rotation);
    }

    public void uploadBytes(final int[] pixels, int width, int height, int stride) {
        GPUPixel.nativeSourceRawInputUploadBytes(mNativeClassID, pixels, width, height, stride);
        proceed(true, false);
    }

}
extern "C" jlong Java_com_pixpark_gpupixel_GPUPixel_nativeSourceRawInputNew(
    JNIEnv* env,
    jclass) {
  return 0;
};

--->

extern "C" jlong Java_com_pixpark_gpupixel_GPUPixel_nativeSourceRawInputNew(
    JNIEnv* env,
    jclass) {
  return SourceRawDataInput();
};

I tried to make edits on it, but the uploadBytes function isn't working.

It sounds like GPUPixelContext::getInstance()->runSync is supposed to create an eglContext if needed, but when I call this method, I encounter a rendering thread error.

public class GPUPixelSourceRawInput extends GPUPixelSource {
    public GPUPixelSourceRawInput() {
        if (mNativeClassID != 0) return;
        GPUPixel.getInstance().runOnDraw(new Runnable() {
            @Override
            public void run() {
                mNativeClassID = GPUPixel.nativeSourceRawInputNew();
            }
        });
    }

    public void SetRotation(int rotation)
    {
        GPUPixel.nativeSourceRawInputSetRotation(mNativeClassID, rotation);
    }

    public void uploadBytes(final int[] pixels, int width, int height, int stride) {
        GPUPixel.nativeSourceRawInputUploadBytes(mNativeClassID, pixels, width, height, stride);
        proceed(true, false);
    }

}

I think it should be

public class GPUPixelSourceRawInput extends GPUPixelSource {
    public GPUPixelSourceRawInput() {
        if (mNativeClassID != 0) return;
        mNativeClassID = GPUPixel.nativeSourceRawInputNew();
    }

    public void SetRotation(int rotation)
    {
        GPUPixel.nativeSourceRawInputSetRotation(mNativeClassID, rotation);
    }

    public void uploadBytes(final int[] pixels, int width, int height, int stride) {
        GPUPixel.nativeSourceRawInputUploadBytes(mNativeClassID, pixels, width, height, stride);
        proceed(true, false);
    }

}
extern "C" jlong Java_com_pixpark_gpupixel_GPUPixel_nativeSourceRawInputNew(
    JNIEnv* env,
    jclass) {
  return 0;
};

--->

extern "C" jlong Java_com_pixpark_gpupixel_GPUPixel_nativeSourceRawInputNew(
    JNIEnv* env,
    jclass) {
  return SourceRawDataInput();
};

I tried to make edits on it, but the uploadBytes function isn't working.

It sounds like GPUPixelContext::getInstance()->runSync is supposed to create an eglContext if needed, but when I call this method, I encounter a rendering thread error.

If you encounter a rendering thread error with that function, you may try manually setup GL. I managed to run it on windows.
void InitIO()
{
window = GPUPixelContext::getInstance()->GetGLContext();

if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return;
}

glfwMakeContextCurrent(window);

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
return;
}

GPUPixelContext::getInstance()->runSync([&] {
face_reshape_filter_ = FaceReshapeFilter::create();
beauty_face_filter_ = BeautyFaceFilter::create();
source_raw_input = SourceRawDataInput::create();
target_raw_data_output = TargetRawDataOutput::create();

source_raw_input->RegLandmarkCallback([=](std::vector<float> landmarks) {
  face_reshape_filter_->SetFaceLandmarks(landmarks);
});
source_raw_input->addTarget(face_reshape_filter_)
    ->addTarget(target_raw_data_output);

});
target_raw_data_output->setPixelsCallbck(
[=](const uint8_t* data, int width, int height, int64_t timestamp) {
cv::Mat output(height, width, CV_8UC4, (void*)data);
showmat = output;
std::cout << "target output callback" << endl;
});
}

@gezhaoyou Thanks for a great project, Can you add an example to use GPUPixelSourceRawInput on Android please, I attempted to integrate GPUPixel into my project (use SourceRawInput) but it's not working.