Kaynağa Gözat

车子长宽高统计

longan 1 yıl önce
ebeveyn
işleme
7382234228
4 değiştirilmiş dosya ile 68 ekleme ve 38 silme
  1. 23 0
      eventServer/capacity.go
  2. 25 14
      eventServer/eventServer.go
  3. 10 6
      go.mod
  4. 10 18
      go.sum

+ 23 - 0
eventServer/capacity.go

@@ -0,0 +1,23 @@
+package eventServer
+
+import "sync"
+
+var LhChan = make(chan [2]float64, 20) //传长,高
+var WChan = make(chan float64, 20)     //传宽
+
+func CalcCap() (l, w, h float64) {
+	var wg sync.WaitGroup
+	wg.Add(2)
+	go func() {
+		lh := <-LhChan
+		l = lh[0]
+		h = lh[1]
+		wg.Done()
+	}()
+	go func() {
+		w = <-WChan
+		wg.Done()
+	}()
+	wg.Wait()
+	return
+}

+ 25 - 14
eventServer/eventServer.go

@@ -31,6 +31,15 @@ type MQDEvent struct {
 }
 
 func StartEventServer() {
+	//记录长宽高
+	go func() {
+		for {
+			l, w, h := CalcCap()
+			time.Sleep(500 * time.Millisecond)
+			//todo 根据长宽高估计车厢体积
+			fmt.Println("长", l, "宽", w, "高", h)
+		}
+	}()
 	http.HandleFunc("/event", handler)
 	logrus.Fatal("事件监听服务启动失败", http.ListenAndServe(":8850", nil))
 }
