From 0b932b8af021e1f97a27c85d823f828fbf854a39 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 06 六月 2024 16:20:13 +0800 Subject: [PATCH] 完善人脸照片图片切图 --- repository/captureRepo.go | 23 +++++++++-------------- 1 files changed, 9 insertions(+), 14 deletions(-) diff --git a/repository/captureRepo.go b/repository/captureRepo.go index 80fb1e8..559a6b7 100644 --- a/repository/captureRepo.go +++ b/repository/captureRepo.go @@ -3,12 +3,12 @@ import ( "encoding/base64" "encoding/json" - "gat1400Exchange/pkg" "time" "gat1400Exchange/client" "gat1400Exchange/config" "gat1400Exchange/models" + "gat1400Exchange/pkg" "gat1400Exchange/pkg/logger" "gat1400Exchange/util" "gat1400Exchange/vo" @@ -37,7 +37,6 @@ var deviceId = face.DeviceID var faceId = face.FaceID var bgImageStr string - var bgImageWidth, bgImageHeight int var bgImageBytes, faceImageBytes []byte = nil, nil // 鑾峰彇澶у浘, 鐩墠娴峰悍鐨勫皬鍥惧垎杈ㄧ巼澶綆 @@ -46,8 +45,6 @@ continue } - bgImageWidth = image.Width - bgImageHeight = image.Height if len(image.Data) > 0 { if len(image.Data) > len(bgImageStr) { bgImageStr = image.Data @@ -72,17 +69,15 @@ } // 鍒ゆ柇鍥剧墖绫诲瀷鏄惁涓哄満鏅浘, 鏍规嵁浜鸿劯鍧愭爣鍒囧皬鍥�. - if config.ImageConf.CutFaceImage { - scaleX := float64(bgImageWidth) / config.ImageConf.OriginWidth - scaleY := float64(bgImageHeight) / config.ImageConf.OriginHeight - faceRect := &vo.Rect{ - Left: int(float64(face.LeftTopX) * scaleX), - Top: int(float64(face.LeftTopY) * scaleY), - Right: int(float64(face.RightBtmX) * scaleX), - Bottom: int(float64(face.RightBtmY) * scaleY), + if config.ImageConf.CutFaceImage && face.LeftTopX != 0 { + faceRect := &pkg.Rect{ + Left: face.LeftTopX, + Top: face.LeftTopY, + Right: face.RightBtmX, + Bottom: face.RightBtmY, } - faceImageBytes, err = util.SubCutImg(bgImageBytes, faceRect, 90) + faceImageBytes, err = pkg.SubCutImage(bgImageBytes, faceRect, config.ImageConf.Enlarge) if err != nil { logger.Warn("Cut face image failure, %s", err.Error()) } @@ -118,7 +113,7 @@ c.CacheData(cacheItem, "basic") logger.Warn("The data forwarding failed, adding to local cache.") } else { - logger.Debug("The data forwarding successful. deviceId:%s", deviceId) + logger.Debug("The data forwarding successful. deviceId:%s, picId:", deviceId, face.FaceID) } } } -- Gitblit v1.8.0