Ask Your Question
0

'm trying to implement an image processing algorithm using OpenCL,for that i I read one image using OpenCV. The problem is how transform the data into OpenCL

asked 2017-06-16 21:55:03 -0600

dab gravatar image

The code should read one image using OpenCV, then transform the data into OpenCL image, then i use a buffer to read data. Finally i copied it to the host again

can someone explain to me how opencv works with opencl

edit retag flag offensive close merge delete

Comments

opencv version ?

berak gravatar imageberak ( 2017-06-17 01:24:58 -0600 )edit

I d'ont know the version of OpenCV installed on my computer. I just installed 2.4.9, would you tell me how can i find out

dab gravatar imagedab ( 2017-06-18 07:34:18 -0600 )edit

that is 2.4, look here

also, cout << cv::getBuildInformation();

berak gravatar imageberak ( 2017-06-18 08:23:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-18 01:49:55 -0600

berak gravatar image

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

edit flag offensive delete link more

Comments

I have opencv2.4 version. Would you please explain a little bit more how it works with opencl

dab gravatar imagedab ( 2017-06-28 22:19:05 -0600 )edit

sorry, cannot help much with 2.4 (not using that)

berak gravatar imageberak ( 2017-06-29 00:50:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-16 21:55:03 -0600

Seen: 349 times

Last updated: Jun 18 '17