From 263c7b18ce7f18f1222318f6e0e499e907895a52 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 13 十一月 2019 19:33:39 +0800 Subject: [PATCH] fix --- extend/util/util.go | 36 ++++++++++++++++++++++++++++++++++-- 1 files changed, 34 insertions(+), 2 deletions(-) diff --git a/extend/util/util.go b/extend/util/util.go index a3e314f..8f7883c 100644 --- a/extend/util/util.go +++ b/extend/util/util.go @@ -7,6 +7,7 @@ "errors" "github.com/gin-gonic/gin" "github.com/golang/glog" + "github.com/pierrec/lz4" "gocv.io/x/gocv" "image" "net" @@ -192,6 +193,37 @@ } func ParseScore(compareScore float32) float32 { - f, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", compareScore), 32) + if compareScore < 1 { + compareScore = compareScore * 100 + } + f, _ := strconv.ParseFloat(fmt.Sprintf("%2.2f", compareScore), 32) return float32(f) -} \ No newline at end of file +} + +// UnCompress uncompress +func UnCompress(in []byte) ([]byte, error) { + out := make([]byte, 10*len(in)) + n, err := lz4.UncompressBlock(in, out) + if err != nil { + fmt.Println(err) + return nil, err + } + out = out[:n] // uncompressed data + return out, nil +} + +// Compress compress +func Compress(in []byte) ([]byte, error) { + out := make([]byte, len(in)) + ht := make([]int, 64<<10) // buffer for the compression table + n, err := lz4.CompressBlock(in, out, ht) + if err != nil { + fmt.Println(err) + return nil, err + } + if n >= len(in) { + fmt.Println("image is not compressible") + } + out = out[:n] // compressed data + return out, nil +} -- Gitblit v1.8.0