Пример #1
0
void gmls_functional_compute(gmls_functional_t* functional,
                             int i,
                             real_t t,
                             multicomp_poly_basis_t* poly_basis,
                             real_t* solution,
                             real_t* lambdas)
{
  START_FUNCTION_TIMER();
  if (functional->surface_quad_rule != NULL)
  {
    surface_integral_set_domain(functional->surface_quad_rule, i);
    int num_quad_points = surface_integral_num_points(functional->surface_quad_rule);
    point_t quad_points[num_quad_points];
    real_t quad_weights[num_quad_points];
    vector_t quad_normals[num_quad_points];
    surface_integral_get_quadrature(functional->surface_quad_rule, quad_points, quad_weights, quad_normals);
    compute_integral(functional, t, poly_basis, solution,
                     quad_points, quad_weights, quad_normals, num_quad_points, 
                     lambdas);
  }
  else
  {
    volume_integral_set_domain(functional->volume_quad_rule, i);
    int num_quad_points = volume_integral_num_points(functional->volume_quad_rule);
    point_t quad_points[num_quad_points];
    real_t quad_weights[num_quad_points];
    volume_integral_get_quadrature(functional->volume_quad_rule, quad_points, quad_weights);
    compute_integral(functional, t, poly_basis, solution, 
                     quad_points, quad_weights, NULL, num_quad_points, 
                     lambdas);
  }
  STOP_FUNCTION_TIMER();
}
Пример #2
0
void CvHaarEvaluator::setImage( const Mat& img, uchar /*clsLabel*/, int /*idx*/)
{
  CV_DbgAssert( !sum.empty() );

  winSize.width = img.cols;
  winSize.height = img.rows;

  CvFeatureEvaluator::setImage( img, 1, 0 );
  if( !isIntegral )
  {
    std::vector<Mat_<float> > ii_imgs;
    compute_integral( img, ii_imgs );
    _ii_img = ii_imgs[0];
  }
  else
  {
    _ii_img = img;
  }
}
bool TrackerMILImpl::updateImpl( const Mat& image, Rect2d& boundingBox )
{
  Mat intImage;
  compute_integral( image, intImage );

  //get the last location [AAM] X(k-1)
  Ptr<TrackerTargetState> lastLocation = model->getLastTargetState();
  Rect lastBoundingBox( (int)lastLocation->getTargetPosition().x, (int)lastLocation->getTargetPosition().y, lastLocation->getTargetWidth(),
                        lastLocation->getTargetHeight() );

  //sampling new frame based on last location
  ( sampler->getSamplers().at( 0 ).second ).staticCast<TrackerSamplerCSC>()->setMode( TrackerSamplerCSC::MODE_DETECT );
  sampler->sampling( intImage, lastBoundingBox );
  std::vector<Mat> detectSamples = sampler->getSamples();
  if( detectSamples.empty() )
    return false;

  /*//TODO debug samples
   Mat f;
   image.copyTo(f);

   for( size_t i = 0; i < detectSamples.size(); i=i+10 )
   {
   Size sz;
   Point off;
   detectSamples.at(i).locateROI(sz, off);
   rectangle(f, Rect(off.x,off.y,detectSamples.at(i).cols,detectSamples.at(i).rows), Scalar(255,0,0), 1);
   }*/

  //extract features from new samples
  featureSet->extraction( detectSamples );
  std::vector<Mat> response = featureSet->getResponses();

  //predict new location
  ConfidenceMap cmap;
  model.staticCast<TrackerMILModel>()->setMode( TrackerMILModel::MODE_ESTIMATON, detectSamples );
  model.staticCast<TrackerMILModel>()->responseToConfidenceMap( response, cmap );
  model->getTrackerStateEstimator().staticCast<TrackerStateEstimatorMILBoosting>()->setCurrentConfidenceMap( cmap );

  if( !model->runStateEstimator() )
  {
    return false;
  }

  Ptr<TrackerTargetState> currentState = model->getLastTargetState();
  boundingBox = Rect( (int)currentState->getTargetPosition().x, (int)currentState->getTargetPosition().y, currentState->getTargetWidth(),
                      currentState->getTargetHeight() );

  /*//TODO debug
   rectangle(f, lastBoundingBox, Scalar(0,255,0), 1);
   rectangle(f, boundingBox, Scalar(0,0,255), 1);
   imshow("f", f);
   //waitKey( 0 );*/

  //sampling new frame based on new location
  //Positive sampling
  ( sampler->getSamplers().at( 0 ).second ).staticCast<TrackerSamplerCSC>()->setMode( TrackerSamplerCSC::MODE_INIT_POS );
  sampler->sampling( intImage, boundingBox );
  std::vector<Mat> posSamples = sampler->getSamples();

  //Negative sampling
  ( sampler->getSamplers().at( 0 ).second ).staticCast<TrackerSamplerCSC>()->setMode( TrackerSamplerCSC::MODE_INIT_NEG );
  sampler->sampling( intImage, boundingBox );
  std::vector<Mat> negSamples = sampler->getSamples();

  if( posSamples.empty() || negSamples.empty() )
    return false;

  //extract features
  featureSet->extraction( posSamples );
  std::vector<Mat> posResponse = featureSet->getResponses();

  featureSet->extraction( negSamples );
  std::vector<Mat> negResponse = featureSet->getResponses();

  //model estimate
  model.staticCast<TrackerMILModel>()->setMode( TrackerMILModel::MODE_POSITIVE, posSamples );
  model->modelEstimation( posResponse );
  model.staticCast<TrackerMILModel>()->setMode( TrackerMILModel::MODE_NEGATIVE, negSamples );
  model->modelEstimation( negResponse );

  //model update
  model->modelUpdate();

  return true;
}
bool TrackerMILImpl::initImpl( const Mat& image, const Rect2d& boundingBox )
{
  srand (1);
  Mat intImage;
  compute_integral( image, intImage );
  TrackerSamplerCSC::Params CSCparameters;
  CSCparameters.initInRad = params.samplerInitInRadius;
  CSCparameters.searchWinSize = params.samplerSearchWinSize;
  CSCparameters.initMaxNegNum = params.samplerInitMaxNegNum;
  CSCparameters.trackInPosRad = params.samplerTrackInRadius;
  CSCparameters.trackMaxPosNum = params.samplerTrackMaxPosNum;
  CSCparameters.trackMaxNegNum = params.samplerTrackMaxNegNum;

  Ptr<TrackerSamplerAlgorithm> CSCSampler = Ptr<TrackerSamplerCSC>( new TrackerSamplerCSC( CSCparameters ) );
  if( !sampler->addTrackerSamplerAlgorithm( CSCSampler ) )
    return false;

  //or add CSC sampler with default parameters
  //sampler->addTrackerSamplerAlgorithm( "CSC" );

  //Positive sampling
  CSCSampler.staticCast<TrackerSamplerCSC>()->setMode( TrackerSamplerCSC::MODE_INIT_POS );
  sampler->sampling( intImage, boundingBox );
  std::vector<Mat> posSamples = sampler->getSamples();

  //Negative sampling
  CSCSampler.staticCast<TrackerSamplerCSC>()->setMode( TrackerSamplerCSC::MODE_INIT_NEG );
  sampler->sampling( intImage, boundingBox );
  std::vector<Mat> negSamples = sampler->getSamples();

  if( posSamples.empty() || negSamples.empty() )
    return false;

  //compute HAAR features
  TrackerFeatureHAAR::Params HAARparameters;
  HAARparameters.numFeatures = params.featureSetNumFeatures;
  HAARparameters.rectSize = Size( (int)boundingBox.width, (int)boundingBox.height );
  HAARparameters.isIntegral = true;
  Ptr<TrackerFeature> trackerFeature = Ptr<TrackerFeatureHAAR>( new TrackerFeatureHAAR( HAARparameters ) );
  featureSet->addTrackerFeature( trackerFeature );

  featureSet->extraction( posSamples );
  const std::vector<Mat> posResponse = featureSet->getResponses();

  featureSet->extraction( negSamples );
  const std::vector<Mat> negResponse = featureSet->getResponses();

  model = Ptr<TrackerMILModel>( new TrackerMILModel( boundingBox ) );
  Ptr<TrackerStateEstimatorMILBoosting> stateEstimator = Ptr<TrackerStateEstimatorMILBoosting>(
      new TrackerStateEstimatorMILBoosting( params.featureSetNumFeatures ) );
  model->setTrackerStateEstimator( stateEstimator );

  //Run model estimation and update
  model.staticCast<TrackerMILModel>()->setMode( TrackerMILModel::MODE_POSITIVE, posSamples );
  model->modelEstimation( posResponse );
  model.staticCast<TrackerMILModel>()->setMode( TrackerMILModel::MODE_NEGATIVE, negSamples );
  model->modelEstimation( negResponse );
  model->modelUpdate();

  return true;
}
Пример #5
0
/*---------------------------------------
|					|
|		init_makeslice()		|
|					|
+--------------------------------------*/
static int init_makeslice(int argc, char *argv[])
{
char	path1[MAXPATHL],diffname[MAXPATHL];
short	status_mask;
int	i;
FILE	*diffusion_file;
double	integ_step;
extern	int	read_peak_file(/*peak_table,filename*/);


#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "At start of init_makeslice\n");
  fclose(debug);
#endif
if (
   P_getreal(PROCESSED,"fn",&fn,1)	||
   P_getreal(CURRENT,"sw",&sw,1)	||
   P_getreal(PROCESSED,"fn1",&fn1,1)	||
   P_getreal(CURRENT,"sw1",&sw1,1)
   )
		{
                Werrprintf("makeslice: Error accessing parameters\n");
                return(ERROR);
                }
/* PB: The following lines have been added to check the number of arguments to makeslice */
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "fn = %f\n",fn);
  fprintf (debug, "sw = %f\n",sw);
  fprintf (debug, "fn1 = %f\n",fn);
  fprintf (debug, "sw1 = %f\n",sw1);
  fprintf (debug, "After reading parameters in init_makeslice\n");
  fclose(debug);
