OpenCL module for OpenCV

#1

Hi,
We’ve developed a OpenCL module for OpenCV and have submitted as a branch of opencv code base:
http://code.opencv.org/svn/opencv/branches/ocl
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

Hi,

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:


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 : )

Source:


#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("
OpenCL Test
");
        printf("
Usage: stereo_test <left_image> <right_image>
");
}

void checkErr(cl_int err, const char * name)
{
    if (err != CL_SUCCESS) {
        std::cerr << "ERROR: " << name << " (" << err << ")" << std::endl;
        exit(EXIT_FAILURE);
    }
}

int main(int argc, char** argv)
{
    const char* img1_filename = 0;
    const char* img2_filename = 0;

    if(argc < 3)
    {
        print_help();
        return 0;
    }
    else
    {
        img1_filename = argv[1];
        img2_filename = argv[2];
    }

    //-----------------------------------------------------------------
    //-----------------------------------------------------------------
    //-----------------------------------------------------------------

    //Device Zugriff
    printf("Begin creating ocl context...
");
    ClContext* context_ocl = ClContext::getContext();
    printf("End creating ocl context...
");

    //Bild links
    Mat left_orig;
    Mat left_gray;
    oclMat left_ocl;

    //Bild rechts
    Mat right_orig;
    Mat right_gray;
    oclMat right_ocl;

    //Disparität
    //Mat disp_orig;
    //oclMat disp_ocl;
    Size img_size;

    //Vorverarbeitung der Bilddaten
    printf("Begin image preprocessing...
");

    //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...
");

    //Kontextinformationen zuweisen
    printf("Begin applying context...
");
    left_ocl.clCxt = context_ocl;
    right_ocl.clCxt = context_ocl;
    disp_ocl.clCxt = context_ocl;
    printf("End applying context...
");

    printf("Begin init algorithm...
");

    //Algorithmus initialisieren
    StereoBM_GPU bm(StereoBM_GPU::BASIC_PRESET, StereoBM_GPU::DEFAULT_NDISP, StereoBM_GPU::DEFAULT_WINSZ);
    bm.preset = StereoBM_GPU::BASIC_PRESET;
    bm.ndisp = StereoBM_GPU::DEFAULT_NDISP;
    bm.winSize = StereoBM_GPU::DEFAULT_WINSZ;

    printf("End init algorithm...
");

    printf("Begin calculation...
");
    int64 t = getTickCount();
    bm(left_ocl, right_ocl, disp_ocl);
    t = getTickCount() - t;
    printf("End calculation...
Time elapsed: %fms
", t*1000/getTickFrequency());

    //Disparität umwandeln
    disp_orig = disp_ocl;

    //Fertig
    return 0;
}

More information about my system:

Board: Kontron KTA55/pITX ( http://us.kontron.com/products/boards+a … 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
Holger

#3

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 http://cat.middlebury.edu/stereo/newdata.html). 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

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://code.opencv.org/opencv.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

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