New file |
| | |
| | | package ruleserver |
| | | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "encoding/json" |
| | | "fmt" |
| | | "ruleprocess/structure" |
| | | |
| | | "testing" |
| | | ) |
| | | |
| | | func TestPgsInterPercent(t *testing.T) { |
| | | areaPoints := json2points("[{\"x\":582,\"y\":11},{\"x\":582,\"y\":525},{\"x\":943,\"y\":525},{\"x\":943,\"y\":11}]") |
| | | widthScale := float64(2688) / 960 |
| | | heigthScale := float64(1520) / 540 |
| | | rec := structure.Rect{1333, 594,204,274} |
| | | per := PgsInterPercent(areaPoints,rec,widthScale,heigthScale) |
| | | fmt.Println(widthScale,heigthScale,per) |
| | | } |
| | | |
| | | // 将字符串格式的坐标序列化为Point格式 |
| | | func json2points(areaPoints string) []Point { |
| | | var pts []Point |
| | | if areaPoints == "[]" || areaPoints == "" { |
| | | logger.Error("=====================此区域为全部区域") |
| | | pts = append(pts, Point{0, 0}) |
| | | pts = append(pts, Point{0, 540}) |
| | | pts = append(pts, Point{960, 540}) |
| | | pts = append(pts, Point{960, 0}) |
| | | } else { |
| | | err := json.Unmarshal([]byte(areaPoints), &pts) |
| | | if err != nil { |
| | | logger.Error("json.Unmarshal错误", err) |
| | | panic("序列化坐标异常,程序退出") |
| | | } |
| | | } |
| | | return pts |
| | | } |
| | |
| | | |
| | | areaPoints := Json2points(a.AreaJson) |
| | | logger.Info("看看图片的width和height:",arg.ImageWidth,arg.ImageHeight) |
| | | widthScale := float64(arg.ImageWidth / 960) |
| | | heigthScale := float64(arg.ImageHeight / 540) |
| | | widthScale := float64(arg.ImageWidth) / 960 |
| | | heigthScale := float64(arg.ImageHeight) / 540 |
| | | for _, obj := range arg.Photo { |
| | | //logger.Info("------------------看看sdkData:", arg.SdkName, "的Photo数据----------------", obj, "----顺便看看占比-----:", PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale)) |
| | | if threshold <= obj.Score && size <= float64(obj.Rects.Width*obj.Rects.Height) && intersectionper <= PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) { |
| | | if obj.Score >= threshold && float64(obj.Rects.Width*obj.Rects.Height) >= size && PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) >= intersectionper { |
| | | // 这步要备齐表达式里所需要的所有参数 |
| | | a.TargetNum++ |
| | | arg1 := structure.Arg{obj.Id,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.Feature, obj.ThftRes, []*structure.BaseInfo{}} |