Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert GpuMat to CvMat in OpenCV?

Tags:

opencv

gpu

I know how to do the opposite i.e. get GpuMat from CvMat using upload, but I need a CvMat from GpuMat, is there any method that can be used for this?

like image 533
Sameer Bagga Avatar asked Aug 06 '11 07:08

Sameer Bagga


People also ask

Does OpenCV use GPU by default?

By default, each of the OpenCV CUDA algorithms uses a single GPU. If you need to utilize multiple GPUs, you have to manually distribute the work between GPUs.

What is a CV :: mat?

In OpenCV the main matrix class is called Mat and is contained in the OpenCV-namespace cv. This matrix is not templated but nevertheless can contain different data types. These are indicated by a certain type-number. Additionally, OpenCV provides a templated class called Mat_, which is derived from Mat.

What is use of mat class in OpenCV?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.

What is CV_64F?

CV_64F is the same as CV_64FC1 . So if you need just 2D matrix (i.e. single channeled) you can just use CV_64F. EDIT. More generally, type name of a Mat object consists of several parts.


2 Answers

explicit conversion: Mat -> GPUMat

Mat myMat;
GpuMat myGpuMat;
myGpuMat.upload(myMat); //Via a member function
//Or
GpuMat myGpuMat(myMat) //Via a constructor
//Use myGpuMat here...

implicit conversion: GpuMat -> Mat

GpuMat myGpuMat;
Mat myMat = myGpyMat;
//Use myMat here...

Hope it helped, Julien,

like image 101
jmartel Avatar answered Oct 18 '22 18:10

jmartel


In win 7 , 64 bit, openCV 2.4

GpuMat --> Mat:

cv::gpu::GpuMat dst;
cv::Mat tran(dst);

As you can see dst is GpuMat, and tran is Mat.

like image 36
eyaler Avatar answered Oct 18 '22 17:10

eyaler