Beispiel #1
0
bool FileUtil::saveDescriptorWithLabel(const cv::Mat &descriptor,
                                       const int32_t label,
                                       const std::string &outputPath,
                                       const std::string &descriptorFileName,
                                       const std::string &labelFileName, const std::string &prefix)
{
    FileWriter<BIN> writer;

    if(!descriptor.empty()) {
        QDir outputDir(QString::fromStdString(outputPath));
        if(outputDir.exists()) {
            if(writer.write(descriptor, outputPath, descriptorFileName, prefix)) {
                if(appendDescriptor(labelFileName,
                                    outputPath,
                                    descriptorFileName,
                                    label,
                                    prefix)) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            error("Output directory doesn't exist, aborting.");
            return false;
        }
    } else {
        error("Empty output object given, aborting.");
        return false;
    }
}
Beispiel #2
0
  bool WayLocationProcessorFilter::AfterProcessingEnd(const ImportParameter& /*parameter*/,
                                                      Progress& progress,
                                                      const TypeConfig& /*typeConfig*/)
  {
    delete nameReader;
    nameReader=NULL;

    delete locationReader;
    locationReader=NULL;

    writer.SetPos(0);
    writer.Write(overallDataCount);

    try {
      writer.Close();
    }
    catch (IOException& e) {
      progress.Error(e.GetDescription());

      writer.CloseFailsafe();

      return false;
    }

    return true;
  }
Beispiel #3
0
void REFRRecord::REFRXSED::Write(FileWriter &writer)
    {
    if(isOffset)
        writer.record_write_subrecord(REV32(XSED), &offset, 1);
    else
        writer.record_write_subrecord(REV32(XSED), &seed, 4);
    }
Beispiel #4
0
ERet FxUtil_SaveShadersToFile(const FxShaderCache& code, const char* path)
{
	FileWriter	stream;
	mxDO(stream.Open(path, FileWrite_NoErrors));
	mxDO(code.SaveShaderCode(stream));
	return ALL_OK;
}
void Gesture::SaveTrainingData( char *filename )
{
    FileWriter *file = g_app->m_resource->GetFileWriter( filename, false );

    int numSymbols = GetNumSymbols();
    file->printf( "%d\n", numSymbols );

    for( int c = 0; c < numSymbols; ++c )
    {
        Classification *theClass = &m_symbols[c].m_classes;

        file->printf( "%d\n", theClass->m_nextTrainer );
        for( int t = 0; t < theClass->m_nextTrainer; ++t )
        {
            FeatureSet *fs = &theClass->m_trainers[t];
            for( int f = 0; f <= GESTURE_MAX_FEATURES; ++f )
            {
                float temp = (float) fs->f[f];
                file->printf( "%f ", temp );
            }
        }

        file->printf( "\n" );
    }

    delete file;
}
Beispiel #6
0
Result_t
Kumu::ReadFileIntoBuffer(const std::string& Filename, Kumu::ByteString& Buffer, ui32_t max_size)
{
  ui32_t file_size = FileSize(Filename);
  Result_t result = Buffer.Capacity(file_size);

  if ( KM_SUCCESS(result) )
    {
      ui32_t read_count = 0;
      FileWriter Reader;

      result = Reader.OpenRead(Filename);

      if ( KM_SUCCESS(result) )
	result = Reader.Read(Buffer.Data(), file_size, &read_count);
    
      if ( KM_SUCCESS(result) )
	{
	  if ( file_size != read_count) 
	    return RESULT_READFAIL;

	  Buffer.Length(read_count);
	}
    }
  
  return result;
}
Beispiel #7
0
Kumu::Result_t
Kumu::ReadFileIntoObject(const std::string& Filename, Kumu::IArchive& Object, ui32_t max_size)
{
  ByteString Buffer;
  ui32_t file_size = static_cast<ui32_t>(FileSize(Filename));
  Result_t result = Buffer.Capacity(file_size);

  if ( KM_SUCCESS(result) )
    {
      ui32_t read_count = 0;
      FileWriter Reader;

      result = Reader.OpenRead(Filename);

      if ( KM_SUCCESS(result) )
	result = Reader.Read(Buffer.Data(), file_size, &read_count);
    
      if ( KM_SUCCESS(result) )
	{
	  assert(file_size == read_count);
	  Buffer.Length(read_count);
	  MemIOReader MemReader(&Buffer);
	  result = Object.Unarchive(&MemReader) ? RESULT_OK : RESULT_READFAIL;
	}
    }

  return result;
}
Beispiel #8
0
Kumu::Result_t
Kumu::WriteObjectIntoFile(const Kumu::IArchive& Object, const std::string& Filename)
{
  ByteString Buffer;
  Result_t result = Buffer.Capacity(Object.ArchiveLength());

  if ( KM_SUCCESS(result) )
    {
      ui32_t write_count = 0;
      FileWriter Writer;
      MemIOWriter MemWriter(&Buffer);

      result = Object.Archive(&MemWriter) ? RESULT_OK : RESULT_WRITEFAIL;

      if ( KM_SUCCESS(result) )
	{
	  Buffer.Length(MemWriter.Length());
	  result = Writer.OpenWrite(Filename);
	}

      if ( KM_SUCCESS(result) )
	result = Writer.Write(Buffer.RoData(), Buffer.Length(), &write_count);
    }

  return result;
}
Beispiel #9
0
SINT32 GMSTRecord::WriteRecord(FileWriter &writer)
    {
    if(EDID.IsLoaded()) //Should only be false if the record was marked deleted
        {
        WRITE(EDID);
        UINT8 null = 0;
        switch(DATA.format)
            {
            case 'i':
                writer.record_write_subrecord(REV32(DATA), &DATA.i, 4);
                break;
            case 'f':
                writer.record_write_subrecord(REV32(DATA), &DATA.f, 4);
                break;
            case 's':
                if(DATA.s != NULL)
                    writer.record_write_subrecord(REV32(DATA), DATA.s, (UINT32)strlen(DATA.s) + 1);
                else
                    writer.record_write_subrecord(REV32(DATA), &null, 1);
                break;
            default:
                printer("Unknown GMST format (%c) when writing: %s\n", DATA.format, EDID.value);
                break;
            }
        }
    return -1;
    }
Beispiel #10
0
  bool Way::Write(const TypeConfig& typeConfig,
                  FileWriter& writer) const
  {
    assert(!nodes.empty());

    writer.WriteTypeId(featureValueBuffer.GetType()->GetWayId(),
                       typeConfig.GetWayTypeIdBytes());

    if (!featureValueBuffer.Write(writer)) {
      return false;
    }

    if (!writer.Write(nodes)) {
      return false;
    }

    if (featureValueBuffer.GetType()->CanRoute() ||
        featureValueBuffer.GetType()->GetOptimizeLowZoom()) {
      if (!WriteIds(writer)) {
        return false;
      }
    }

    return !writer.HasError();
  }
 void write(FileWriter& writer) const 
 {
   writer.start_section("animation");
   writer.write("pos",  m_pos);
   writer.write("name", m_name);
   writer.end_section();
 }
Beispiel #12
0
// 文件加密函数
// 这个函数有点长,但是基本上都是检错的代码。逻辑还是很清晰的。
errno_t EasyEncrypt(const string& inFilename, const string& outFilename, const string& key)
{
    LOGPOS();

    FileReader fileReader;
    FilePath inFilePath(inFilename);
    if (fileReader.Open(inFilePath.value()) != CPT_OK) {
        LOGW("Open file %s failed!", inFilePath.value().c_str());
        return CPT_ERROR;
    }

    Encrypt encrypt;
    if (encrypt.SetReader(dynamic_cast<Reader*>(&fileReader)) != CPT_OK) {
        LOGW("Encrypt Set Reader failed");
        return CPT_ERROR;
    }

    FileHeader *fileHeader = encrypt.GenrHeader();
    if (fileHeader == NULL) {
        LOGW("Generate file header failed!");
        return CPT_ERROR;
    }

    fileHeader->SetFormat(inFilePath.Extension());

    if (encrypt.EncryptHeader(key.c_str(), key.length()) != CPT_OK) {
        LOGW("Encrypt file header failed");
        return CPT_ERROR;
    }

    FileWriter writer;
    if (writer.Open(outFilename) != CPT_OK) {
        LOGW("Create file %s failed!", outFilename.c_str());
        return CPT_ERROR;
    }

    if (encrypt.SetWriter(dynamic_cast<Writer*>(&writer)) != CPT_OK) {
        LOGW("encrypt set writer failed!");
        return CPT_ERROR;
    }

    if (encrypt.WriteHeader() != CPT_OK) {
        LOGW("Encrypt write header failed!");
        return CPT_ERROR;
    }
    
    int err = encrypt.PreEncrypt();
    ASSERT(err == CPT_OK);

    if (encrypt.DoEncrypt(key.c_str(), key.length()) != CPT_OK) {
        LOGW("Encrypt encrypt failed!");
        return CPT_ERROR;
    }

    err = encrypt.PostEncrypt();
    ASSERT(err == CPT_OK);

    return CPT_OK;
}
Beispiel #13
0
void ex_mfcc_chain () {

	ITheFramework *frame = Factory::GetFramework ();

	Decorator *decorator = ssi_create (Decorator, 0, true);
	frame->AddDecorator(decorator);

	// audio sensor	
#ifndef SIMULATE
	Audio *audio = ssi_create (Audio, "audio", true);
	audio->getOptions()->scale = true;		
	ITransformable *audio_p = frame->AddProvider(audio, SSI_AUDIO_PROVIDER_NAME);
#else
	WavReader *audio = ssi_create (WavReader, 0, true);
	audio->getOptions()->setPath("audio.wav");
	audio->getOptions()->scale = true;		
	ITransformable *audio_p = frame->AddProvider(audio, SSI_WAVREADER_PROVIDER_NAME);
#endif	
	frame->AddSensor(audio);

	// preemph
	OSPreemphasis *preemph = ssi_create (OSPreemphasis, "preemph", true);
	ITransformable *preemph_t = frame->AddTransformer(audio_p, preemph, "0.02s");

	// fft
	OSMfccChain *mfcc = ssi_create (OSMfccChain, "mfcc", true);	
	mfcc->getOSTransformFFT()->getOptions()->nfft = 2048;
	ITransformable *mfcc_t = frame->AddTransformer(preemph_t, mfcc, "0.01s", "0.01s");

	// plot
	SignalPainter *plot = 0;	

	plot = ssi_create_id (SignalPainter, 0, "plot");
	plot->getOptions()->setTitle("audio");
	plot->getOptions()->type = PaintSignalType::AUDIO;
	plot->getOptions()->size = 10.0;		
	frame->AddConsumer(audio_p, plot, "0.1s");
	
	plot = ssi_create_id (SignalPainter, 0, "plot");
	plot->getOptions()->setTitle("mfcc");
	plot->getOptions()->type =  PaintSignalType::IMAGE;
	plot->getOptions()->size = 10.0;
	frame->AddConsumer(mfcc_t, plot, "0.1s"); 

	FileWriter *writer = ssi_create (FileWriter, 0, true);
	writer->getOptions()->setPath("mfcc_chain");
	writer->getOptions()->type = File::ASCII;
	frame->AddConsumer(mfcc_t, writer, "0.1s");

	// run framework
	decorator->add("console", 0, 0, 650, 800);
	decorator->add("plot*", 650, 0, 400, 400);
	decorator->add("monitor*", 650, 400, 400, 400);

	frame->Start();
	frame->Wait();
	frame->Stop();
	frame->Clear();	
}
  /**
   * Write the TurnRestriction data to the given FileWriter
   *
   * @throws IOException
   */
  void TurnRestriction::Write(FileWriter& writer) const
  {
    writer.WriteNumber((uint32_t)type);

    writer.WriteNumber(from);
    writer.WriteNumber(via);
    writer.WriteNumber(to);
  }
Beispiel #15
0
void WriteBuffer(const char *pszFormat, const char *pszFilename, void *pBuffer, DWORD dwBufferSize)
{
  FileWriter fw;
  char szTmp[MAX_PATH];
  sprintf(szTmp, pszFormat, pszFilename);
  if ( fw.Open( szTmp ) )
    fw.WriteRaw(pBuffer, dwBufferSize);
}
Beispiel #16
0
bool ex_plp(void *args) {

	ITheFramework *frame = Factory::GetFramework();

	Decorator *decorator = ssi_create (Decorator, 0, true);
	frame->AddDecorator(decorator);

	// audio sensor	
#ifndef SIMULATE
	Audio *audio = ssi_create(Audio, "audio", true);
	audio->getOptions()->scale = true;
	ITransformable *audio_p = frame->AddProvider(audio, SSI_AUDIO_PROVIDER_NAME);
#else
	WavReader *audio = ssi_create(WavReader, 0, true);
	audio->getOptions()->setPath("audio.wav");
	audio->getOptions()->scale = true;
	ITransformable *audio_p = frame->AddProvider(audio, SSI_WAVREADER_PROVIDER_NAME);
#endif	
	frame->AddSensor(audio);

	OSPlpChain *plp = ssi_create(OSPlpChain, "OSPlpChain", true);
	ITransformable *plp_t = frame->AddTransformer(audio_p, plp, "0.06s", "0.01s");

	SignalPainter *plot = 0;

	plot = ssi_create_id (SignalPainter, 0, "plot");
	plot->getOptions()->setTitle("audio");
	plot->getOptions()->type = PaintSignalType::AUDIO;
	plot->getOptions()->size = 10.0;
	frame->AddConsumer(audio_p, plot, "0.1s");

	plot = ssi_create_id (SignalPainter, 0, "plot");
	plot->getOptions()->setTitle("lpc");
	plot->getOptions()->size = 10.0;
	frame->AddConsumer(plp_t, plot, "1");

	FileWriter *writer = ssi_create(FileWriter, 0, true);
	writer->getOptions()->setPath("plp_chain");
	writer->getOptions()->type = File::ASCII;
	frame->AddConsumer(plp_t, writer, "1");

#ifdef SIMULATE
	AudioPlayer *player = ssi_create(AudioPlayer, "player", true);
	frame->AddConsumer(audio_p, player, "0.01s");
#endif

	// run framework
	decorator->add("console", 0, 0, 650, 800);
	decorator->add("plot*", 650, 0, 400, 400);
	decorator->add("monitor*", 650, 400, 400, 400);

	frame->Start();
	frame->Wait();
	frame->Stop();
	frame->Clear();

	return true;
}
Beispiel #17
0
void LegacyRulePlanNode::write(FileWriter &w, CPArea parentArea) const
{
	PlanNode::write(w, parentArea);
	// write rule identification including revision here
	w.appendIdentifier(getDatabase()->getId(),'/');
	w.appendIdentifier(getCube()->getId(),'/');
	w.appendIdentifier(getRule()->getId(),'/');
	w.appendIdentifier((IdentifierType)getDatabase()->getObjectRevision(),0); // TODO: -jj- serialize uint64_t
}
Beispiel #18
0
void ex_pitch_chain () {

	ITheFramework *frame = Factory::GetFramework ();

	Decorator *decorator = ssi_create (Decorator, 0, true);
	frame->AddDecorator(decorator);

	// audio sensor	
#ifndef SIMULATE
	Audio *audio = ssi_create (Audio, "audio", true);
	audio->getOptions()->scale = true;		
	ITransformable *audio_p = frame->AddProvider(audio, SSI_AUDIO_PROVIDER_NAME);
#else
	WavReader *audio = ssi_create (WavReader, 0, true);
	audio->getOptions()->setPath("audio.wav");
	audio->getOptions()->scale = true;		
	audio->getOptions()->block = 0.01;
	ITransformable *audio_p = frame->AddProvider(audio, SSI_WAVREADER_PROVIDER_NAME);
#endif	
	frame->AddSensor(audio);

	// pitch
	OSPitchChain *pitch = ssi_create (OSPitchChain, "pitch", true);	
	pitch->getOSTransformFFT()->getOptions()->nfft = 1024;
	pitch->getOSPitchShs()->getOptions()->baseSr = audio_p->getSampleRate();
	ITransformable *pitch_t = frame->AddTransformer(audio_p, pitch, "0.01s", "0.01s");

	// plot
	SignalPainter *plot = 0;	

	plot = ssi_create_id (SignalPainter, 0, "plot");
	plot->getOptions()->setTitle("audio");
	plot->getOptions()->type = PaintSignalType::AUDIO;
	plot->getOptions()->size = 10.0;		
	frame->AddConsumer(audio_p, plot, "0.01s");
	
	plot = ssi_create_id (SignalPainter, 0, "plot");
	plot->getOptions()->setTitle("pitch");
	plot->getOptions()->size = 10.0;
	frame->AddConsumer(pitch_t, plot, "0.01s"); 

	FileWriter *writer = ssi_create (FileWriter, 0, true);
	writer->getOptions()->setPath("pitch_chain");
	writer->getOptions()->type = File::ASCII;
	frame->AddConsumer(pitch_t, writer, "0.01s");

	// run framework
	decorator->add("console", 0, 0, 650, 800);
	decorator->add("plot*", 650, 0, 400, 400);
	decorator->add("monitor*", 650, 400, 400, 400);

	frame->Start();
	frame->Wait();
	frame->Stop();
	frame->Clear();	
}
Beispiel #19
0
void LStringRecord::ReqWrite(UINT32 _Type, FileWriter &writer)
{
    if (value != NULL)
        writer.record_write_subrecord(_Type, value, static_cast<UINT32>(strlen(value)) + 1);
    else
    {
        UINT8 null = 0x00;
        writer.record_write_subrecord(_Type, &null, 1);
    }
}
Beispiel #20
0
FileWriter *FileWriter::Open(const char *filename)
{
	FileWriter *fwrit = new FileWriter();
	if (fwrit->OpenDirect(filename))
	{
		return fwrit;
	}
	delete fwrit;
	return NULL;
}
void
Timeline::write(FileWriter& writer) const
{
    writer.start_section("layers");
    for(const_iterator i = begin(); i != end(); ++i)
    {
        (*i)->write(writer);
    }
    writer.end_section();
}
void ArrayStringCount::writeToDisk(std::string& file_name)
{
    WaitForSingleObject(gHashWriteSemaphone, INFINITE);
    {
        FileWriter FW = FileWriter(file_name);
        FW.write(this->start, this->start_offset - this->start);
        this->total_write += (this->start_offset - this->start);
        this->start_offset = this->start;
    }
    ReleaseSemaphore(gHashWriteSemaphone, 1, NULL);
}
Beispiel #23
0
errno_t EasyDecrypt(const string& filename, const string& key, string *outFilename)
{
    LOGPOS();

    FilePath inFilePath(filename);
    FileReader reader;
    if (reader.Open(inFilePath.value()) != CPT_OK) {
        LOGW("Open file %s failed!", inFilePath.value().c_str());
        return CPT_ERROR;
    }

    Decrypt decrypt;
    if (decrypt.SetReader(&reader) != CPT_OK) {
        LOGW("Decrypt set reader failed!");
        return CPT_ERROR;
    }

    if (decrypt.LoadHeader() != CPT_OK) {
        LOGW("Decrypt load header failed!");
        return CPT_ERROR;
    }

    FileHeader *fileHeader = decrypt.DecryptHeader(key.c_str(), key.length());
    if (fileHeader == NULL) {
        LOGW("LoadHeader error");
        return CPT_ERROR;
    }

    FilePath outFilePath = inFilePath.ReplaceExtension(fileHeader->GetFormat());
    *outFilename = outFilePath.value();
    FileWriter writer;
    if (writer.Open(outFilePath.value()) != CPT_OK) {
        LOGW("Create file %s failed!", outFilePath.value().c_str());
        return CPT_ERROR;
    }

    if (decrypt.SetWriter(dynamic_cast<Writer*>(&writer)) != CPT_OK) {
        LOGW("Decrypt set writer failed!");
        return CPT_ERROR;
    }

    int err = decrypt.PreDecrypt();
    ASSERT(err == CPT_OK);

    if (decrypt.DoDecrypt(key.c_str(), key.length())) {
        LOGW("Decrypt decrypt file failed!");
        return CPT_ERROR;
    }

    err = decrypt.PostDecrypt();
    ASSERT(err == CPT_OK);

    return CPT_OK;
}
Beispiel #24
0
bool FileUtil::saveBinary(const cv::Mat &data,
                          const std::string &outputPath,
                          const std::string &fileName,
                          const std::string &prefix)
{
    FileWriter<BIN> binaryWriter;

    return binaryWriter.write(data,
                              outputPath,
                              fileName,
                              prefix);
}
Beispiel #25
0
void CullingNode::save(FileWriter& file) const
{
    // Save complex entity data
    ComplexEntity::save(file);

    // Write header
    file.beginVersionedSection(CullingNodeVersionInfo);

    file.write(41);

    file.endVersionedSection();
}
Beispiel #26
0
void batch_mode(){
  if(pa("-config")){
    ConfigFile f(*pa("-config"));
    int masksize = f["config.masksize"];
    int thresh = f["config.threshold"];
    float gamma = f["config.gammaslope"];
    if(!pa("-output")){
      printf("please specify output file pattern\n");
      return;
    }

    grabber.init(pa("-i"));
    FileList fl;
    int maxSteps = -1;
    if(grabber.getType() == "file"){
      fl = FileList(*pa("-input",1));
      maxSteps = fl.size();
    }

    static FileWriter w(*pa("-output"));
    static LocalThresholdOp t;
    t.setMaskSize(masksize);
    t.setGlobalThreshold(thresh);
    t.setGammaSlope(gamma);
  
    int i=0;
    while(maxSteps < 0 || maxSteps--){
      if(maxSteps > 0){
        printf("processing image %30s ......",fl[i++].c_str());
      }
      const ImgBase *image = grabber.grab();
      if(image->getFormat() != formatGray){
        printf("...");
        static ImgBase *grayImage = 0;
        ensureCompatible(&grayImage,depth8u,image->getSize(),formatGray);
        cc(image,grayImage);
        printf("...");
        image = grayImage;
      }
      static ImgBase *dst = 0;
      printf("...");
      t.apply(image,&dst);
      printf("...");
      w.write(dst); 
      printf("done! \n");
      printf("writing image to %30s ... done\n",w.getFilenameGenerator().showNext().c_str());
    }
  }else{
    ERROR_LOG("please run with -config config-filename!");
    return;
  }
}
Beispiel #27
0
void PropertyObject::Write(FileWriter &writer)
{
    // Always in format 2
    uint16_t null = 0;
    Property::Write(writer);
    writer.record_write(&null, sizeof(null));
    writer.record_write(&aliasId, sizeof(aliasId));
    writer.record_write(&formId, sizeof(formId));
    // format 1:
    // writer.record_write(&formId, sizeof(formId));
    // writer.record_write(&aliasId, sizeof(aliasId));
    // writer.record_write(&null, sizeof(null));
}
Beispiel #28
0
  bool Node::Write(const TypeConfig& /*typeConfig*/,
                   FileWriter& writer) const
  {
    writer.WriteNumber(featureValueBuffer.GetType()->GetId());

    if (!featureValueBuffer.Write(writer)) {
      return false;
    }

    writer.WriteCoord(coords);

    return !writer.HasError();
  }
Beispiel #29
0
Kumu::Result_t
Kumu::WriteStringIntoFile(const std::string& filename, const std::string& inString)
{
  FileWriter File;
  ui32_t write_count = 0;

  Result_t result = File.OpenWrite(filename);

  if ( KM_SUCCESS(result) )
    result = File.Write((byte_t*)inString.c_str(), inString.length(), &write_count);

  return result;
}
Beispiel #30
0
void createHeader(FileWriter& writer, FileReader& reader) {
	std::string line("");
	while (true){
		line = reader.getNextLine() + "\n";
		if (isHeaderLine(line)) {
			writer.writeLine(line);
		} else if (isCommentLine(line)) {
			writer.writeLine(line);
			return;
		}
		if (!reader.isGood()) return;
	}
};