#endif

if((argc<3)||(argc>4)){
		Werrprintf("makeslice: incorrect number of arguments \n");
		Werrprintf("makeslice('<mode>(optional)',start,finish)\n");
                return(ERROR);
		}
if(argc==3) {
		display_mode='i'; 
		start_diff = atof(argv[1]);
		finish_diff = atof(argv[2]);
	}	

else {
	if((argv[1][0]!='i')&&(argv[1][0]!='s')){
		Werrprintf("makeslice: if 'mode' is specified, it must be supplied as first argument!");
		return(ERROR);
		}
		display_mode = argv[1][0];
		start_diff = atof(argv[2]);
		finish_diff = atof(argv[3]);
	}

if(start_diff>finish_diff) swap(&start_diff,&finish_diff);
mean_diff = 0.5*(start_diff+finish_diff);
diff_window = finish_diff-start_diff;


/* initialise the data files in the present experiment ... */
if ( (r = D_gethead(D_DATAFILE, &fidhead)) )
	{
      	if (r == D_NOTOPEN)
      		{
/*		Wscrprintf("spectrum had to be re-opened?\n"); */
         	strcpy(path1, curexpdir);
         	strcat(path1, "/datdir/data");
         	r = D_open(D_DATAFILE, path1, &fidhead); /* open the file */
      		}
      	if (r)
      		{
         	D_error(r);
 	        return(ERROR);
      		}
  	}

