How to create thrust device_vector from opencv gpumat and vice-versa
I need to convert a opencv::gpumat to a thrust::device_vector, then perform a thrust::copy_if , then copy the resultant thrust::device_vector to a cv::gpumat again.
How to convert from cv::gpumat to thrust::device_vector & vice-versa? I am omitting the thrust::copy_if statements for clarity in my code below.
My code(below) gives compilation error: error: expected a type specifier
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
nvcc: Cuda compilation tools, release 8.0, V8.0.44
Thrust v1.8
ubuntu 16.04
My code:
#include <thrust/random.h>
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
#include <opencv2/core/cuda.hpp>
int main(void)
{
cv::Mat input_host(1,100,CV_32F);
cv::Mat output_host(1,100,CV_32F);
cv::randu(input_host, cv::Scalar(-10), cv::Scalar(10));
cv::cuda::GpuMat input_device(1, 100, CV_32F);
input_device.upload(input_host);
thrust::device_ptr<CV_32F> input_ptr(input_device.ptr());
thrust::device_vector<CV_32F> input_device_vector (input_ptr,100);
return 0;
}
I need to copy the non zero elements of a gpumat to a new gpumat with corresponding indices. I intend to use thrust iterators for the same.
I tried to use the gpuMat-thrust-interop sample code from opencv. But it gave several(46) compilation errors as pointed out in my other post compilation error with opencv gpu-thrust-interop sample code