我有位图和JPEG图像。我将不得不通过获得所有像素的RGB值从图像中检索像素。请提出一种从图像文件中检索RGB值的方法。如果C中有任何可用的功能,我将不胜感激。

最佳答案

您可以使用libJPEG解析并从JPEG获取位图-这非常简单

假设在“ rgb”中有RGB bimap。结果将被放置在“ yuv420p”向量中。

void rgb2yuv420p(std::vector<BYTE>& rgb, std::vector<BYTE>& yuv420p)
{
  unsigned int i = 0;
  unsigned int numpixels = width * height;
  unsigned int ui = numpixels;
  unsigned int vi = numpixels + numpixels / 4;
  unsigned int s = 0;

#define sR (BYTE)(rgb[s+2])
#define sG (BYTE)(rgb[s+1])
#define sB (BYTE)(rgb[s+0])

  yuv420p.resize(numpixels * 3 / 2);

  for (int j = 0; j < height; j++)
    for (int k = 0; k < width; k++)
    {
      yuv420p[i] = (BYTE)( (66*sR + 129*sG + 25*sB + 128) >> 8) + 16;

      if (0 == j%2 && 0 == k%2)
      {
        yuv420p[ui++] = (BYTE)( (-38*sR - 74*sG + 112*sB + 128) >> 8) + 128;
        yuv420p[vi++] = (BYTE)( (112*sR - 94*sG - 18*sB + 128) >> 8) + 128;
      }
      i++;
      s += colors;
    }
}

关于c - 使用C编程将RGB图像转换为YUV,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14018666/

10-11 22:35
查看更多