@@ -115,7 +124,7 @@ func handleMultipart(r *http.Request) {
 		picName := timeFmt(eventAlert.DateTime) + ".jpeg"
 		data, _ := ioutil.ReadAll(part)
 		if strings.Contains(eventAlert.ChannelName, "plateNumber") {
-			//todo 识别车牌,记录次数
+			// 识别车牌,记录次数
 			number, err := CallLicensePlateRecognitionAPI(data)
 			if err != nil {
 				fmt.Println("车牌识别失败:", err)
@@ -126,7 +135,7 @@ func handleMultipart(r *http.Request) {
 			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)
@@ -137,8 +146,9 @@ func handleMultipart(r *http.Request) {
 			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)
+			//dateTime := eventAlert.DateTime
+			//bulk[dateTime] = append(bulk[dateTime], rh, rl)
+			LhChan <- [2]float64{rl, rh}
 			return
 		}
 		if strings.Contains(eventAlert.ChannelName, "metering2") {
@@ -151,16 +161,17 @@ func handleMultipart(r *http.Request) {
 			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 {
-				fmt.Println("车牌识别失败:", err)
-				//time.Sleep(1000)
-			}
-			//todo 处理车牌号
-			carInfoService.ProcessPlateNumber(number)
+			WChan <- rw
+			//dateTime := eventAlert.DateTime
+			//bulk[dateTime] = append(bulk[dateTime], rw)
+			//// 识别车牌,记录次数
+			//number, err := CallLicensePlateRecognitionAPI(data)
+			//if err != nil {
+			//	fmt.Println("车牌识别失败:", err)
+			//	//time.Sleep(1000)
+			//}
+			//// 处理车牌号
+			//carInfoService.ProcessPlateNumber(number)
 			return
 		}
 		f := &mail.File{

+ 10 - 6
go.mod

@@ -11,10 +11,13 @@ require (
 	github.com/go-sql-driver/mysql v1.7.1
 	github.com/gofrs/uuid/v5 v5.0.0
 	github.com/golang-jwt/jwt/v4 v4.5.0
+	github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f
 	github.com/mojocn/base64Captcha v1.3.5
 	github.com/redis/go-redis/v9 v9.2.1
 	github.com/sirupsen/logrus v1.9.3
 	github.com/songzhibin97/gkit v1.2.11
+	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.782
+	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.780
 	github.com/unrolled/secure v1.13.0
 	github.com/xhit/go-simple-mail/v2 v2.16.0
 	go.uber.org/zap v1.26.0
@@ -26,14 +29,15 @@ require (
 )
 
 require (
-	github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f // indirect
+	github.com/bytedance/sonic v1.9.1 // indirect
+	github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
+	github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
+	github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
+	github.com/jonboulle/clockwork v0.4.0 // indirect
+	github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 // indirect
 	github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
-	github.com/tencentcloud/tencentcloud-sdk-go v1.0.782 // indirect
-	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.782 // indirect
-	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.782 // indirect
-	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.780 // indirect
-	gocv.io/x/gocv v0.35.0 // indirect
+	github.com/tebeka/strftime v0.1.5 // indirect
 )
 
 require (

+ 10 - 18
go.sum

@@ -82,6 +82,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
 github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
 github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 h1:Ghm4eQYC0nEPnSJdVkTrXpu9KtoVCSo1hg7mtI7G9KU=
+github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw=
 github.com/flipped-aurora/gin-vue-admin/server v0.0.0-20231014055930-232aaad09094 h1:uqUWj6saMMAMvuy/CJK1NcfENMXjan/kQbvrEvLw+4c=
 github.com/flipped-aurora/gin-vue-admin/server v0.0.0-20231014055930-232aaad09094/go.mod h1:rXcid1oL4HO8NpnK0FDKxxZiz9Jry9yc2+y2vwzUa9o=
 github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
@@ -204,7 +206,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
 github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
-github.com/hybridgroup/mjpeg v0.0.0-20140228234708-4680f319790e/go.mod h1:eagM805MRKrioHYuU7iKLUyFPVKqVV6um5DAvCkUtXs=
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
@@ -219,11 +220,15 @@ github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nD
 github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
 github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
 github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
+github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
+github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
 github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
+github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
+github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
 github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
@@ -244,6 +249,8 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
 github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
 github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
 github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
+github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 h1:0iQektZGS248WXmGIYOwRXSQhD4qn3icjMpuxwO7qlo=
+github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570/go.mod h1:BLt8L9ld7wVsvEWQbuLrUZnCMnUmLZ+CGDzKtclrTlE=
 github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f h1:sgUSP4zdTUZYZgAGGtN5Lxk92rK+JUFOwf+FT99EEI4=
 github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8=
 github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 h1:Bvq8AziQ5jFF4BHGAEDSqwPW1NJS3XshxbRCxtjFAZc=
@@ -271,7 +278,6 @@ github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt
 github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
 github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
 github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
-github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
 github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
 github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
@@ -324,23 +330,11 @@ github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
 github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
-github.com/tencentcloud/tencentcloud-sdk-go v1.0.780 h1:Fqg1bt8jbUhu4cJ3wSvJoENd1vpLj7pIGkfUdEScoh0=
-github.com/tencentcloud/tencentcloud-sdk-go v1.0.780/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
-github.com/tencentcloud/tencentcloud-sdk-go v1.0.781 h1:pMIp/w7JZdz8kxrFjqbZCA83xQeyOe+okJSzaqm0kQg=
-github.com/tencentcloud/tencentcloud-sdk-go v1.0.781/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
-github.com/tencentcloud/tencentcloud-sdk-go v1.0.782 h1:3CH0kg/M+UbB0FPozvFcfTHNC+zLZlkai0UiCGPWYJ4=
-github.com/tencentcloud/tencentcloud-sdk-go v1.0.782/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
+github.com/tebeka/strftime v0.1.5 h1:1NQKN1NiQgkqd/2moD6ySP/5CoZQsKa1d3ZhJ44Jpmg=
+github.com/tebeka/strftime v0.1.5/go.mod h1:29/OidkoWHdEKZqzyDLUyC+LmgDgdHo4WAFCDT7D/Ig=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.780/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.781 h1:ZLcrm4Mp3pWZnlHh61oKx4LrNeZ6Dmdu4RxWMloULJw=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.781/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.782 h1:du/bh8RvkLIHjpmpXtOT0lhwhPUdiobmxr32Sv6xAtA=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.782/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.780 h1:TH1Yue6/avkQylkzbNf4qsyYdnxxZ6u88wC9l7HJqMo=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.780/go.mod h1:zivJtasCyOpsjkLG45LPZfVZCMT3qzQNJ+yL/FPK/S8=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.781 h1:t3meBdyVJhuU7MKTtcz3qAbvjcfuCjcbmMa4af4IjlM=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.781/go.mod h1:P3kN49ZZCl/CiYUzyW9XU9e7EoWlSeZvtE1mMhLn7OA=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.782 h1:KWOG2mTArNdoBhc8Y17lKTe6cjiXCDp2Bj+teyvJic0=
-github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.782/go.mod h1:ZIjKSDw6BqRyUOnIr+Wwzr8NXIppxcdUJM2hwhw+CtA=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.780 h1:hiH/tc3y1p4hIWNJdvxzZBBSjh07PLj6GjHRS/u4rD0=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.780/go.mod h1:E5tmeQ3bIO+spB5Rdgw8pcD/ZR7WqslfOAyzA1J5XLs=
 github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
@@ -389,8 +383,6 @@ go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
 go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
 go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
 go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
-gocv.io/x/gocv v0.35.0 h1:Qaxb5KdVyy8Spl4S4K0SMZ6CVmKtbfoSGQAxRD3FZlw=
-gocv.io/x/gocv v0.35.0/go.mod h1:oc6FvfYqfBp99p+yOEzs9tbYF9gOrAQSeL/dyIPefJU=
 golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
 golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
 golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=