engineerper 1 år sedan
förälder
incheckning
a3f330a9a7
5 ändrade filer med 75 tillägg och 3 borttagningar
  1. 7 0
      config.yaml
  2. 11 0
      config/config.go
  3. 50 1
      eventServer/eventServer.go
  4. 1 0
      eventServer/plateNumber.go
  5. 6 2
      model/app/carinfo.go

+ 7 - 0
config.yaml

@@ -58,3 +58,10 @@ hikvision:
   streamBaseUrl: "webrtc://106.52.134.22/live/"
 
 
+#摄像头1 测量长度和高度
+camera1:
+  a: [500, 450, 400, 350, 300, 250, 200, 150, 100, 50]
+  b: [50, 100, 150, 200, 250, 300, 350, 400, 450, 500]
+#摄像头2 测量宽度
+camera2:
+  a: [500, 450, 400, 350, 300, 250, 200, 150, 100, 50]

+ 11 - 0
config/config.go

@@ -36,6 +36,7 @@ type config struct {
 	HttpHostNotificationList HttpHostNotificationList `mapstructure:"HttpHostNotificationList" yaml:"HttpHostNotificationList" xml:"HttpHostNotificationList"`
 	Foreign                  Foreign                  `mapstructure:"foreign" yaml:"foreign" json:"foreign"`
 	Hikvision                Hikvision                `mapstructure:"hikvision" yaml:"hikvision" json:"hikvision"`
+	Metering                 Metering                 `mapstructure:"metering" yaml:"metering" json:"metering"`
 }
 
 type System struct {
@@ -112,6 +113,7 @@ type Redis struct {
 }
 
 // 事件监听服务器列表
+
 type HttpHostNotificationList struct {
 	HttpHostNotification []HttpHostNotification `yaml:"HttpHostNotification"`
 }
@@ -138,3 +140,12 @@ type Hikvision struct {
 	Password      string `yaml:"password"`
 	StreamBaseUrl string `mapstructure:"streamBaseUrl" yaml:"streamBaseUrl"`
 }
+type Metering struct {
+	Camera1 struct {
+		A []int `yaml:"a"`
+		B []int `yaml:"b"`
+	} `yaml:"camera1"`
+	Camera2 struct {
+		A []int `yaml:"a"`
+	} `yaml:"camera2"`
+}

+ 50 - 1
eventServer/eventServer.go

@@ -7,11 +7,14 @@ import (
 	mail "github.com/xhit/go-simple-mail/v2"
 	"io"
 	"io/ioutil"
+	"lc-fangdaosha/global"
 	"lc-fangdaosha/model/app"
 	"lc-fangdaosha/service"
 	"log"
+	"math"
 	"mime/multipart"
 	"net/http"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -68,6 +71,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
 var eventService = service.ServiceGroupApp.AppServiceGroup.EventService
 var carInfoService = service.ServiceGroupApp.AppServiceGroup.CarInfoService
 
+// 保留小数
+func round(num float64, places int) float64 {
+	shift := math.Pow(10, float64(places))
+	return math.Round(num*shift) / shift
+}
+
+var bulk = make(map[string][]float64)
+
 // 处理多文件事件
 func handleMultipart(r *http.Request) {
 	// todo  远程联动
@@ -103,7 +114,45 @@ func handleMultipart(r *http.Request) {
 		eventCode := part.Header.Get("Content-ID")
 		picName := timeFmt(eventAlert.DateTime) + ".jpeg"
 		data, _ := ioutil.ReadAll(part)
-		if strings.Contains(eventAlert.ChannelName, "PlateNumber") {
+		if strings.Contains(eventAlert.ChannelName, "plateNumber") {
+			//todo 识别车牌,记录次数
+			number, err := CallLicensePlateRecognitionAPI(data)
+			if err != nil {
+				fmt.Println("车牌识别失败:", err)
+				//time.Sleep(1000)
+			}
+			//todo 处理车牌号
+			carInfoService.ProcessPlateNumber(number)
+			return
+		}
+		if strings.Contains(eventAlert.ChannelName, "metering1") {
+			//todo 测量车的长度和高度
+			targetRect := eventAlert.DetectionRegionList.DetectionRegionEntry[0].TargetRect
+			//x, _ := strconv.ParseFloat(targetRect.X, 64)
+			y, _ := strconv.ParseFloat(targetRect.Y, 64)
+			h, _ := strconv.ParseFloat(targetRect.Height, 64)
+			w, _ := strconv.ParseFloat(targetRect.Width, 64)
+			n := int(round(y+h, 1) * 10)
+			b := float64(global.Config.Metering.Camera1.B[n])
+			a := float64(global.Config.Metering.Camera1.A[n])
+			rh := h / (y + h) * b
+			rl := w * a
+			dateTime := eventAlert.DateTime
+			bulk[dateTime] = append(bulk[dateTime], rh, rl)
+			return
+		}
+		if strings.Contains(eventAlert.ChannelName, "metering2") {
+			//todo 测量车的宽度
+			targetRect := eventAlert.DetectionRegionList.DetectionRegionEntry[0].TargetRect
+			//x, _ := strconv.ParseFloat(targetRect.X, 64)
+			y, _ := strconv.ParseFloat(targetRect.Y, 64)
+			h, _ := strconv.ParseFloat(targetRect.Height, 64)
+			w, _ := strconv.ParseFloat(targetRect.Width, 64)
+			n := int(round(y+h, 1) * 10)
+			a := float64(global.Config.Metering.Camera2.A[n])
+			rw := w * a
+			dateTime := eventAlert.DateTime
+			bulk[dateTime] = append(bulk[dateTime], rw)
 			//todo 识别车牌,记录次数
 			number, err := CallLicensePlateRecognitionAPI(data)
 			if err != nil {

+ 1 - 0
eventServer/plateNumber.go

@@ -10,6 +10,7 @@ import (
 	ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
 )
 
+// CallLicensePlateRecognitionAPI 识别车牌
 func CallLicensePlateRecognitionAPI(file []byte) (number string, err error) {
 	// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
 	credential := common.NewCredential(

+ 6 - 2
model/app/carinfo.go

@@ -10,8 +10,12 @@ type CarInfo struct {
 	global.GVA_MODEL
 	PlateNumber string `json:"plateNumber" form:"plateNumber" gorm:"column:plate_number;comment:车牌号;"`
 	//CarType     string    `json:"carType" form:"carType" gorm:"column:car_type;comment:车类型;"`
-	Time  time.Time `json:"time" form:"time" gorm:"column:time;comment:出现时间;"`
-	Count int       `json:"count" form:"count" gorm:"column:count;comment:出现次数;"`
+	Long   float64   `json:"long" form:"long" gorm:"column:long;comment:长度;"`
+	Width  float64   `json:"width" form:"width" gorm:"column:width;comment:宽度;"`
+	Height float64   `json:"height" form:"height" gorm:"column:height;comment:高度;"`
+	Time   time.Time `json:"time" form:"time" gorm:"column:time;comment:出现时间;"`
+	Count  int       `json:"count" form:"count" gorm:"column:count;comment:出现次数;"`
+	Volume float64   `json:"volume" form:"volume" gorm:"column:volume;comment:体积;"`
 }
 
 // TableName CarInfo 自定义表名