# Channel number from zed2

**URL:** <https://community.stereolabs.com/t/channel-number-from-zed2/8350>\
**Category:** C++\
**Tags:** zed-sdk\
**Created:** [March 17, 2025, 12:08pm UTC](https://community.stereolabs.com/t/channel-number-from-zed2/8350 "2025-03-17T12:08:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pelayo](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/p/6bbea6/32.png) [@Pelayo](https://community.stereolabs.com/u/Pelayo)\
**Post date:** [March 17, 2025, 12:08pm UTC](https://community.stereolabs.com/t/channel-number-from-zed2/8350/1 "2025-03-17T12:08:19Z")

</div>

I am using the function

`cv::Mat image_ocv = slMat2cvMat(image_zed);`

with the goal of using the image in OpenCV, but if I try to acquire 3 channels instead of 4, the resulting image is not displayed correctly.

`Mat image_zed(new_width, new_height, MAT_TYPE::U8_C3);`  
`Mat image_zed(new_width, new_height, MAT_TYPE::U8_C4);`

Is it possible that the ZED 2 camera always returns a 4-channel matrix even if I only want a 3-channel one?

---

<div class="post-metadata">

**Author:** ![hbeaumont](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/h/67e7ee/32.png) [@hbeaumont](https://community.stereolabs.com/u/hbeaumont)\
**Post date:** [March 18, 2025, 2:31pm UTC](https://community.stereolabs.com/t/channel-number-from-zed2/8350/2 "2025-03-18T14:31:44Z")

</div>

Hello @Pelayo, welcome on [StereoLabs](https://www.stereolabs.com/) forum !  
If I understand well your issue, you are trying to retrieve a 3-channel image, but when you retrieve an image it is always a 4-channel one, so you cannot use it to get a 3-channel cv::Mat.  
If this is right, I can answer on two points:

- When you use the function retrieveImage(…) on your camera object (here is the doc: [Camera Class Reference | API Reference | Stereolabs](https://www.stereolabs.com/docs/api/classsl_1_1Camera.html#a01dce4f0af6f8959a9c974ffaca656b5)) , you can give an enum parameter named “VIEW” (doc of this parameter: [Video Module | API Reference | Stereolabs](https://www.stereolabs.com/docs/api/group __Video__ group.html#ga77fc7bfc159040a1e2ffb074a8ad248c)). This parameter supports only 1-channel and 4-channel recording.
- What I can suggest you is to use this fix which should resolve your issue:

```auto
    sl::Mat sl_mat_img;
    zed.grab();
    zed.retrieveImage(sl_mat_img, sl::VIEW::LEFT); // let's take the "sl::VIEW::LEFT" (4 channels)
    cv::Mat image_cv = slMat2cvMat(sl_mat_img);

    cv::Mat img_CV_8UC3_BGR;
    cv::cvtColor(image_cv, img_CV_8UC3_BGR, cv::COLOR_BGRA2BGR);

    std::cout << "image_cv: data type=" << image_cv.type() << std::endl; // Should print 24 (=CV_8UC4)
    std::cout << "img_CV_8UC3_BGR: data type=" << img_CV_8UC3_BGR.type() << std::endl; // Should print 16 (=CV_8UC3)

```

I hope it will help you, let us know if it does not.  
Best regards,
