Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

this pretty much depends on the opencv verson you use:

for opencv2.4, you need aocl::oclMat , which has a constructor taking cv::Mat and an upload() member to get data from cpu to gpu, also a download() member and a cv::Mat operator to get it from gpu to cpu. then you can use that oclMat with functions from the ocl namespace

for opencv3, all you have to do is put you data into a cv::UMat . then you can use any opencv functionality with opencl acceleration.

upload is like this:

        cv::Mat m = ....
        cv::UMat um; m.copyTo(um);

or like this:

        UMat um(ROWS, COLS, CV_32F);
        Mat_<float> mc = um.getMat(ACCESS_WRITE);
        for (int j=0; j<COLS; j++)
        {
            mc(0,j) = theRNG().uniform(0.0f, 1.0f);
        }
        // now um is filled with random elements

download goes like this:

        Mat um = ...
        Mat m = um.getMat(ACCESS_READ);
        // note, that ACCESS_READ is far more expensive, than ACCESS_WRITE !

also have a look at ocl utility functions