Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::Mat::copyTo and cv::gpu::GpuMat::copyTo show different behaviour

The doc of Mat::copyTo (void Mat::copyTo(OutputArray m, InputArray mask) const) says:

When the operation mask is specified, and the Mat::create call shown above reallocated the matrix, the newly allocated matrix is initialized with all zeros before copying the data.

I called the method with an empty Mat and a mask for both CPU and GPU. The CPU variant initializes all values to zero, while the GPU variant apparently does not.

For clarity:

My Code CPU1:

// have defined and filled cv::Mat lo_input, lo_mask;<br>
cv::Mat lo_mat;<br>
lo_input.copyTo( lo_mat, lo_mask );<br>

--> works perfect lo_mat now contains the values of lo_input, where lo_mask is non-zero, and has value zero everywhere else

My Code GPU1:

// have defined and filled cv::gpu::GpuMat lo_input, lo_mask;<br>
cv::gpu::GpuMat lo_mat;<br>
lo_input.copyTo( lo_mat, lo_mask );<br>

--> does not cause seg fault and lo_mat has size and type, so apparently calls create on lo_mat but lo_mat contains random fragments of released matrices where the lo_mask is zero -> apparently lo_mat values are not initialized to zero

My Code GPU2:

// have defined and filled cv::gpu::GpuMat lo_input, lo_mask;<br>
cv::gpu::GpuMat lo_mat( lo_input.size(), lo_input.type() );<br>
lo_mat.setTo( cv::Scalar::all( 0 ) );<br>
lo_input.copyTo( lo_mat, lo_mask );<br>

--> works perfect like CPU1

Is this difference in the behaviours of cv::Mat::copyTo and cv::gpu::GpuMat::copyTo intended or a bug?

I am using ubuntu 12.04 64 bit with cuda 5.5 and OpenCV 2.4.7

cv::Mat::copyTo and cv::gpu::GpuMat::copyTo show different behaviour

The doc of Mat::copyTo (void Mat::copyTo(OutputArray m, InputArray mask) const) says:

When the operation mask is specified, and the Mat::create call shown above reallocated the matrix, the newly allocated matrix is initialized with all zeros before copying the data.

I called the method with an empty Mat and a mask for both CPU and GPU. The CPU variant initializes all values to zero, while the GPU variant apparently does not.

For clarity:

My Code CPU1:

// have defined and filled cv::Mat lo_input, lo_mask;<br>
lo_mask;
cv::Mat lo_mat;<br>
lo_mat;
lo_input.copyTo( lo_mat, lo_mask );<br>
);

--> works perfect lo_mat now contains the values of lo_input, where lo_mask is non-zero, and has value zero everywhere else

My Code GPU1:

// have defined and filled cv::gpu::GpuMat lo_input, lo_mask;<br>
lo_mask;
cv::gpu::GpuMat lo_mat;<br>
lo_mat;
lo_input.copyTo( lo_mat, lo_mask );<br>
);

--> does not cause seg fault and lo_mat has size and type, so apparently calls create on lo_mat but lo_mat contains random fragments of released matrices where the lo_mask is zero -> apparently lo_mat values are not initialized to zero

My Code GPU2:

// have defined and filled cv::gpu::GpuMat lo_input, lo_mask;<br>
lo_mask;
cv::gpu::GpuMat lo_mat( lo_input.size(), lo_input.type() );<br>
);
lo_mat.setTo( cv::Scalar::all( 0 ) );<br>
);
lo_input.copyTo( lo_mat, lo_mask );<br>
);

--> works perfect like CPU1

Is this difference in the behaviours of cv::Mat::copyTo and cv::gpu::GpuMat::copyTo intended or a bug?

I am using ubuntu 12.04 64 bit with cuda 5.5 and OpenCV 2.4.7