# Converting NV12 to BGR

**URL:** <https://forum.opencv.org/t/converting-nv12-to-bgr/16994>\
**Category:** C++\
**Created:** [March 27, 2024, 4:30am UTC](https://forum.opencv.org/t/converting-nv12-to-bgr/16994 "2024-03-27T04:30:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tsardoz](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@Tsardoz](https://forum.opencv.org/u/Tsardoz)\
**Post date:** [March 27, 2024, 4:30am UTC](https://forum.opencv.org/t/converting-nv12-to-bgr/16994/1 "2024-03-27T04:30:13Z")

</div>

I am trying to convert NV12 from a camera to BGR24. I have tried using opencv’s conversion functions but when I do that I just get a lovely solid pink image. I know the NV12 is fine as I save it to /tmp, scp it and use ffplay to view the raw data and the image is fine. But using this code and doing the same with BGR gives me solid pink, as does saving as jpeg. I need BGR for opencv’s image processing.

EDIT: I should add this is on a MIPS32EL SOC with opencv4 built by BUILDROOT

```auto
        cv::Mat picNV12 = cv::Mat(height * 3/2, width, CV_8UC1, frame->virAddr);
        cv::Mat picBGR;
        cv::cvtColor(picNV12, picBGR, cv::COLOR_YUV2BGR_NV12);

```

I guess I could save the NV12 as png and read it back but that is a waste of time.

---

<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:** [March 27, 2024, 7:30am UTC](https://forum.opencv.org/t/converting-nv12-to-bgr/16994/2 "2024-03-27T07:30:47Z")

</div>

plain cvtColor might not be able to handle _planar_ formats. browse the docs. there’s a sibling function specifically for planar stuff.
