Access/Create/Modify pixels in UMat
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`
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 I just edited my post with an example code