示例#1
0
int TargetICU::Load(string file)
{
  string filename;
  string tmp;
  string patchfic;
  ifstream fichier;
  string ficshape = icuConfigPath +"shapes/";
  string ficshape_config = icuConfigPath +"shapes/";

  cout << "****************************************" << endl;
  cout << "*   LOADING NEW FACE TRACKING TARGET   *" << endl;
  cout << "****************************************" << endl;
  
  /* charge les parametres communs de la cible */
  if(!Target::Load(file)) 
    {
      cout << "|ERROR|--> TargetICU (LO) \t:\t Loading error" << endl;
      return 0;
    } 

  /* ouverture */
  fichier.open(file.c_str(), ios::in);
  if(!fichier)
    {
      cout << "|ERROR|--> TargetICU (LO) \t:\t file not found [" << file << "]" << endl;  
      return 0;
    }   

  /* Charge les parametres de forme a utiliser */

  /*******************************************************************************************************/
  /* Chargement des parametres de mesure de la forme                                                     */
  /*******************************************************************************************************/

  /* Fichier contenant la forme */
  cout << "--> TargetICU (Load) \t:\t Loading shape" << endl;
  FindStr2(fichier,"<ShapeModel>");
  if(fichier.eof()) 
    { 
      cout << "--> TargetICU (Load) \t:\t No <ShapeModel> defined" << endl;
      this->spline=NULL;
      shapeCue=false;
      fichier.clear();
    }
  else
    {
      fichier >> tmp;
      ficshape+=tmp;
      ficshape_config+=tmp + "_config";
      cout << "--> TargetICU (Load) \t:\t Loading shape from [" << ficshape  << ".dat]" << endl;
      this->ShM = new ShapeModels(ficshape.c_str(),ficshape_config.c_str(),"dat");
      cout << "--> TargetICU (Load) \t:\t ShapeModel loaded" << endl;
      
      /* Fichier contenant la forme */
      FindStr2(fichier,"<UseFlowMask>");
      if(fichier.eof())
	{
	  cout << "--> TargetICU (LO) \t:\t Don't use flowmask" << endl;
	  useflowmask=false;
	  fichier.clear();
	}
      else
	{    
	  fichier >> tmp;
	  if(tmp=="yes") 
	    {
	      useflowmask=true;
	      cout << "--> TargetICU (LO) \t:\t Use flowmask" << endl;
	    }
	  else
	    {
	      useflowmask=false;
	      cout << "--> TargetICU (LO) \t:\t Don't use flowmask" << endl;
	    }
	}

      /* Pointe sur la forme */
      this->spline = this->ShM->GetShapeModels();
      shapeCue=true;
    }


  /*******************************************************************************************************/
  /* Chargement des parametres de mesure de la couleur                                                   */
  /*******************************************************************************************************/

  /* On charge la Structure des rectangles qui constituent la cible */
  cout << "--> TargetICU (LO) \t:\t Loading rect structure" << endl;
  FindStr2(fichier,"<ColorRectStructFile>");
  if(fichier.eof()) 
    { 
      cout << "--> TargetICU (LO) \t:\t Don't use color distribution cue" << endl;
      colorCue=false;
      fichier.clear();
    }
  else
    {
      /* Lecture du nom de fichier a charger */
      fichier >> tmp;
      
      /* Allocation de la cible multi rectangles */
      cout << "--> TargetICU (LO) \t:\t Using color distribution cue" << endl;
      colorCue=true;

      /* Alloc des patchs */
      FileReplace(file,tmp,patchfic);
      colorPatch = new RoiManager(width,height,patchfic);

      /* Allocation des histogrammes */
      cout << "--> TargetICU (LO) \t:\t Histograms allocations....(" << colorPatch->nbp << ")" << endl;
      coldistref = new ColorDistribution(colorPatch->nbp,width,height);
      coldist = new ColorDistribution(colorPatch->nbp,width,height);
      cout << "--> TargetICU (LO) \t:\t Histograms allocations....OK" << endl;

      cout << "--> TargetICU (LO) \t:\t Loading " << colorPatch->nbp << " coeff in the list" << endl;
      coefflist = new double[colorPatch->nbp];
      
      FindStr2(fichier,"<ColorUpdateCoeff>");
      if(fichier.eof()) 
	{
	  cout << "|ERROR|--> TargetICU (LO) \t:\t <ColorUpdateCoeff> not found" << endl;       
	  return 0;
	}
      for(int i=0;i<colorPatch->nbp;i++)
	{
	  fichier >> this->coefflist[i];
	  cout << "--> TargetICU (LO) \t:\t Histogram " << i << " coeff = " << this->coefflist[i]  << endl;
	}
      
      /* Controle la validite de la lecture */
      fichier >> tmp;
      if(tmp!="</ColorUpdateCoeff>") 
	{
	  cout << "|ERROR|--> TargetICU (LO) \t:\t not enought coeffs, must be = " << colorPatch->nbp << endl;       
	  return 0;
	}
    }

  /*******************************************************************************************************/
  /* Chargement des parametres de mesure de mouvement                                                    */
  /*******************************************************************************************************/

  /* On charge la Structure des rectangles qui constituent la cible */
  cout << "--> TargetICU (LO) \t:\t Loading motion rect structure" << endl;
  FindStr2(fichier,"<MotionRectStructFile>");
  if(fichier.eof()) 
    { 
      cout << "--> TargetICU (LO) \t:\t Don't use motion distribution cue" << endl;
      motionCue=false;
      fichier.clear();
    }
  else
    {
      /* Lecture du nom de fichier a charger */
      fichier >> tmp;
      
      /* Allocation de la cible multi rectangles */
      cout << "--> TargetICU (LO) \t:\t Using motion distribution cue" << endl;
      motionCue=true;

      /* Alloc des patchs */
      FileReplace(file,tmp,patchfic);
      motionPatch = new RoiManager(width,height,patchfic);

      /* Allocation des histogrammes */
      cout << "--> TargetICU (LO) \t:\t Histogram allocation...." << endl;
      md = new MotionDistribution(8,motionPatch->nbp,width,height);
      cout << "--> TargetICU (LO) \t:\t Histogram allocation....OK" << endl;
    }

  fichier.close(); 

  /* En fonction du type de generateur d'image de mesure on associe une methode de calcul de vraissemblance */
  
  return 1;
}
示例#2
0
//Write the file back out, with the changes
bool BlueZip::Write(bool Store)
{
	//TODO: Do not use a TempFile, send straight to the output

	char TempFileName[MAX_PATH];
	File f;

	zList* z;
	zList** next = &Files; //where to insert the next zList

	int i, j; //global enumeration variables

	if ((Files == NULL) && (Pending == NULL))
	{
		ErrMsg("Blank ZIP files not allowed");
		return false;
	}

	//Always use a temporary file name (they may have the ZIP file on a floppy)
	f = FileOpenTemp(TempFileName);
	if (!FileValid(f))
	{
		ErrMsg(Failed to open the temporary file);
		return false;
	}

	if (Files != NULL)
	{
		File Orig = FileOpenRead(FileName);
		if (!FileValid(Orig))
		{
			ErrMsg("Failed to open the reading file");
			return false;
		}

		const int BlockSize = 4096;
		char* Buffer = new char[BlockSize];
		datCentral hLocal;
		for (z = Files; z != NULL; z = z->next)
		{
			if (!z->Delete)
			{
				//Remove any that have dropped out of the list
				*next = z;
				next = &z->next;

				//Perform a ZIP copy
				SeekBeg(Orig, z->data.Offset + z->FileDeltaPos);
				z->data.Offset = FilePos(f);

				u32 sig;
				FileRead(Orig, &sig, 4);
				Assert(sig == sigLocal);
				FileWrite(f, &sig, 4);

				hLocal.ReadLocal(Orig);
				hLocal.WriteLocal(f);

				i = hLocal.CompSize + hLocal.lFileName + hLocal.lExtra;
				while(i != 0)
				{
					j = min(i, BlockSize);
					FileRead(Orig, Buffer, j);
					FileWrite(f, Buffer, j);
					i -= j;
				}
			}
		}
		FileClose(Orig);
		delete[] Buffer;
	}


	while (Pending != NULL)
	{
		fList* fAdd = Pending;
		Pending = Pending->next;

		z = fAdd->ZipUp(f, Store);
		if (z == NULL)
		{
			ErrMsg("Failed to add the file");
		}
		else
		{
			*next = z;
			next = &z->next;
		}

		delete fAdd;

	}

	//Write out the central header
	data.Count = 0;
	data.Offset = FilePos(f);
	for (z = Files; z != NULL; z = z->next, data.Count++)
		z->WriteCentral(f);

	data.Size = FilePos(f) - data.Offset;
	WriteEnd(f);

	FileClose(f);

	//Using a temp file
	if (!FileReplace(FileName, TempFileName))
	{
		ErrMsg("Failed to copy the temporary file");
		return false;
	}

	return true;
}