I have an OpenCV mat of type CV_8UC3 with BGR data in it. I’m trying to convert it to the right format to save a jpg with NvJPEGEncoder.
I’m following the basics from this post: NvJPEGEncoder - Converting from OpenCV Mat
- Convert to YUV with
cvtColor(bayerMat, YUVmat, cv::COLOR_BGR2YUV_I420);
- Copy into an NvBuffer of type
NvBuffer nvbuf(V4L2_PIX_FMT_YUV420M, image_width, image_height, 0);
- Then save with the jpeg encoder
std::unique_ptr jpgEnc(NvJPEGEncoder::createJPEGEncoder(“jpenenc”));
jpgEnc->encodeFromBuffer(nvbuf, JCS_YCbCr, &out_buf_ptr, out_buf_size, jpgQuality);
however this produces a jpg with limited range (blacks and saturation missing). Using OpenCV imwrite on the BRG mat does not have this issue.
NvJPEGEncoder produced image histogram:
OpenCV imwrite produced image histogram:
Edit: it appears I can only embed one image in a post
Is there a different OpenCV conversion code I need to be using to get the full range?
The closest discussion I can find to my issue is this thread: cvtColor for BGR to YUV 4:2:0 returns darker image · Issue #13066 · opencv/opencv · GitHub which seems to indicate that the OpenCV YUV420 conversion is what’s limiting the range.
Any thoughts on a work around for this?