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

why halide blur algorithm is slower than the blur by opencv #8166

Closed
halcomcn opened this issue Mar 29, 2024 · 1 comment
Closed

why halide blur algorithm is slower than the blur by opencv #8166

halcomcn opened this issue Mar 29, 2024 · 1 comment

Comments

@halcomcn
Copy link

halcomcn commented Mar 29, 2024

loop 30 times, compare infos output:

image channel: 1
Halide Elapsed time: 7274 ms
Opencv Elapsed time: 23 ms
Halide: Done

someone can help me to explain it?
I am first time to coding halide program. thanks.

I had try some schedule to speed up, but halide is slower than opencv, it is so weird.

if I want to speed up, how can I modify these codes to get good result.

int main()
{
    cv::Mat image;
    image = imread("C:\\AIOCRProjects\\Image\\1 (1).jpg", 0); // GrayImage
    std::cout << "image channel: " << image.channels() << std::endl;

    ////////////////////////////////////////////////////////////
    auto startH = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < 30; i++)
    {
        // Halide-17.0.1-x86-64-windows C++ --> Win10+64bit+VS2022
        cv::Mat HalideBlur;
        HalideBlur = aiPredict.BlurHal(image);
        cv::Mat HalideThreshold;
        HalideThreshold = aiPredict.ThresholdHal(HalideBlur, 128.0f);
    }
    auto endH = std::chrono::high_resolution_clock::now();
    auto durationH = std::chrono::duration_cast<std::chrono::milliseconds>(endH - startH);
    std::cout << "Halide Elapsed time: " << durationH.count() << " ms" << std::endl;
    //
    auto startO = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < 30; i++)
    {
        // opencv C++ --> Win10+64bit+VS2022
        cv::Mat opencvBlur;
        cv::blur(image, opencvBlur, cv::Size(3, 3));
        cv::Mat opencvThreshold;
        cv::threshold(opencvBlur, opencvThreshold, 128.0, 255.0, cv::THRESH_BINARY);
    }
    auto endO = std::chrono::high_resolution_clock::now();
    auto durationO = std::chrono::duration_cast<std::chrono::milliseconds>(endO - startO);
    std::cout << "Opencv Elapsed time: " << durationO.count() << " ms" << std::endl;
    ////////////////////////////////////////////////////////////
    std::cout << "Halide: " << "Done" << std::endl;

}



@halcomcn
Copy link
Author

need to learn it step by step. it is more much faster

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

1 participant