I am trying to allocate space for an opencv mat ptr on my Gpu. After allocating when i make some changes in the pixel data it is not reflecting in the final output after copying back onto a host matrix. Below is my code.
__global__ void test(Mat *m,int rows,int cols)//float *d_out,float *d_in)
{ int col = threadIdx.x;
int row = blockIdx.x;
m->data[row*3*cols+cols*3]=0;
m->data[row*3*cols+cols*3+1]=0;
m->data[row*3*cols+cols*3+2]=0;
//float f = d_in[idx];
//d_out[idx] = f*f*f;
}
int main( )
{
Mat m=imread("Ori/(19).jpg");
Mat *darr;
const size_t sz = sizeof(m);
cudaMalloc((void**)&darr, sz);
cudaMemcpy(darr, &m, sz, cudaMemcpyHostToDevice);
test<<<m.rows,m.cols>>>(darr,m.rows,m.cols);
Mat* x=new Mat(m);
cudaMemcpy(&x, darr, sz, cudaMemcpyDeviceToHost);
///the following line should give 0 as output
cout<<(int)x->data[0]<<endl;
cudaFree(darr);
return 0;
}
I intend to black out all the pixels on the image buffer on GPU and then copy it back. But the output shows that the original matrix remains unchanged.