#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "After reading header in init_makeslice\n");
  fclose(debug);
#endif
f1pts=1;
status_mask = (S_COMPLEX);
if ((fidhead.status & status_mask) == status_mask ) f1pts=2;
status_mask = (S_HYPERCOMPLEX);
if ((fidhead.status & status_mask) == status_mask ) f1pts=4;
status_mask = (S_DATA|S_SPEC|S_FLOAT|S_SECND);
if ( (fidhead.status & status_mask) != status_mask )
	{
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Status is %d in init_makeslice\n",fidhead.status);
  fclose(debug);
#endif
     	Werrprintf("No 2D spectrum available, please use undosy3D or do 2D transform before using makeslice\n");
     	return(ERROR);
  	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Before initialising peak table in init_makeslice\n");
  fclose(debug);
#endif
fn_int = (int) fn;
fn1_int = (int) fn1;
/* Initialise the peak table */
strcpy(path1,curexpdir);
strcat(path1,"/ll2d/peaks.bin");
if (read_peak_file(&peak_table,path1))
	{
	Wscrprintf("makeslice: Could not read ll2d peak file !\n");
	delete_peak_table(&peak_table);
	return(ERROR);
	}

#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Opening diffusion_display_3d.inp file in init_makeslice\n");
  fclose(debug);
#endif
peak = peak_table->head;
strcpy(diffname,curexpdir);
strcat(diffname,"/dosy/diffusion_display_3D.inp");
if ((diffusion_file=fopen(diffname,"r"))==NULL)
	{
	Werrprintf("Error opening %s file\n",diffname);
	return(ERROR);
	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Reading diffusion_display_3d.inp file in init_makeslice\n");
  fclose(debug);
#endif

/* Read in the diffusion information, and check whether peaks are in the diffusion band */
i=0;
integ_step = diff_window/(2.0*(double)NINTSTEPS);	/* the calculation is divided in NINTSTEPS steps */
/*Wscrprintf("\n\tDiffusion range visible: %.2lf +/- %.2lf\n\n",mean_diff,0.5*diff_window);*/
Wscrprintf("\n\tDiffusion range visible: from %.2lf to %.2lf (*10e-10m2s-1)\n\n",start_diff,finish_diff);
while(fscanf(diffusion_file,"%d %lf %lf\n",&pk[i].num,&pk[i].diff_coef,&pk[i].std_dev)!=EOF && i<MAXNUMPEAKS)
	{
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Reading peak %d in init_makeslice\n",i);
  fclose(debug);
#endif
	if (display_mode == 's')
		{
		if (within_diffusion_boundaries(i))
			{
			if (compute_integral(i,integ_step) == TRUE)	i++;
			}
		}
	else if (display_mode == 'i')
		{
		r = compute_integral(i,integ_step);
		/* If less than 1 % of intensity, then assume 0 */
        	if (pk[i].intensity >= 0.01)
               		{
		/* If at least 95 % of the intensity within, then assume 100 % */
                	if (pk[i].intensity >= 0.95) pk[i].intensity = 1.0;
                	i++;
                	}
		}
	}
if (display_mode == 's')
	{
	/* Check that the last peak IS within the slice because it does not get eliminated by the above loop */
	if (!within_diffusion_boundaries(i))
		{
		pk[i].num = 0;
		pk[i].diff_coef = 0.0;
		pk[i].std_dev = 0.0;
		}
	else if (compute_integral(i,integ_step) != TRUE)
		{
		pk[i].num = 0;
		pk[i].diff_coef = 0.0;
		pk[i].std_dev = 0.0;
		}
	}
if (display_mode == 'i')
	{
	/* Check the final peak */
	if (pk[i-1].intensity < 0.01)
		{
		pk[i-1].num = 0.0;
		pk[i-1].diff_coef = 0.0;
		pk[i-1].std_dev = 0.0;
		pk[i-1].intensity = 0.0;
		}
	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "Before closing diffusion_display_3d.inp file in init_makeslice\n");
  fclose(debug);
#endif
fclose(diffusion_file);
if (i == MAXNUMPEAKS)
	{
	Wscrprintf("number of peaks reduced to %d\n",MAXNUMPEAKS);
	}
#ifdef DEBUG_MAKESLICE
  strcpy (rubbish, curexpdir);
  strcat (rubbish, "/dosy/debug_makeslice");
  debug = fopen (rubbish, "a"); /* file for debugging information */
  fprintf (debug, "After reading peak file in init_makeslice\n");
  fclose(debug);
#endif

/*   Set PHASFILE status to !S_DATA - this is required to
   force a recalculation of the display from the new data
   in DATAFILE (in the ds routine, see proc2d.c)          */

if ( (r = D_gethead(D_PHASFILE,&phasehead)) )
	{
	if (r == D_NOTOPEN)
		{
/*		Wscrprintf("phas NOTOPEN\n"); */
		strcpy(path1,curexpdir);
		strcat(path1,"/datdir/phasefile");
		r = D_open(D_PHASFILE,path1,&phasehead);
		}
	if (r)
		{
		D_error(r);
		return(ERROR);
		}
	}
phasehead.status = 0;
if ( (r = D_updatehead(D_PHASFILE, &phasehead)) )
	{
	D_error(r);
	Wscrprintf("PHASE updatehead\n");
	return(ERROR);
	}

return(COMPLETE);
}