コード例 #1
0
ファイル: cap_openni.cpp プロジェクト: AndreSteenveld/opencv
inline void getBGRImageFromMetaData( const xn::ImageMetaData& imageMetaData, cv::Mat& bgrImage )
{
    if( imageMetaData.PixelFormat() != XN_PIXEL_FORMAT_RGB24 )
        CV_Error( CV_StsUnsupportedFormat, "Unsupported format of grabbed image\n" );

    cv::Mat rgbImage( imageMetaData.YRes(), imageMetaData.XRes(), CV_8UC3 );
    const XnRGB24Pixel* pRgbImage = imageMetaData.RGB24Data();

    // CV_Assert( 3*sizeof(uchar) == sizeof(XnRGB24Pixel) );
    memcpy( rgbImage.data, pRgbImage, rgbImage.total()*sizeof(XnRGB24Pixel) );
    cv::cvtColor( rgbImage, bgrImage, CV_RGB2BGR );
}
コード例 #2
0
ファイル: Md2Parser.cpp プロジェクト: Gustavo6046/TrenchBroom
 Assets::Texture* Md2Parser::loadTexture(const Md2Skin& skin) {
     const Path skinPath(String(skin.name));
     MappedFile::Ptr file = m_fs.openFile(skinPath);
     
     Color avgColor;
     const ImageLoader image(ImageLoader::PCX, file->begin(), file->end());
     
     const Buffer<unsigned char>& indices = image.indices();
     Buffer<unsigned char> rgbImage(indices.size() * 3);
     m_palette.indexedToRgb(indices, indices.size(), rgbImage, avgColor);
     
     return new Assets::Texture(skin.name, image.width(), image.height(), avgColor, rgbImage);
 }
コード例 #3
0
void
ColorImageWriter<ImageType>::write(std::string filename) {

	LOG_DEBUG(colorimagewriterlog) << "requesting image update" << std::endl;

	updateInputs();

	if (!_r.isSet() || !_g.isSet() || !_b.isSet()) {

		LOG_ERROR(colorimagewriterlog) << "no input image set" << std::endl;
		return;
	}

	if (filename == "")
		filename = _filename;

	LOG_DEBUG(colorimagewriterlog) << "attempting to write image" << std::endl;

	if (_r->shape() != _g->shape() || _r->shape() != _b->shape()) {

		LOG_ERROR(colorimagewriterlog) << "images are not of same size" << std::endl;
		return;
	}

	vigra::MultiArray<2, vigra::RGBValue<float> > rgbImage(_r->shape());

	typename ImageType::iterator ri = _r->begin();
	typename ImageType::iterator gi = _g->begin();
	typename ImageType::iterator bi = _b->begin();
	vigra::MultiArray<2, vigra::RGBValue<float> >::iterator rgb = rgbImage.begin();

	while (rgb != rgbImage.end()) {

		rgb->red()   = *ri;
		rgb->green() = *gi;
		rgb->blue()  = *bi;

		ri++;
		gi++;
		bi++;
		rgb++;
	}

	// save to file
	vigra::exportImage(vigra::srcImageRange(rgbImage), vigra::ImageExportInfo(filename.c_str()));

	LOG_DEBUG(colorimagewriterlog) << "image written" << std::endl;
}
コード例 #4
0
	uchar* depth::convert2Color()
	{
		/// color image to be returned
		uchar* rgbImage(nullptr);

		const uchar farColor[] = { 255, 0, 0 }, nearColor[] = { 20, 40, 255 };
		const int N = 256 * 256;
		int histogram[N] = { 1 };

		/// histogram
		for (int row_i = 0; row_i < m_height; row_i++)
		{
			for (int col_i = 0; col_i < m_width; col_i++)
			{
				int index = static_cast<int>(m_uspDepthData[row_i * m_width + col_i]);
				histogram[index]++;
			}
		}

		/// integral arry
		for (int hist_i = 1; hist_i < N; hist_i++)
		{
			histogram[hist_i] += histogram[hist_i - 1];
		}

		/// remap the integral histogram to range [0...256];
		int sum = histogram[N - 1];
		for (int hist_i = 0; hist_i < N; hist_i++)
		{
			histogram[hist_i] = (histogram[hist_i] << 8) / sum;
		}

		/// init color image
		rgbImage = new uchar[m_height * m_width * 3];
		memset(rgbImage, 0, sizeof(rgbImage));

		/// generate color image by using the histogram to interpolate between two colors
		for (int row_i = 0; row_i < m_height; row_i++)
		{
			for (int col_i = 0; col_i < m_width; col_i++)
			{
				int curPos = row_i * m_width + col_i;

				ushort curDepthVal = m_uspDepthData[curPos];
				int curHist = histogram[curDepthVal];

				/// get the corresponding rgb postions in the two dimension color image
				uchar &curRVal(rgbImage[curPos * 3]), &curGVal(rgbImage[curPos * 3 + 1]), 
					&curBVal(rgbImage[curPos * 3 + 2]);
				if (curDepthVal > 0)
				{
					curRVal = ((std::numeric_limits<uchar>::max() - curHist) * nearColor[0] + curHist * farColor[0]) >> 8;
					curGVal = ((std::numeric_limits<uchar>::max() - curHist) * nearColor[1] + curHist * farColor[1]) >> 8;
					curBVal = ((std::numeric_limits<uchar>::max() - curHist) * nearColor[2] + curHist * farColor[2]) >> 8;
				}
				else
				{
					curRVal = static_cast<uchar>(0);
					curGVal = static_cast<uchar>(0);
					curBVal = static_cast<uchar>(0);
				}
			}
コード例 #5
0
void OpenGLMethods::paintImagePixelsToOpenGLList(const DebugImage& image, int colorModel, int zComponent, bool polygons, int listID, int x1, int x2, int y1, int y2)
{
  // Build a new list
  ::glNewList(listID, GL_COMPILE_AND_EXECUTE);

  if(polygons)
  {
    glPolygonMode(GL_FRONT, GL_FILL);
    glPolygonMode(GL_BACK, GL_FILL);
    glBegin(GL_QUADS);
  }
  else
    glBegin(GL_POINTS);

  TImage<PixelTypes::BGRAPixel> rgbImage(image.getImageWidth(), image.height);
  image.convertToBGRA(rgbImage[0]);

  ColorChannels* convertedImage;
  bool allocated = false;
  switch(colorModel)
  {
    case 0: //yuv
      if(image.type == PixelTypes::YUV)
      {
        convertedImage = const_cast<ColorChannels*>(image.getView<ColorChannels>()[0]);
      }
      else
      {
        convertedImage = new ColorChannels[rgbImage.width * rgbImage.height];
        allocated = true;
        PixelTypes::YUVPixel* dest = reinterpret_cast<PixelTypes::YUVPixel*>(convertedImage);
        switch(image.type)
        {
          case PixelTypes::BGRA:
            for(const PixelTypes::BGRAPixel* src = image.getView<PixelTypes::BGRAPixel>()[0], *srcEnd = image.getView<PixelTypes::BGRAPixel>()[image.height]; src < srcEnd; src++, dest++)
              ColorModelConversions::fromRGBToYUV(src->r, src->g, src->b, dest->y, dest->u, dest->v);
            break;
          case PixelTypes::RGB:
            for(const PixelTypes::RGBPixel* src = image.getView<PixelTypes::RGBPixel>()[0], *srcEnd = image.getView<PixelTypes::RGBPixel>()[image.height]; src < srcEnd; src++, dest++)
              ColorModelConversions::fromRGBToYUV(src->r, src->g, src->b, dest->y, dest->u, dest->v);
            break;
          case PixelTypes::YUYV:
            for(const PixelTypes::YUYVPixel* src = image.getView<PixelTypes::YUYVPixel>()[0], *srcEnd = image.getView<PixelTypes::YUYVPixel>()[image.height]; src < srcEnd; src++, dest++)
            {
              dest->y = src->y0;
              dest->u = src->u;
              dest->v = src->v;
              dest++;
              dest->y = src->y1;
              dest->u = src->u;
              dest->v = src->v;
            }
            break;
          case PixelTypes::Colored:
            for(const PixelTypes::BGRAPixel* src = rgbImage[0], *srcEnd = rgbImage[rgbImage.height]; src < srcEnd; src++, dest++)
              ColorModelConversions::fromRGBToYUV(src->r, src->g, src->b, dest->y, dest->u, dest->v);
            break;
          case PixelTypes::Grayscale:
            for(const PixelTypes::GrayscaledPixel* src = image.getView<PixelTypes::GrayscaledPixel>()[0], *srcEnd = image.getView<PixelTypes::GrayscaledPixel>()[image.height]; src < srcEnd; src++, dest++)
            {
              dest->y = *src;
              dest->u = dest->v = 128;
            }
            break;
          default:
            ASSERT(false);
        }
      }
      break;
    case 1: //rgb
      convertedImage = reinterpret_cast<ColorChannels*>(rgbImage[0]);
      break;
    case 2: //hsi
      convertedImage = new ColorChannels[rgbImage.width * rgbImage.height];
      allocated = true;
      PixelTypes::HSIPixel* dest = reinterpret_cast<PixelTypes::HSIPixel*>(convertedImage);
      for(const PixelTypes::BGRAPixel* src = rgbImage[0], *srcEnd = rgbImage[rgbImage.height]; src < srcEnd; src++, dest++)
        ColorModelConversions::fromRGBToHSI(src->r, src->g, src->b, dest->h, dest->s, dest->i);
      break;
  }

  float tmp = 2.0f / 255.0f;
  float x, y, xn, yn;
  float z00, z01, z10, z11;

  for(int j = y1; j < y2 - 2; j++)
  {
    for(int i = x1; i < x2 - 2; i++)
    {
      if(zComponent == -1)
      {
        unsigned char* channels = convertedImage[j * rgbImage.width + i].channels;
        if(colorModel == 0) //(padding is at 0 by yuv)
          channels++;
        x = -1.0f + channels[2] * tmp;
        y = -1.0f + channels[0] * tmp;
        z00 = -1.0f + channels[1] * tmp;
        glColor3ub(rgbImage[j][i].r, rgbImage[j][i].g, rgbImage[j][i].b);
        glVertex3d(x, y, z00);
      }
      else
      {
        x = (+i - rgbImage.width / 2.f) * tmp;
        y = (-j + rgbImage.height / 2.f) * tmp;
        xn = (+i + 1 - rgbImage.width / 2.f) * tmp;
        yn = (-j - 1 + rgbImage.height / 2.f) * tmp;
        z00 = (-0.5f + convertedImage[j * rgbImage.width + i].channels[zComponent] * tmp / 2);
        if(polygons)
        {
          z01 = -0.5f + convertedImage[(j + 1) * rgbImage.width + i].channels[zComponent] * tmp / 2;
          z10 = -0.5f + convertedImage[j * rgbImage.width + i + 1].channels[zComponent] * tmp / 2;
          z11 = -0.5f + convertedImage[(j + 1) * rgbImage.width + i + 1].channels[zComponent] * tmp / 2;
          glColor3ub(rgbImage[j][i].r, rgbImage[j][i].g, rgbImage[j][i].b);
          glVertex3d(x, y, z00);

          glColor3ub(rgbImage[j][i + 1].r, rgbImage[j][i + 1].g, rgbImage[j][i + 1].b);
          glVertex3d(xn, y, z10);

          glColor3ub(rgbImage[j + 1][i + 1].r, rgbImage[j + 1][i + 1].g, rgbImage[j + 1][i + 1].b);
          glVertex3d(xn, yn, z11);

          glColor3ub(rgbImage[j + 1][i].r, rgbImage[j + 1][i].g, rgbImage[j + 1][i].b);
          glVertex3d(x, yn, z01);
        }
        else
        {
          glColor3ub(rgbImage[j][i].r, rgbImage[j][i].g, rgbImage[j][i].b);
          glVertex3d(x, y, z00);
        }
      }
    }
  }

  if(allocated)
  {
    delete[] convertedImage;
  }

  glEnd();
  glPolygonMode(GL_FRONT, GL_LINE);
  glPolygonMode(GL_BACK, GL_LINE);
  ::glEndList();
}