Revision: 8556
http://playerstage.svn.sourceforge.net/playerstage/?rev=8556&view=rev
Author: hsujohnhsu
Date: 2010-02-17 23:39:55 +0000 (Wed, 17 Feb 2010)
Log Message:
-----------
add bayer camera support
Modified Paths:
--------------
code/gazebo/trunk/server/rendering/OgreCamera.cc
code/gazebo/trunk/server/rendering/OgreCamera.hh
Modified: code/gazebo/trunk/server/rendering/OgreCamera.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreCamera.cc 2010-02-17 22:13:05 UTC
(rev 8555)
+++ code/gazebo/trunk/server/rendering/OgreCamera.cc 2010-02-17 23:39:55 UTC
(rev 8556)
@@ -58,6 +58,7 @@
this->saveFrameBuffer = NULL;
this->saveCount = 0;
+ this->bayerFrameBuffer = NULL;
this->myCount = cameraCounter++;
@@ -98,6 +99,9 @@
if (this->saveFrameBuffer)
delete [] this->saveFrameBuffer;
+ if (this->bayerFrameBuffer)
+ delete [] this->bayerFrameBuffer;
+
delete this->nearClipP;
delete this->farClipP;
delete this->saveFramesP;
@@ -142,9 +146,18 @@
this->imageFormat = Ogre::PF_R8G8B8;
else if (this->imageFormatP->GetValue() == "B8G8R8")
this->imageFormat = Ogre::PF_B8G8R8;
+ else if ( (this->imageFormatP->GetValue() == "BAYER_RGGB8") ||
+ (this->imageFormatP->GetValue() == "BAYER_BGGR8") ||
+ (this->imageFormatP->GetValue() == "BAYER_GBRG8") ||
+ (this->imageFormatP->GetValue() == "BAYER_GRBG8") )
+ {
+ // let ogre generate rgb8 images for all bayer format requests
+ // then post process to produce actual bayer images
+ this->imageFormat = Ogre::PF_R8G8B8;
+ }
else
{
- std::cerr << "Error parsing image format, using default
Ogre::PF_R8G8B8\n";
+ std::cerr << "Error parsing image format (" <<
this->imageFormatP->GetValue() << "), using default Ogre::PF_R8G8B8\n";
this->imageFormat = Ogre::PF_R8G8B8;
}
}
@@ -417,9 +430,14 @@
return 3;
else if (this->imageFormatP->GetValue() == "B8G8R8")
return 3;
+ else if ( (this->imageFormatP->GetValue() == "BAYER_RGGB8") ||
+ (this->imageFormatP->GetValue() == "BAYER_BGGR8") ||
+ (this->imageFormatP->GetValue() == "BAYER_GBRG8") ||
+ (this->imageFormatP->GetValue() == "BAYER_GRBG8") )
+ return 1;
else
{
- std::cerr << "Error parsing image format, using default Ogre::PF_R8G8B8\n";
+ std::cerr << "Error parsing image format (" <<
this->imageFormatP->GetValue() << "), using default Ogre::PF_R8G8B8\n";
return 3;
}
}
@@ -600,7 +618,22 @@
if (i!=0)
gzerr(0) << "Camera index must be zero for mono cam";
- return this->saveFrameBuffer;
+ int width = this->imageSizeP->GetValue().x;
+ int height = this->imageSizeP->GetValue().y;
+
+ // do last minute conversion if Bayer pattern is requested, go from R8G8B8
+ if ( (this->imageFormatP->GetValue() == "BAYER_RGGB8") ||
+ (this->imageFormatP->GetValue() == "BAYER_BGGR8") ||
+ (this->imageFormatP->GetValue() == "BAYER_GBRG8") ||
+ (this->imageFormatP->GetValue() == "BAYER_GRBG8") )
+ {
+ if (!this->bayerFrameBuffer)
+ this->bayerFrameBuffer = new unsigned char[width*height];
+
this->ConvertRGBToBAYER(this->bayerFrameBuffer,this->saveFrameBuffer,this->imageFormatP->GetValue(),width,height);
+ return this->bayerFrameBuffer;
+ }
+ else
+ return this->saveFrameBuffer;
}
//////////////////////////////////////////////////////////////////////////////
@@ -721,3 +754,107 @@
}
}
}
+
+////////////////////////////////////////////////////////////////////////////////
+/// post process, convert from rgb to bayer
+void OgreCamera::ConvertRGBToBAYER(unsigned char* dst, unsigned char* src,
std::string format,int width, int height)
+{
+ // do last minute conversion if Bayer pattern is requested, go from R8G8B8
+ if (format == "BAYER_RGGB8")
+ {
+ for (int i=0;i<width;i++)
+ {
+ for (int j=0;j<height;j++)
+ {
+ //
+ // RG
+ // GB
+ //
+ // determine position
+ if (j%2) // even column
+ if (i%2) // even row, red
+ dst[i+j*width] = src[i*3+j*width*3+0];
+ else // odd row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ else // odd column
+ if (i%2) // even row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ else // odd row, blue
+ dst[i+j*width] = src[i*3+j*width*3+2];
+ }
+ }
+ }
+ else if (format == "BAYER_BGGR8")
+ {
+ for (int i=0;i<width;i++)
+ {
+ for (int j=0;j<height;j++)
+ {
+ //
+ // BG
+ // GR
+ //
+ // determine position
+ if (j%2) // even column
+ if (i%2) // even row, blue
+ dst[i+j*width] = src[i*3+j*width*3+2];
+ else // odd row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ else // odd column
+ if (i%2) // even row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ else // odd row, red
+ dst[i+j*width] = src[i*3+j*width*3+0];
+ }
+ }
+ }
+ else if (format == "BAYER_GBRG8")
+ {
+ for (int i=0;i<width;i++)
+ {
+ for (int j=0;j<height;j++)
+ {
+ //
+ // GB
+ // RG
+ //
+ // determine position
+ if (j%2) // even column
+ if (i%2) // even row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ else // odd row, blue
+ dst[i+j*width] = src[i*3+j*width*3+2];
+ else // odd column
+ if (i%2) // even row, red
+ dst[i+j*width] = src[i*3+j*width*3+0];
+ else // odd row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ }
+ }
+ }
+ else if (format == "BAYER_GRBG8")
+ {
+ for (int i=0;i<width;i++)
+ {
+ for (int j=0;j<height;j++)
+ {
+ //
+ // GR
+ // BG
+ //
+ // determine position
+ if (j%2) // even column
+ if (i%2) // even row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ else // odd row, red
+ dst[i+j*width] = src[i*3+j*width*3+0];
+ else // odd column
+ if (i%2) // even row, blue
+ dst[i+j*width] = src[i*3+j*width*3+2];
+ else // odd row, green
+ dst[i+j*width] = src[i*3+j*width*3+1];
+ }
+ }
+ }
+
+}
Modified: code/gazebo/trunk/server/rendering/OgreCamera.hh
===================================================================
--- code/gazebo/trunk/server/rendering/OgreCamera.hh 2010-02-17 22:13:05 UTC
(rev 8555)
+++ code/gazebo/trunk/server/rendering/OgreCamera.hh 2010-02-17 23:39:55 UTC
(rev 8556)
@@ -218,6 +218,9 @@
/// \brief Set whether to view the world in wireframe
public: void ShowWireframe(bool s);
+ /// \brief if user requests bayer image, post process rgb from ogre to
generate bayer formats
+ private: void ConvertRGBToBAYER(unsigned char* dst, unsigned char* src,
std::string format,int width, int height);
+
// Save the camera frame
protected: virtual void SaveFrame();
@@ -237,6 +240,7 @@
// Info for saving images
protected: unsigned char *saveFrameBuffer;
+ protected: unsigned char *bayerFrameBuffer;
protected: unsigned int saveCount;
protected: ParamT<bool> *saveFramesP;
protected: ParamT<std::string> *savePathnameP;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit