Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read UMat from a file in opencv 3.0 Beta?

Tags:

c++

opencv

opencl

I want to use UMat so my code can be run on both GPU and CPU using OpenCL (OpenCV 3.0.0 Beta).

but I can not find a way to read an image file into a UMat or convert a Mat to UMat.

How can I read an image into a UMat?

like image 907
mans Avatar asked Dec 12 '14 14:12

mans


2 Answers

Sample for Mat to UMat conversion is below. Coudlnt' find documentation for this. So only option was to read the source.

UMat img = imread( "lena.jpg", IMREAD_COLOR  ).getUMat( ACCESS_READ );

Different access flags as in source are

ACCESS_READ, ACCESS_WRITE, ACCESS_RW, ACCESS_FAST

For undestanding UMat usage, a complete sample for face detection is available here. Also note that documentation still refers to older flags as imread second parameter. You might need to use newer flags as in your OpenCV header file.

like image 188
kiranpradeep Avatar answered Oct 02 '22 07:10

kiranpradeep


What works for me is...

cv::UMat image;
cv::imread("image.jpeg", 1).copyTo(image);

This is using the latest opencv 3.2

like image 36
JoeManiaci Avatar answered Oct 02 '22 06:10

JoeManiaci