0

对不起我的英语:) 试图改进我的应用程序我想将向量直接复制到没有字符串的 mysql 中,这甚至可能吗?

FileStorage fs( ".yml", FileStorage::WRITE + FileStorage::MEMORY );

Ptr < FaceRecognizer > model0 = createmyfisherRecognizer();

model0->train( images, labels );

model0->save( fs );




void myfisher::save( FileStorage & fs ) const {

    static char * host = "localhost"; /* host serwera MySQL */
    static char * user = "root"; /* nazwa loginu by polaczyc sie do serwera */
    static char * password = ""; /* haslo */
    static char * sql_db = "fisher"; /* nazwa bazy */
    static unsigned int sql_port = NULL; /* port na jakim odbiera/wysyla serwer mysql */
    static char * opt_socket = NULL; /* socket name */
    static unsigned int sql_flags = 0;
    static MYSQL * sock; /* Wskaznik do polaczenia do MySQL */

    sock = mysql_init( NULL );

    if( mysql_real_connect( sock, host, user, password, sql_db, sql_port, opt_socket, sql_flags ) )
         cout << "Poprawnie polaczyles sie z baza danych" << endl;
    else
         cout << "Blad w polaczeniu z baza danych" << endl;

    fs << "num_components" << _num_components;
    fs << "mean" << _mean;
    fs << "eigenvalues" << _eigenvalues;
    writeFileNodeList( fs, "projections", _projections );
    fs << "labels" << _labels;

    string buf = fs.releaseAndGetString();

    fs.release();

    string zapytanie = "insert into baa values (\"" + buf + "\")";

    if( !mysql_query( sock, zapytanie.c_str() ) )
         cout << "Poprawnie dodano" << endl;
    else
         cout << "Blad przy zapisywaniu" << endl;

}

在这里,我发布了有问题的代码。目前它以这种方式工作:

  1. 一切都保存到 fs (FileStorage)
  2. fs 中的数据转换为字符串
  3. fs 发送到数据库 众所周知,如果不带字符串直接将程序复制到数据库,程序运行速度会快得多。
4

1 回答 1

0

我认为您可以为此使用snprintf,不幸的是,因为缺少变量类型,我无法给您确切的示例。

char string[100];
snprintf(string, 100, "printe text %s,\n and integer %i", "printf", 100); //almost same as printf
于 2013-07-17T11:46:35.400 回答