Beispiel #1
0
void Camera::init(const mo3d::NVM_Camera* cam, int width, int height, const int maxLevel){

	projection_.resize(maxLevel+1);
	kMat_.resize(maxLevel+1);

	// calculate projection matrix for level 0
	kMat_[0] <<  cam->f , 0 , width/2.0 , 0 , cam->f , height/2.0 , 0, 0, 1;


	Eigen::Quaterniond q;
	q.w() = cam->rq[0];
	q.x() = cam->rq[1];
	q.y() = cam->rq[2];
	q.z() = cam->rq[3];

	projection_[0].col(3) = -q.matrix().cast<float>() * cam->c.cast<float>() ;
	projection_[0].topLeftCorner(3,3) = q.matrix().cast<float>();

	projection_[0] = kMat_[0] * projection_[0];

	// now propagate to lower levels:
	for (int l = 1; l < maxLevel+1; l++){
		projection_[l] = projection_[l-1];
		projection_[l].row(0) /= 2.0;
		projection_[l].row(1) /= 2.0;

		kMat_[l] = kMat_[l-1];
		kMat_[l].row(0) /= 2.0;
		kMat_[l].row(1) /= 2.0;
	}

	// optical center
	center_.head(3) = cam->c.cast<float>();
	center_(3) = 1;

	// axis of the camera
	oAxis_ =  projection_[0].row(2);
	oAxis_ /= projection_[0].row(2).head(3).norm();

	zAxis_ = oAxis_.head(3);
	xAxis_ = projection_[0].row(0).head(3);
	yAxis_ = zAxis_.cross(xAxis_).normalized();
	xAxis_ = yAxis_.cross(zAxis_).normalized();

	// get the average pixelscale
	ipscale_ = (projection_[0].row(0).head(3).norm() + projection_[0].row(1).head(3).norm())/2.0;

}
Beispiel #2
0
void 
MFCC::init()
{
  unsigned int i,j;
  unsigned int chan;
  
  if (inSize_ != DEFAULT_WIN_SIZE) 
    {
      cerr << "MFCC::init warning inSize_ != 512\n" << endl ;
    }
  
  // Initialize frequency boundaries for the filters 
  freqs_.create(42);
  lowestFrequency_ = 133.3333f;
  linearFilters_ = 13;
  linearSpacing_ = 66.66666f;
  logFilters_ = 27;
  logSpacing_ = 1.0711703f;
  
  totalFilters_ = linearFilters_ + logFilters_;
  
  lower_.create(totalFilters_);
  center_.create(totalFilters_);
  upper_.create(totalFilters_);
  triangle_heights_.create(totalFilters_);

  // Linear filter boundaries
  for (i=0; i< linearFilters_; i++)
    freqs_(i) = lowestFrequency_ + i * linearSpacing_;

  // Logarithmic filter boundaries  
  float first_log = freqs_(linearFilters_-1);
  for (i=1; i<=logFilters_+2; i++)
    {
      freqs_(linearFilters_-1+i) = first_log * pow(logSpacing_, (float)i);
    }  
 
  // Triangles information
  for (i=0; i<totalFilters_; i++)
    lower_(i) = freqs_(i);
  
  for (i=1; i<= totalFilters_; i++)
    center_(i-1) = freqs_(i);
  
  for (i=2; i<= totalFilters_+1; i++)
    upper_(i-2) = freqs_(i);
  
  for (i=0; i<totalFilters_; i++)
    triangle_heights_(i) = 2.0 / (upper_(i) - lower_(i));
 
  fftSize_ = 512;
  samplingRate_ = 22050;
  fftFreqs_.create(fftSize_);
  cepstralCoefs_ = 13;
  
  for (i=0; i< fftSize_; i++)
    fftFreqs_(i) = (float)i / (float)fftSize_ * (float)samplingRate_;
  
  mfccFilterWeights_.create(totalFilters_, fftSize_);
  mfccDCT_.create(cepstralCoefs_, totalFilters_);
  
  // Initialize mfccFilterWeights

  
  for (chan = 0; chan < totalFilters_; chan++)
    for (i=0; i< fftSize_; i++)
      {
	if ((fftFreqs_(i) > lower_(chan))&& (fftFreqs_(i) <= center_(chan)))
	  {
	    mfccFilterWeights_(chan, i) = triangle_heights_(chan) *
	      ((fftFreqs_(i) - lower_(chan))/(center_(chan) - lower_(chan)));
	  }
	if ((fftFreqs_(i) > center_(chan)) && (fftFreqs_(i) <= upper_(chan)))
	  {
	    mfccFilterWeights_(chan, i) = triangle_heights_(chan) *
	      ((upper_(chan) - fftFreqs_(i))/(upper_(chan) - center_(chan)));
	  }
      }

  // Initialize MFCC_DCT
  float scale_fac = 1.0/ sqrt((double)(totalFilters_/2));
  for (j = 0; j<cepstralCoefs_; j++)
    for (i=0; i< totalFilters_; i++)
      {
	mfccDCT_(j, i) = scale_fac * cos(j * (2*i +1) * PI/2/totalFilters_);
	if (i == 0)
	  mfccDCT_(j,i) *= sqrt(2.0)/2.0;
      }  

  // Prepare feature names 
  
  featSize_ = outSize_;
  featNames_.push_back("MFCC00");
  featNames_.push_back("MFCC01");
  featNames_.push_back("MFCC02");
  featNames_.push_back("MFCC03");
  featNames_.push_back("MFCC04");
  featNames_.push_back("MFCC05");
  featNames_.push_back("MFCC06");
  featNames_.push_back("MFCC07");
  featNames_.push_back("MFCC08");
  featNames_.push_back("MFCC09");
  featNames_.push_back("MFCC10");
  featNames_.push_back("MFCC11");
  featNames_.push_back("MFCC12");

  hamming_ = new Hamming(inSize_, zeroSize_);
  magfft_ = new MagFFT(inSize_);
  windowed.create(inSize_);
  magnitude.create(inSize_/2);
  fmagnitude.create(inSize_);
  earMagnitude_.create(totalFilters_);
}
Beispiel #3
0
 uint SelectSubvolume(vec_t point) {
   std::bitset<D> bitindex;
   for(int i=0;i<D;++i)
     bitindex[i] = point(i) > center_(i) ? 1 : 0;
   return bitindex.to_ulong();
 }
Beispiel #4
0
 double center(int i) const { return center_(i); }