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

  • Screenshot 2024-02-02 104311.png
    Screenshot 2024-02-02 104311.png
    408.9 KB · Views: 448
  • Screenshot 2024-02-02 104335_.png
    Screenshot 2024-02-02 104335_.png
    958.6 KB · Views: 455
Good day.
We raised the ticket WCS-4038 to implement an YUV->RGB->YUV example, will let you know about progress here.
 
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.
 
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)
 
Many thanks, it worked. Now the colours drawn on the output match the input.
 

Attachments

  • Screenshot 2024-03-17 103358.png
    Screenshot 2024-03-17 103358.png
    485.1 KB · Views: 422
  • Screenshot 2024-03-17 103420.png
    Screenshot 2024-03-17 103420.png
    674.4 KB · Views: 406
  • Like
Reactions: Max
Top