qixiaoning
9 天以前 eac932eb827c93e2e998ac1210c3f5e548af0dbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package zconf
 
import (
    "encoding/json"
    "fmt"
    "io/ioutil"
    "os"
)
 
const configPath = "/opt/vasystem/bin/zconf/Projection.json"
 
/* 算法配置文件模板
{
    "so_file_path": "/opt/vasystem/libs/Detect/libdemo.so",
    "runtime": "/opt/vasystem/libs/Detect:/usr/local/cuda-11.1/lib64:",  // 项目所用到的环境
    "param": {
        "modelboard_path": "../2.jpg",
        "rotation":[
                    4.4445828203215609e-01,
                    8.9316070946330617e-01,
                    -6.8707951534213177e-02,
                    -8.4673423557111882e-01,
                    4.4391245485198838e-01,
                    2.9322835254980756e-01,
                    2.9240035883154664e-01,
                    -7.2150394997427411e-02,
                    9.5357031762576261e-01
                ],
        "translation": [-3.1951405668851648e+03, 2.1818898071652611e+03, 6.3212411982103204e+03]
    }
}
*/
 
type ZConfig struct {
    SoFilePath string `json:"so_file_path"`
    Runtime    string `json:"runtime"`
    Param      struct {
        ModelBoardPath string    `json:"modelboard_path"`
        Rotation       []float64 `json:"rotation"`
        Translation    []float64 `json:"translation"`
    } `json:"param"`
}
 
var Options *ZConfig
 
func LoadConfig() {
    Options = nil
 
    if !pathExists(configPath) {
        Options = DefaultConfig()
        SaveConfig(Options)
    } else {
        file, _ := os.Open(configPath)
        defer file.Close()
 
        fd := json.NewDecoder(file)
 
        err := fd.Decode(&Options)
        if err != nil {
            fmt.Printf("parse config error, %s\n", err.Error())
        } else {
            fmt.Printf("config:%v\n", Options)
        }
    }
}
 
func DefaultConfig() *ZConfig {
    var defaultOption ZConfig
    defaultOption.SoFilePath = "/opt/vasystem/libs/Detect/libdemo.so"
    defaultOption.Runtime = "/opt/vasystem/libs/Detect:/usr/local/cuda-11.1/lib64"
    defaultOption.Param.ModelBoardPath = "../2.jpg"
    defaultOption.Param.Rotation = []float64{
        4.4445828203215609e-01,
        8.9316070946330617e-01,
        -6.8707951534213177e-02,
        -8.4673423557111882e-01,
        4.4391245485198838e-01,
        2.9322835254980756e-01,
        2.9240035883154664e-01,
        -7.2150394997427411e-02,
        9.5357031762576261e-01,
    }
 
    defaultOption.Param.Translation = []float64{
        -3.1951405668851648e+03,
        2.1818898071652611e+03,
        6.3212411982103204e+03,
    }
 
    return &defaultOption
}
 
func SaveConfig(options *ZConfig) {
    bytes, err := json.MarshalIndent(options, "", "\t")
    if err == nil {
        ioutil.WriteFile(configPath, bytes, 0744)
    }
}
 
func pathExists(path string) bool {
    _, err := os.Stat(path)
    if err != nil {
        fmt.Printf("%v", err.Error())
        return os.IsExist(err)
    }
 
    return true
}