Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert RGB to YCbCr - C code
    primarykey
    data
    text
    <p>I need to convert RGB to YCbCr for my final project and I trying to do this way (I'm programming in C):</p> <pre><code>/* Autor: Vinicius Garcia * Data : 09.ago.2011 * * Função que converte um pixel RGB em YCbCr * * param : int R valor do pixel no canal red * param : int G valor do pixel no canal green * param : int B valor do pixel no canal blue * return: int* vetor de inteiros com os valores H, S e V calculados - nesta ordem */ int* converter_RGB_para_YCbCr(int R, int G, int B){ int* YCbCr = (int*) malloc(3 * sizeof(int)); double delta = 128.0; //Constante necessaria para o calculo da conversão de cor double Y = (0.299 * R + 0.587 * G + 0.114 * B); double Cb = ((B - Y) * 0.564 + delta); double Cr = ((R - Y) * 0.713 + delta); YCbCr[0] = (int) Y; YCbCr[1] = (int) Cb; YCbCr[2] = (int) Cr; return YCbCr; } </code></pre> <p>But it doesn't work for me!</p> <p>I was comparing with cvCvtColor (from OpenCv library) and the results doesn't match:</p> <pre><code> R = 88, G = 76, B = 78 cvCvtColor: Y = 80, Cb = 127, Cr = 134 myfunction: Y = 382, Cb = 132, Cr = 132 (cr and cr are always equal!) </code></pre> <p>I really need help with this, I trying do this for a long time and I couldn't find any answer for my doubt.</p> <hr> <p>Do you guys think I'm getting the RGB values wrong? I'm doing this way:</p> <pre><code>uchar B = CV_IMAGE_ELEM(img_RGB, uchar, linha, coluna * 3); uchar G = CV_IMAGE_ELEM(img_RGB, uchar, linha, coluna * 3 + 1); uchar R = CV_IMAGE_ELEM(img_RGB, uchar, linha, coluna * 3 + 2); </code></pre> <p>Then I'm calling my conversion function this way:</p> <pre><code>converter_RGB_para_YCbCr(R, G, B); </code></pre> <p>My function expects int R, int G, int B but I'm passing uchar B, uchar G, uchar R. its that ok?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload