Access/Create/Modify pixels in UMat

asked 2018-03-01 08:11:48 -0600

ROSpioneer gravatar image

updated 2018-03-01 08:29:19 -0600

I want to create a vector of type cv::UMat but I didn't find any method to do that.

What I do in normal cv::Mat in the CPU is pretty straight forward:

lut.at<float>(i,1) = cv::saturate_cast<uchar>(pow((float)(i / 255.0), fGamma) * 255.0f);

How can I do that without having to move elements from CPU to GPU?

EDIT:

Example:

Here is a code example you can compile of why I want to create a vector of type UMat:

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core/utility.hpp>

#include <iostream>
#include <chrono>

void GammaCorrection(cv::UMat&, double, cv::UMat&);
int main(int argc, char* argv[])
{

  cv::UMat src_temp = cv::imread(argv[1]).getUMat(cv::ACCESS_READ);
  GammaCorrection(src_temp, 0.08, src_temp);

}


void GammaCorrection(cv::Mat& src, double fGamma, cv::Mat& dst)
{         
   //On CPU I would do
     unsigned char lut[256];
      for (size_t i=0; i<256; i++)
             lut[i] = cv::saturate_cast<uchar>(pow((float)(i / 255.0), fGamma) * 255.0f);

   //On GPU:?
   cv::UMat lut = cv::UMat::zeros(256, 1, CV_8UC1);
   for (size_t i=0; i<256; i++)
      ///

//Do something with lut
}

Compile using gcc

g++ -std=c++1z -Wall -Weffc++ -O3 test.cpp -o test -fopenmp `pkg-config --cflags --libs opencv`
edit retag flag offensive close merge delete

Comments

you can't, you can only access pixels on the cpu

"I want to create a vector of type cv::UMat" -- can you give us a bit more context ?

berak gravatar imageberak ( 2018-03-01 08:21:48 -0600 )edit
1

@berak I just edited my post with an example code

ROSpioneer gravatar imageROSpioneer ( 2018-03-01 08:30:36 -0600 )edit