当前位置: 首页>>代码示例>>C++>>正文


C++ Encoder::flush方法代码示例

本文整理汇总了C++中Encoder::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ Encoder::flush方法的具体用法?C++ Encoder::flush怎么用?C++ Encoder::flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Encoder的用法示例。


在下文中一共展示了Encoder::flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv) {
  // argv[0] est le nom de la programme
  // argv[1] est le premier argument passé au programme
  // Get the data file name
  std::string path;
  
  if(argc>1)
      path = argv[1];
  else 
  {
    std::cerr <<"Usage error : "<< argv[0] << "+ data folder name." << std::endl;
    return 0;
  }
    
  std::cout << "Nom du chemin vers les données : ";
  std::cout << path << std::endl;
  
  
  
	Encoder * encoder = new Encoder();
  struct timeval now ;
  gettimeofday(&now,NULL);
	double initTime  = now.tv_sec + ((double)now.tv_usec)/1000000.0;
  encoder->acquire();
  encoder->flush(initTime);


  //compute odometry
  double L(0.529);
  encoder->odometry(L); 


  encoder->save(path);
  encoder->saveLeft(path);
  encoder->saveRight(path); 
  encoder->saveSynchro(path); 
  encoder->saveRaw(path); 
  
  
  
  
  
  return 0;
}
开发者ID:clairedune,项目名称:gaitan,代码行数:44,代码来源:encoderAcquire.cpp

示例2: mexFunction

void mexFunction(	int nlhs, mxArray *plhs[], 
				 int nrhs, const mxArray*prhs[] ) 
{ 
	/* retrive arguments */
	if( nrhs<4 ) 
		mexErrMsgTxt("4 input arguments are required."); 
    if( nlhs!=1 ) 
        mexErrMsgTxt("1 output arguments are required."); 
	// first argument : input array
	int n = mxGetM(prhs[0]); 
	int p = mxGetN(prhs[0]);
    if( p>1 )
        mexErrMsgTxt("Works only for vector arrays."); 
    int dir = (int) *mxGetPr(prhs[1]);
    double* x = mxGetPr(prhs[0]);

    if( mxGetM(prhs[3])!=2 && mxGetN(prhs[3])!=2 )
        mexErrMsgTxt("known_bounds must be of size 2."); 
    int known_size = (int) *mxGetPr(prhs[2]);

    // lower and upper bounds on the int to code
    int known_a = (int) mxGetPr(prhs[3])[0];
    int known_b = (int) mxGetPr(prhs[3])[1];
    bool coding_size = true;
    if( known_size>0 )          // the decoder will know the size and provide it
        coding_size = false;
    bool coding_bounds = false;
    if( known_a==known_b && known_b==-1 )
        coding_bounds = true;  // the decoder will not know the bounds and pr

    // create encoderovide it    
    int capacity = HISTO_CAPACITY;       // capacity of histogram for arithmetic coder  
    EscapeCoder* entropy = new EscapeCoder(capacity);

    if( dir==1 )
    {
        // compute range of the data
        int a = 1<<20, b = -(1<<20); 
        for( int i=0; i<n; ++i )
        {
            if( x[i]<a )
                a = (int) x[i];
            if( x[i]>b )
                b = (int) x[i];
        }
        int subrange = b-a+1;
		if( subrange>=HISTO_CAPACITY )
			mexErrMsgTxt( "Too much symbols." );

        // Open output file
        ofstream outfile(filename, ios::out | ios::trunc | ios::binary);
        if( !outfile )
            mexErrMsgTxt("Cannot open file."); 
        // Create I/O interface object for arithmetic coder
        Encoder* encoder = new Encoder( outfile );

        // set the number of symbols
        entropy->setNSym( subrange );

        // code the size of the image and range
        if( coding_size )
            encoder->writePositive(n);
        else if( known_size!=n )
            mexErrMsgTxt("The provided size does not match the real size."); 
        if( coding_bounds )
            encoder->writeInt(a);
        else if( known_a>a )
            mexErrMsgTxt("The provided bound does not match the real size."); 
        if( coding_bounds )
            encoder->writeInt(b);
        else if( known_b<b )
            mexErrMsgTxt("The provided bound does not match the real size."); 

        // perform coding
        for( int i=0; i<n; i++ ) 
        {
            // rescale to positive integers
            int symbol = (int) (x[i]-a);
            assert( symbol>=0 && symbol<subrange );
            entropy->write(encoder, symbol, TRUE);
        }
        // finish encoding
        encoder->flush();
        delete encoder;
        outfile.close();

        // reopen output file
        FILE* fin = fopen( filename, "rb" );
        if( fin==NULL )
            mexErrMsgTxt("Cannot open file."); 
        int nbr_bytes = 0;
        // compute number of bytes
        while( getc(fin)!=EOF )
            nbr_bytes++;
        fclose(fin);
        // retrieve results in byte
        fin = fopen( filename, "rb" );
        plhs[0] = mxCreateNumericMatrix( nbr_bytes, 1, mxDOUBLE_CLASS, mxREAL );
        double* y = mxGetPr( plhs[0] );
        for( int i=0; i<nbr_bytes; ++i )
//.........这里部分代码省略.........
开发者ID:FlyingZXC,项目名称:matlab-toolboxes,代码行数:101,代码来源:perform_arithmetic_coding_escape.cpp


注:本文中的Encoder::flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。