frameDecoded writePixel yuv420 wrong colors

Hello, we are using WCS to transfer frame data to OpenCV, process it there and then return the resulting frame to WCS in order to change pixels colours. The pixels we return are in either BGR or RGB pixel sequence. The generic formula we use is this:

byte by = (byte) (r * .299000 + g * .587000 + b * .114000);
byte bu = (byte) (r * -.168736 + g * -.331264 + b * .500000 + 128);
byte bv = (byte) (r * .500000 + g * -.418688 + b * -.081312 + 128);
frame.writePixel(x, y, new byte[] { by, bu, bv });

This formula works fine for solid colours (e.g. RGB(126, 126, 126)) but generally fails with regular frames coming from a stream. We wonder, if that's the problem of the formula or the way WCS treats some pixel numbers.

Attached is the original image being streamed and also what we get as the result of a BGR pixel sequence when used with the writePixel method.

Thanks,
P
 

Attachments

Max

Administrator
Staff member
Good day.
We raised the ticket WCS-4038 to implement an YUV->RGB->YUV example, will let you know about progress here.
 

Max

Administrator
Staff member
Please clarify what YUV420 format do you use? WCS uses IYUV format:
Code:
[Y1 ... Yn, U1 ... Un, V1 ... Vn]
If you use some other form, it may work on solid colors, but probably will now work on real images
 
Thanks for an update. When it comes to transforming a YUV420 frame in WCS to RGB format in OpenCV we use cvtColor(*mat, *mat, COLOR_YUV2RGB_I420); and this conversion works as expected. Problems arise when we try to convert an OpenCV RGB frame in WCS from RGB to YUV420 using writePixel.
 

Max

Administrator
Staff member
Good day.
Since WCS build 5.2.1914 we added the method Frame.rewriteData() to update frame data not by pixel, but as a solid byte array. This allows to use OpenCV RBG to YUV I420 convertion function and render its result properly. Please see the detailed example here: Decoded frames interception and hangling with OpenCV (and OpenCV building too, for customers who do not use it yet)
 
Top