1. 程式人生 > >halcon學習之tuple轉化操作

halcon學習之tuple轉化操作

對tuple陣列執行相關的轉化操作

//通過截斷一個浮點型的資料,轉化為整形資料,tuple內容不允許是string型別

    HTuple tuple1 = 12.124431432;
    HTuple result = tuple1.TupleInt();
    cout << (Hlong)result<<endl;

//檢測一個tuple是否代表是數字,輸入可以是字串、浮點數、整數。字串內容如果都代表數字,返回1,整數、浮點數返回1,其他返回0;

    HTuple tuple2 = "0";
    result = tuple2.TupleIsNumber();
    cout << (Hlong)result
<< endl;

//轉化一個(主要是指string型別)tuple到數字

    HTuple tuple3;
    tuple3[0] = "102.51";
    tuple3[1] = "10";
    result = tuple3.TupleNumber();
    cout << (double)result[0] << endl;
    cout << (Hlong)result[1] << endl;

//轉化一個數字型別為浮點型,不允許為string型別

    HTuple tuple4 = 586
; result = tuple4.TupleReal(); cout << (double)result << endl;

//轉化一個數字型別為整形,比如2.9=3,2.1=2

    HTuple tuple5 = 2.1;
    result = tuple5.TupleRound();
    cout << (Hlong)result << endl;

//按照一定格式轉化一個tuple為string型別

    HTuple tuple6 = 23;
    result = tuple6.TupleString("10.3f"
); cout << (HString)result << endl;

//返回長度為1的單個字元,(比如“0”,“a”…)對應的ASCII碼所對應的值。

    HTuple tuple7 = "0";
    result = tuple7.TupleOrd();
    cout << (Hlong)result << endl;

//返回一個字串中每個字元,(比如“0”,“a”…)對應的ASCII碼所對應的值。

    HTuple tuple8 = "ab1";
    result = tuple8.TupleOrds();
    cout << (Hlong)result[0] << endl;
    cout << (Hlong)result[1] << endl;
    cout << (Hlong)result[2] << endl;

//TupleOrd函式的逆操作。

    HTuple tuple9 = 97;
    result = tuple9.TupleChr();
    cout << (HString)result << endl;

//TupleOrd函式的逆操作

    HTuple tuple10;
    tuple10[0] = 48;
    tuple10[1] = 98;
    tuple10[2] = 99;

    result = tuple10.TupleChrt();
    cout << (HString)result << endl;