Results 1 to 5 of 5

Thread: OpenCL module for OpenCV

  1. #1

    OpenCL module for OpenCV

    We've developed a OpenCL module for OpenCV and have submitted as a branch of opencv code base:
    We'd developers of image processing can be benefit from this piece of work. The basic idea of this module is similar to OpenCV's gpu module, but enable none CUDA GPUs to run OpenCV functions. We also feel happy if OpenCL programers learn technics from our kernels when using it.

    This version of OpenCV is based on OpenCV2.31. Please copy the FindOpenCL.cmake to you CMake's share folder so that it can find your OpenCL path. And this module is only tested on AMD's GPU, but i think that's enough.

  2. #2
    Junior Member
    Join Date
    Mar 2012

    Re: OpenCL module for OpenCV


    first of all thx for your great work. I've tried to run your StereoBM algorithm on my GPU with the following sample code. Thereby my whole system crashs at:
    Code :
    bm(left_ocl, right_ocl, disp_ocl);

    Do you see any misstakes in my sample code?
    I would be happy if i get your great code running on my GPU : )

    Code :
    #include <CL/cl.hpp>
    #include <stdio.h>
    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cstdlib>
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <iterator>
    #include "opencv2/ocl/ocl.hpp"
    #include "opencv2/highgui/highgui.hpp"
    using namespace cv;
    using namespace cv::ocl;
    using namespace std;
    void print_help()
            printf("\nOpenCL Test\n");
            printf("\nUsage: stereo_test <left_image> <right_image>\n");
    void checkErr(cl_int err, const char * name)
        if (err != CL_SUCCESS) {
            std::cerr << "ERROR: " << name << " (" << err << ")" << std::endl;
    int main(int argc, char** argv)
        const char* img1_filename = 0;
        const char* img2_filename = 0;
        if(argc < 3)
            return 0;
            img1_filename = argv[1];
            img2_filename = argv[2];
        //Device Zugriff
        printf("Begin creating ocl context...\n");
        ClContext* context_ocl = ClContext::getContext();
        printf("End creating ocl context...\n");
        //Bild links
        Mat left_orig;
        Mat left_gray;
        oclMat left_ocl;
        //Bild rechts
        Mat right_orig;
        Mat right_gray;
        oclMat right_ocl;
        //Mat disp_orig;
        //oclMat disp_ocl;
        Size img_size;
        //Vorverarbeitung der Bilddaten
        printf("Begin image preprocessing...\n");
        //Linkes und rechtes Bild vorverarbeiten
        left_orig = imread(img1_filename);
        right_orig = imread(img2_filename);
        cvtColor(left_orig, left_gray, CV_BGR2GRAY);
        cvtColor(right_orig, right_gray, CV_BGR2GRAY);
        left_ocl = left_gray;
        right_ocl = right_gray;
        img_size = left_gray.size();
        //Disparität vorbereiten
        Mat disp_orig(img_size, CV_8U);
        oclMat disp_ocl; //(img_size, CV_8U);
        printf("End image preprocessing...\n");
        //Kontextinformationen zuweisen
        printf("Begin applying context...\n");
        left_ocl.clCxt = context_ocl;
        right_ocl.clCxt = context_ocl;
        disp_ocl.clCxt = context_ocl;
        printf("End applying context...\n");
        printf("Begin init algorithm...\n");
        //Algorithmus initialisieren
        bm.preset = StereoBM_GPU::BASIC_PRESET;
        bm.ndisp = StereoBM_GPU::DEFAULT_NDISP;
        bm.winSize = StereoBM_GPU::DEFAULT_WINSZ;
        printf("End init algorithm...\n");
        printf("Begin calculation...\n");
        int64 t = getTickCount();
        bm(left_ocl, right_ocl, disp_ocl);
        t = getTickCount() - t;
        printf("End calculation...\nTime elapsed: %fms\n", t*1000/getTickFrequency());
        //Disparität umwandeln
        disp_orig = disp_ocl;
        return 0;

    More information about my system:
    Board: Kontron KTA55/pITX ( ... 5pitx.html )
    CPU: AMD G-T40N
    GPU: ATI Radeon HD6290

    System: Ubuntu 10.04 (64Bit)
    Driver: AMD Catalyst 12.3 (64Bit)
    APP SDK: AMD-APP-SDK-v2.6-lnx64.tgz
    With best regards

  3. #3
    Junior Member
    Join Date
    Mar 2012

    Re: OpenCL module for OpenCV

    I would like to first thanks bitwangyaoyao due to sharing this code. OpenCV is definitely needing OpenCL support and any effort like this is undoubtedly welcome!

    I have just started messing around with bitwangyaoyao's OpenCV-OpenCL svn branch and since I have not found any sample code, I decided to give a try at Horego's code.

    I wasn't expecting this, but the code just worked fine without any kind of modification. I have tested with 2 images (Teddy/img2 and Teddy/img6 from No pre-processing on the images was done.

    The test machine is the following:
    Ubuntu 11.04 x64
    Kernel 2.6.39-02063902-generic
    Driver: Catalyst 12.2 (x64)
    APP SDK: AMD-APP-SDK-v2.6-lnx64.tgz
    CPU: Core i5-2400S
    GPU: ATI Radeon HD6750M

    I think Horego's system is very similar to mine. Maybe he should try to test using the same images that I referenced.

  4. #4

    Re: OpenCL module for OpenCV

    Thanks vlab & Horego's trying. As it is still under developement, some bugs need fix. But it's growing fast recently, and the code now is moved with OpenCV repository to Git. (git://
    For the StereoBM, i'm afraid there still have some problem to make it running. But most of other functions are working. We'll try to fix the problems and add a sample about Stereo.

  5. #5
    Junior Member
    Join Date
    Aug 2012

    Re: OpenCL module for OpenCV

    Just registered to this board to thank you for this effort! Keep going!

Similar Threads

  1. OpenCV Libraries within .cl Files
    By Flipside in forum OpenCL
    Replies: 3
    Last Post: 10-03-2011, 09:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean