Richard Knop
Richard Knop

Reputation: 83705

Convert YUV to lossy compression with OpenCV

How would I go about converting an image in YUV colorspace to a JPEG image?

I have a raw image data saved in a char* variable:

char* frame = (char*)camera->getFrame(); // YUV colorspace image data

I need to convert this to a JPEG image data instead. I don't want to save it to disk because I will be sending it in a stream.

Upvotes: 0

Views: 2736

Answers (2)

Neon22
Neon22

Reputation: 640

Check the opencv src for the file cvcolor.cpp. This has all the color conversions in it.

I suggest you modify the existing routines near this line:

/* BGR/RGB -> YCrCb */

They are almost exactly what you need for YUV encoding. if its 4:4:4 and not 4:2:2 or 4:1:1

for jpg compression

  • The jpg encoder and decoder are in grfmt_jpeg.cpp which happens to #include "jpeglib.h"

  • You can call these directly

Upvotes: 1

ypnos
ypnos

Reputation: 52357

OpenCV itself does not export this functionality. Cleanest is to use libjpeg for encoding. See the answers to these questions:

Upvotes: 1

Related Questions