# How to use cv::cudev::GpuMat\_ correctly?

**URL:** <https://forum.opencv.org/t/how-to-use-cv-gpumat-correctly/3522>\
**Category:** C++\
**Tags:** cuda\
**Created:** [May 25, 2021, 1:35pm UTC](https://forum.opencv.org/t/how-to-use-cv-gpumat-correctly/3522 "2021-05-25T13:35:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kansai](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@Kansai](https://forum.opencv.org/u/Kansai)\
**Post date:** [May 25, 2021, 1:35pm UTC](https://forum.opencv.org/t/how-to-use-cv-gpumat-correctly/3522/1 "2021-05-25T13:35:33Z")

</div>

I have found a problem when using `cv::cuda::GpuMat` since I am uploading originally an image of type `Mat1b` (which is `Mat_<uchar>` )

Since apparently a Mat1b does not exist for CUDA versions, I am trying to use what I suppose is the equivalent: [the cv::cudev::GpuMat\_](https://docs.opencv.org/master/d3/d1c/classcv_1_1cudev_1_1GpuMat__.html) template

However when doing

`cv::cudev::GpuMat_<uchar> GPUother_image;`

I got the following error

```auto
error: aggregate ‘cv::cudev::GpuMat_<unsigned char> GPUother_image’ has incomplete type and cannot be defined
     cv::cudev::GpuMat_<uchar> GPUother_image;

```

How can I solve this problem and use `GpuMat_` correctly?

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [May 25, 2021, 3:14pm UTC](https://forum.opencv.org/t/how-to-use-cv-gpumat-correctly/3522/2 "2021-05-25T15:14:16Z")

</div>

I have never used the thin wrappers before but it seems that both:

> cv::cudev::GpuMat\_\<uchar\> gpuMat1b(mat1b);

and

> cv::cudev::GpuMat\_\<uchar\> gpuMat1b;  
> gpuMat1b.upload(mat1b);

with

> Mat1b mat1b(3, 3);

are working for me. Maybe you are missing the header

> #include \<opencv2/cudev/ptr2d/gpumat.hpp\>

Just out of interest why do you want to use cv::cudev::GpuMat\_ instead of GpuMat?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 25, 2021, 6:06pm UTC](https://forum.opencv.org/t/how-to-use-cv-gpumat-correctly/3522/3 "2021-05-25T18:06:50Z")

</div>

cross-post and solution:

> <https://stackoverflow.com/questions/67688991/trying-to-use-cvcudevgpumat-without-errors>

---

<div class="post-metadata">

**Author:** ![Kansai](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@Kansai](https://forum.opencv.org/u/Kansai)\
**Post date:** [May 26, 2021, 12:58am UTC](https://forum.opencv.org/t/how-to-use-cv-gpumat-correctly/3522/4 "2021-05-26T00:58:56Z")

</div>

there is a `GpuMat_`? I didn’t know that.  
And is `cv::cudev::GpuMat_ gpuMat1b(mat1b);` similar to `gpuMat1b.upload(mat1b)`??

as for the reason, in my group project, the requirements are to use Mat1b or equivalent

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [May 26, 2021, 9:31am UTC](https://forum.opencv.org/t/how-to-use-cv-gpumat-correctly/3522/5 "2021-05-26T09:31:25Z")

</div>

> [@Kansai](#):
>
> there is a `GpuMat_` ? I didn’t know that.

No sorry there is not, the markup “\<\>” killed \<uchar\>. I have corrected my previous post.

> [@Kansai](#):
>
> And is `cv::cudev::GpuMat_ gpuMat1b(mat1b);` similar to `gpuMat1b.upload(mat1b)` ??

Yes they are equivalent. Furthermore if you are simply using `Mat1b` because you have to you might as well use standard `GpuMat`, which can be created from a `Mat1b`.

> cv::cudaGpuMat gpuMat(mat1b);
