diff --git a/ci.go b/ci.go index d72e145..24b79d4 100644 --- a/ci.go +++ b/ci.go @@ -40,9 +40,10 @@ func EncodePicOperations(pic *PicOperations) string { } type ImageProcessResult struct { - XMLName xml.Name `xml:"UploadResult"` - OriginalInfo *PicOriginalInfo `xml:"OriginalInfo,omitempty"` - ProcessResults []PicProcessObject `xml:"ProcessResults>Object,omitempty"` + XMLName xml.Name `xml:"UploadResult"` + OriginalInfo *PicOriginalInfo `xml:"OriginalInfo,omitempty"` + ProcessResults []PicProcessObject `xml:"ProcessResults>Object,omitempty"` + ImgTargetRecResult *ImgTargetRecResult `xml:"ImgTargetRecResult,omitempty"` // 历史兼容考虑不建议抽象单独struct防止客户使用影响 ProcessResultsText string `xml:"ProcessResults>Text,omitempty"` ProcessResultsWatermarkStatusCode int `xml:"ProcessResults>WatermarkStatusCode,omitempty"` @@ -73,6 +74,9 @@ type PicProcessObject struct { WatermarkStatus int `xml:"WatermarkStatus,omitempty"` CodeStatus int `xml:"CodeStatus,omitempty"` QRcodeInfo []QRcodeInfo `xml:"QRcodeInfo,omitempty"` + FrameCount int `xml:"FrameCount,omitempty"` + Md5 string `xml:"Md5,omitempty"` + BitDepth int `xml:"BitDepth,omitempty"` } type QRcodeInfo struct { CodeUrl string `xml:"CodeUrl,omitempty"` @@ -2828,3 +2832,38 @@ func (s *CIService) DescribeCIBuckets(ctx context.Context, opt *DescribeCIBucket resp, err := s.client.send(ctx, sendOpt) return &res, resp, err } + +type ImgTargetRecResult struct { + BodyDetailInfos struct { + BodyDetailInfo []struct { + X string `xml:"X"` + Y string `xml:"Y"` + Width string `xml:"Width"` + Height string `xml:"Height"` + } `xml:"BodyDetailInfo"` + } `xml:"BodyDetailInfos"` + CarDetailInfos struct { + CarDetailInfo []struct { + X string `xml:"X"` + Y string `xml:"Y"` + Width string `xml:"Width"` + Height string `xml:"Height"` + } `xml:"CarDetailInfo"` + } `xml:"CarDetailInfos"` + FaceDetailInfos struct { + FaceDetailInfo []struct { + X string `xml:"X"` + Y string `xml:"Y"` + Width string `xml:"Width"` + Height string `xml:"Height"` + } `xml:"FaceDetailInfo"` + } `xml:"FaceDetailInfos"` + PlateDetailInfos struct { + PlateDetailInfo []struct { + X string `xml:"X"` + Y string `xml:"Y"` + Width string `xml:"Width"` + Height string `xml:"Height"` + } `xml:"PlateDetailInfo"` + } `xml:"PlateDetailInfos"` +} diff --git a/example/CI/ai_recognition/image_target_rec.go b/example/CI/ai_recognition/image_target_rec.go new file mode 100644 index 0000000..6ce9f02 --- /dev/null +++ b/example/CI/ai_recognition/image_target_rec.go @@ -0,0 +1,114 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "net/url" + "os" + + "github.com/tencentyun/cos-go-sdk-v5" + "github.com/tencentyun/cos-go-sdk-v5/debug" +) + +func log_status(err error) { + if err == nil { + return + } + if cos.IsNotFoundError(err) { + // WARN + fmt.Println("WARN: Resource is not existed") + } else if e, ok := cos.IsCOSError(err); ok { + fmt.Printf("ERROR: Code: %v\n", e.Code) + fmt.Printf("ERROR: Message: %v\n", e.Message) + fmt.Printf("ERROR: Resource: %v\n", e.Resource) + fmt.Printf("ERROR: RequestId: %v\n", e.RequestID) + // ERROR + } else { + fmt.Printf("ERROR: %v\n", err) + // ERROR + } +} + +// 图⽚⼈⻋通⽤识别功能(上传时) +func imageTargetRecWhenUpload() { + u, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com") + b := &cos.BaseURL{BucketURL: u} + c := cos.NewClient(b, &http.Client{ + Transport: &cos.AuthorizationTransport{ + SecretID: os.Getenv("COS_SECRETID"), + SecretKey: os.Getenv("COS_SECRETKEY"), + Transport: &debug.DebugRequestTransport{ + RequestHeader: true, + RequestBody: false, + ResponseHeader: true, + ResponseBody: true, + }, + }, + }) + + opt := &cos.ObjectPutOptions{ + ACLHeaderOptions: nil, + ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{ + XOptionHeader: &http.Header{}, + }, + } + pic := &cos.PicOperations{ + IsPicInfo: 1, + Rules: []cos.PicOperationsRules{ + { + FileId: "/pic/out.jpeg", + Rule: "ci-process=ImageTargetRec&detect-type=car,face,plate,body&cover=1", + }, + }, + } + opt.XOptionHeader.Add("Pic-Operations", cos.EncodePicOperations(pic)) + name := "pic/cup.png" + local_filename := "./test_output_02_000.jpg" + res, _, err := c.CI.PutFromFile(context.Background(), name, local_filename, opt) + log_status(err) + fmt.Printf("%+v\n", res) + fmt.Printf("%+v\n", res.OriginalInfo) + fmt.Printf("%+v\n", res.ProcessResults) + fmt.Printf("%+v\n", res.ImgTargetRecResult) +} + +// 图⽚⼈⻋通⽤识别功能(云上数据处理) +func imageTargetRecWhenCloud() { + u, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com") + b := &cos.BaseURL{BucketURL: u} + c := cos.NewClient(b, &http.Client{ + Transport: &cos.AuthorizationTransport{ + SecretID: os.Getenv("COS_SECRETID"), + SecretKey: os.Getenv("COS_SECRETKEY"), + Transport: &debug.DebugRequestTransport{ + RequestHeader: true, + // Notice when put a large file and set need the request body, might happend out of memory error. + RequestBody: false, + ResponseHeader: true, + ResponseBody: true, + }, + }, + }) + + pic := &cos.PicOperations{ + IsPicInfo: 1, + Rules: []cos.PicOperationsRules{ + { + FileId: "/pic/cup_out.jpeg", + Rule: "ci-process=ImageTargetRec&detect-type=car,face,plate,body&cover=1", + }, + }, + } + + key := "pic/cup.png" + res, _, err := c.CI.ImageProcess(context.Background(), key, pic) + log_status(err) + fmt.Printf("%+v\n", res) + fmt.Printf("%+v\n", res.ImgTargetRecResult) +} + +func main() { + // imageTargetRecWhenUpload() + imageTargetRecWhenCloud() +} diff --git a/object.go b/object.go index c225f60..4c8ba2c 100644 --- a/object.go +++ b/object.go @@ -32,6 +32,7 @@ type ObjectGetOptions struct { ResponseCacheControl string `url:"response-cache-control,omitempty" header:"-"` ResponseContentDisposition string `url:"response-content-disposition,omitempty" header:"-"` ResponseContentEncoding string `url:"response-content-encoding,omitempty" header:"-"` + CiProcess string `url:"ci-process,omitempty" header:"-"` Range string `url:"-" header:"Range,omitempty"` IfModifiedSince string `url:"-" header:"If-Modified-Since,omitempty"` // SSE-C