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

Convert AHardwareBuffer into OpenCV #1

Open
JaouadROS opened this issue Jan 3, 2024 · 1 comment
Open

Convert AHardwareBuffer into OpenCV #1

JaouadROS opened this issue Jan 3, 2024 · 1 comment

Comments

@JaouadROS
Copy link

Hello,
I want to convert AHardwareBuffer into OpenCV, have you tried this code? I want to do something similar but the mat I get is empty

//Convert Android HardwareBuffer to OpenCV Mat
jlong hardwareBufferToMat(AHardwareBuffer* hardwareBuffer) {
    AHardwareBuffer_Desc bufferDesc;
    AHardwareBuffer_describe(hardwareBuffer, &bufferDesc);
    //Get all pixels data
    void* buffer;
    AHardwareBuffer_lock(hardwareBuffer, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, -1, nullptr, &buffer);
    //Create OpenCV Mat
    auto *mat = new cv::Mat(bufferDesc.height, bufferDesc.width, CV_8UC4, buffer);
    AHardwareBuffer_unlock(hardwareBuffer, nullptr);
    return (jlong) mat;
}
@pboymt
Copy link
Owner

pboymt commented Jan 4, 2024

I'm sorry, the reason my project is currently suspended is that this code is not effective. The efficiency of using AccessibilityService's takeScreenshot is too low. If you can find a more efficient way in the future, please make sure to inform me.

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

2 participants