int main(int argc, char **argv) {
	if (argc!=7) {
		printf("Usage: this.exe hsKind covKind nStates mixes paraKind streamList\n");
		printf("hsKind : P(?)\n");
		printf("covKind : InvDiagC/DiagC/FullC\n");
		printf("nStates : 1(3,5)\n");
		printf("mixes, mixes for each stream: \"6 6 6\"(3 streams here)\n");
		printf("paraKind : MFCC_E_D_A_Z(case-by-case)\n");
		printf("streamList, feature dimension for each stream : \"13 13 13\"(also 3 streams here)\n");
		exit(-1);
	}

	char hsKind[2];//=P
	char covKind[10];//=D
	int nStates;//=3
	char paraKind[100];//=MFCC_E_D_A_Z

	sscanf(argv[1],"%s", &hsKind);
	sscanf(argv[2],"%s", &covKind);
	sscanf(argv[3],"%d", &nStates);
	sscanf(argv[5],"%s", &paraKind);

	//u must copy static argv[4] into a modifiable memory like tmpstr, if you use strtok();
	
	String strobj(1000);
	
  StringArray list_stream(100, 10, 10);
	int nStreams = strobj.split(argv[6], " ", &list_stream);

  StringArray list_mix(nStreams, 10, 10);
	int nMix = strobj.split(argv[4], " ", &list_mix);

    if (nStreams!=nMix)
    {
        printf("number of streams not the same as number of mixtures\n");
	    exit(1);
	}
	int* mixes = new int[nStreams];
	int* sWidths = new int[nStreams];//=13 13 13
	int vecSize = 0; 
	for (int i=0;i<nStreams;i++)
	{
		mixes[i] = atoi(list_mix.rowAt(i));
		sWidths[i]=atoi(list_stream.rowAt(i));
        vecSize += sWidths[i];
	}
	
	outMacroTxt(hsKind, covKind, nStates, nStreams, sWidths, mixes, paraKind, vecSize) ;
	delete mixes;
	delete sWidths;
    exit(0);    
}
Exemple #2
0
int CommandHandler::process(const string& cmd, ImageDBConfig& config) {
    if (cmd == "list") {
        db::DB* db = db::open_db(config.src(), db::READ);
        if (!db) {
            LOG(ERROR) << "Failed to open db: " << config.src();
            return -1;
        }
        for (db::Iterator* it = db->new_iterator(); it->valid(); it->next()) {
            cout << it->key() << endl;
        }
        return 0;
    }

    std::istream list_stream(cin.rdbuf());
    std::ifstream list_file_stream;
    if (!config.listfile().empty()) {
        list_file_stream.open(config.listfile());
        if (list_file_stream.is_open()) {
            list_stream.rdbuf(list_file_stream.rdbuf());
        } else {
            LOG(ERROR) << "Failed to open listfile: " << config.listfile() << endl;
            return -1;
        }
    }

    int ret_code = 0;
    boost::shared_ptr<CommandProcessor> processor;
    std::vector<boost::shared_ptr<op::Operation>> ops;
    if (cmd == "pipe") {
        if (!op::create_ops_from_config(config.opsfile(), ops)) {
            return -1;
        }
        processor.reset(new PipeProcessor(ops));
    } else if (cmd == "save") {
        processor.reset(new SaveProcessor(config.dst()));
    } else {
        std::map<string, string> ops_config;
        ops_config["cmd"] = cmd;
        if (!config.dst().empty()) {
            ops_config["db"] = config.dst();
        }

        boost::shared_ptr<op::Operation> op_ptr = op::get_operation(ops_config);
        if (op_ptr) {
            ops.push_back(op_ptr);
        } else {
            LOG(ERROR) << "Unsupported command: " << cmd;
            return -1;
        }

        if (!config.dst().empty()) {
            ops_config["cmd"] = "save";
            ops_config["key"] = "$2";
            boost::shared_ptr<op::Operation> save_op = op::get_operation(ops_config);
            ops.push_back(save_op);
            op_ptr.get()->post(save_op);
        }

        processor.reset(new PipeProcessor(ops));
    }

    if (processor->good()) {
        ret_code = process_list(config, list_stream, processor);
    } else {
        ret_code = -1;
    }

    if (list_file_stream.is_open()) {
        list_file_stream.close();
    }

    return ret_code;
}