|
@@ -12,38 +12,70 @@
|
|
|
using namespace std;
|
|
|
using namespace NICE;
|
|
|
using namespace OBJREC;
|
|
|
-RSMeanShift::RSMeanShift()
|
|
|
-{
|
|
|
- minimumRegionArea = 50;
|
|
|
- rangeBandwidth = 6.5;
|
|
|
-
|
|
|
- spatialBandwidth = 7;
|
|
|
|
|
|
- imageProc = new msImageProcessor();
|
|
|
- speedUpLevel = MED_SPEEDUP;
|
|
|
-}
|
|
|
-RSMeanShift::RSMeanShift ( const Config *conf )
|
|
|
+void RSMeanShift::setSpeedUpLevel( const string& _speedUpLevelString )
|
|
|
{
|
|
|
- imageProc = new msImageProcessor();
|
|
|
- minimumRegionArea = conf->gI ( "RSMeanShift", "MinimumRegionArea", 50 );
|
|
|
- rangeBandwidth = conf->gD ( "RSMeanShift", "RangeBandwidth", 6.5 );
|
|
|
- spatialBandwidth = conf->gI ( "RSMeanShift", "SpatialBandwidth", 7 );
|
|
|
- speedUpLvlStr = conf->gS ( "RSMeanShift", "SpeedUpLevel", "MEDIUM" );
|
|
|
- if ( speedUpLvlStr == "NONE" ) speedUpLevel = NO_SPEEDUP;
|
|
|
- else if ( speedUpLvlStr == "MEDIUM" ) speedUpLevel = MED_SPEEDUP;
|
|
|
- else if ( speedUpLvlStr == "HIGH" ) speedUpLevel = HIGH_SPEEDUP;
|
|
|
+ if ( speedUpLvlString == "NONE" )
|
|
|
+ this->speedUpLevel = NO_SPEEDUP;
|
|
|
+ else if ( speedUpLvlString == "MEDIUM" )
|
|
|
+ this->speedUpLevel = MED_SPEEDUP;
|
|
|
+ else if ( speedUpLvlString == "HIGH" )
|
|
|
+ this->speedUpLevel = HIGH_SPEEDUP;
|
|
|
else
|
|
|
{
|
|
|
- cerr << "[err] RSMeanShift::RSMeanShift: Wrong SpeedUpLevel-Value (" << speedUpLvlStr << ") only NONE, MEDIUM and HIGH allowed! Take default Value (MED_SPEEDUP)" << endl;
|
|
|
- speedUpLevel = MED_SPEEDUP;
|
|
|
+ std::cerr << "[err] RSMeanShift::RSMeanShift: Wrong SpeedUpLevel-Value (" << speedUpLvlString << ") only NONE, MEDIUM and HIGH allowed! Take default Value (MED_SPEEDUP)" << std::endl;
|
|
|
+ this->speedUpLevel = MED_SPEEDUP;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+///////////////////// ///////////////////// /////////////////////
|
|
|
+// CONSTRUCTORS / DESTRUCTORS
|
|
|
+///////////////////// ///////////////////// /////////////////////
|
|
|
+
|
|
|
+
|
|
|
+RSMeanShift::RSMeanShift() : RegionSegmentationMethod()
|
|
|
+{
|
|
|
+ this->minimumRegionArea = 50;
|
|
|
+ this->rangeBandwidth = 6.5;
|
|
|
+
|
|
|
+ this->spatialBandwidth = 7;
|
|
|
+
|
|
|
+ this->imageProc = new msImageProcessor();
|
|
|
+ this->speedUpLvlString = "MEDIUM";
|
|
|
+ this->setSpeedUpLevel( this->speedUpLvlString );
|
|
|
+}
|
|
|
+
|
|
|
+RSMeanShift::RSMeanShift ( const Config * _conf )
|
|
|
+{
|
|
|
+ this->initFromConfig( _conf );
|
|
|
+}
|
|
|
+
|
|
|
RSMeanShift::~RSMeanShift()
|
|
|
{
|
|
|
- delete imageProc;
|
|
|
+ if ( this->imageProc != NULL )
|
|
|
+ delete imageProc;
|
|
|
+ this->imageProc = NULL;
|
|
|
+}
|
|
|
+
|
|
|
+void RSMeanShift::initFromConfig( const NICE::Config* _conf, const std::string & _confSection )
|
|
|
+{
|
|
|
+ //first, call method for parent object
|
|
|
+ OBJREC::RegionSegmentationMethod::initFromConfig( _conf );
|
|
|
+
|
|
|
+ //now set own member variables
|
|
|
+ this->imageProc = new msImageProcessor();
|
|
|
+ this->minimumRegionArea = _conf->gI ( _confSection, "MinimumRegionArea", 50 );
|
|
|
+ this->rangeBandwidth = _conf->gD ( _confSection, "RangeBandwidth", 6.5 );
|
|
|
+ this->spatialBandwidth = _conf->gI ( _confSection, "SpatialBandwidth", 7 );
|
|
|
+ this->speedUpLvlString = _conf->gS ( _confSection, "SpeedUpLevel", "MEDIUM" );
|
|
|
+ this->setSpeedUpLevel( this->speedUpLvlString );
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+///////////////////// ///////////////////// /////////////////////
|
|
|
+// SEGMENTATION STUFF
|
|
|
+///////////////////// ///////////////////// //////////////////
|
|
|
+
|
|
|
int RSMeanShift::segRegions ( const NICE::Image & img, NICE::Matrix & mask ) const
|
|
|
{
|
|
|
ColorImage cimg ( img, img, img );
|
|
@@ -108,7 +140,7 @@ int RSMeanShift::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask
|
|
|
delete[] rawImageData;
|
|
|
rawImageData = 0;
|
|
|
|
|
|
- ColorImage ippTempImage ( width, height );
|
|
|
+ NICE::ColorImage ippTempImage ( width, height );
|
|
|
|
|
|
x = y = 0;
|
|
|
|
|
@@ -129,3 +161,131 @@ int RSMeanShift::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask
|
|
|
return transformSegmentedImg ( ColorImage ( resultRawImageData, width, height, GrayColorImageCommonImplementation::noAlignment ), mask );
|
|
|
#endif
|
|
|
}
|
|
|
+
|
|
|
+///////////////////// INTERFACE PERSISTENT /////////////////////
|
|
|
+// interface specific methods for store and restore
|
|
|
+///////////////////// INTERFACE PERSISTENT /////////////////////
|
|
|
+
|
|
|
+void RSMeanShift::restore ( std::istream & is, int format )
|
|
|
+{
|
|
|
+ //delete everything we knew so far...
|
|
|
+ this->clear();
|
|
|
+
|
|
|
+
|
|
|
+ if ( is.good() )
|
|
|
+ {
|
|
|
+
|
|
|
+ std::string tmp;
|
|
|
+ is >> tmp; //class name
|
|
|
+
|
|
|
+ if ( ! this->isStartTag( tmp, "RSMeanShift" ) )
|
|
|
+ {
|
|
|
+ std::cerr << " WARNING - attempt to restore RSMeanShift, but start flag " << tmp << " does not match! Aborting... " << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool b_endOfBlock ( false ) ;
|
|
|
+
|
|
|
+ while ( !b_endOfBlock )
|
|
|
+ {
|
|
|
+ is >> tmp; // start of block
|
|
|
+
|
|
|
+ if ( this->isEndTag( tmp, "RSMeanShift" ) )
|
|
|
+ {
|
|
|
+ b_endOfBlock = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ tmp = this->removeStartTag ( tmp );
|
|
|
+
|
|
|
+ if ( tmp.compare("minimumRegionArea") == 0 )
|
|
|
+ {
|
|
|
+ is >> minimumRegionArea;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("rangeBandwidth") == 0 )
|
|
|
+ {
|
|
|
+ is >> rangeBandwidth;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("spatialBandwidth") == 0 )
|
|
|
+ {
|
|
|
+ is >> spatialBandwidth;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("imageProc") == 0 )
|
|
|
+ {
|
|
|
+ //nothing to read actually :)
|
|
|
+ imageProc = new msImageProcessor();
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("speedUpLvlString") == 0 )
|
|
|
+ {
|
|
|
+ is >> speedUpLvlString;
|
|
|
+ this->setSpeedUpLevel( this->speedUpLvlString );
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "WARNING -- unexpected RSMeanShift object -- " << tmp << " -- for restoration... aborting" << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "RSMeanShift::restore -- InStream not initialized - restoring not possible!" << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void RSMeanShift::store ( std::ostream & os, int format ) const
|
|
|
+{
|
|
|
+ if (os.good())
|
|
|
+ {
|
|
|
+ // show starting point
|
|
|
+ os << this->createStartTag( "RSMeanShift" ) << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ os << this->createStartTag( "minimumRegionArea" ) << std::endl;
|
|
|
+ os << this->minimumRegionArea << std::endl;
|
|
|
+ os << this->createEndTag( "minimumRegionArea" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "rangeBandwidth" ) << std::endl;
|
|
|
+ os << this->rangeBandwidth << std::endl;
|
|
|
+ os << this->createEndTag( "rangeBandwidth" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "spatialBandwidth" ) << std::endl;
|
|
|
+ os << this->spatialBandwidth << std::endl;
|
|
|
+ os << this->createEndTag( "spatialBandwidth" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "imageProc" ) << std::endl;
|
|
|
+ //nothing to write actually :)
|
|
|
+ os << this->createEndTag( "imageProc" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "speedUpLvlString" ) << std::endl;
|
|
|
+ os << this->speedUpLvlString << std::endl;
|
|
|
+ os << this->createEndTag( "speedUpLvlString" ) << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // done
|
|
|
+ os << this->createEndTag( "RSMeanShift" ) << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void RSMeanShift::clear ()
|
|
|
+{
|
|
|
+ if ( this->imageProc != NULL )
|
|
|
+ delete imageProc;
|
|
|
+ this->imageProc = NULL;
|
|
|
+}
|