Skip to content

Commit da6055b

Browse files
committed
Merge branch 'dev-imagetargetrec' into 'master' (merge request !122)
支持上传时和云上图⽚⼈⻋通⽤识别功能
2 parents 9a785eb + 9c43251 commit da6055b

File tree

2 files changed

+156
-3
lines changed

2 files changed

+156
-3
lines changed

ci.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ func EncodePicOperations(pic *PicOperations) string {
4040
}
4141

4242
type ImageProcessResult struct {
43-
XMLName xml.Name `xml:"UploadResult"`
44-
OriginalInfo *PicOriginalInfo `xml:"OriginalInfo,omitempty"`
45-
ProcessResults []PicProcessObject `xml:"ProcessResults>Object,omitempty"`
43+
XMLName xml.Name `xml:"UploadResult"`
44+
OriginalInfo *PicOriginalInfo `xml:"OriginalInfo,omitempty"`
45+
ProcessResults []PicProcessObject `xml:"ProcessResults>Object,omitempty"`
46+
ImgTargetRecResult *ImgTargetRecResult `xml:"ImgTargetRecResult,omitempty"`
4647
// 历史兼容考虑不建议抽象单独struct防止客户使用影响
4748
ProcessResultsText string `xml:"ProcessResults>Text,omitempty"`
4849
ProcessResultsWatermarkStatusCode int `xml:"ProcessResults>WatermarkStatusCode,omitempty"`
@@ -73,6 +74,9 @@ type PicProcessObject struct {
7374
WatermarkStatus int `xml:"WatermarkStatus,omitempty"`
7475
CodeStatus int `xml:"CodeStatus,omitempty"`
7576
QRcodeInfo []QRcodeInfo `xml:"QRcodeInfo,omitempty"`
77+
FrameCount int `xml:"FrameCount,omitempty"`
78+
Md5 string `xml:"Md5,omitempty"`
79+
BitDepth int `xml:"BitDepth,omitempty"`
7680
}
7781
type QRcodeInfo struct {
7882
CodeUrl string `xml:"CodeUrl,omitempty"`
@@ -2828,3 +2832,38 @@ func (s *CIService) DescribeCIBuckets(ctx context.Context, opt *DescribeCIBucket
28282832
resp, err := s.client.send(ctx, sendOpt)
28292833
return &res, resp, err
28302834
}
2835+
2836+
type ImgTargetRecResult struct {
2837+
BodyDetailInfos struct {
2838+
BodyDetailInfo []struct {
2839+
X string `xml:"X"`
2840+
Y string `xml:"Y"`
2841+
Width string `xml:"Width"`
2842+
Height string `xml:"Height"`
2843+
} `xml:"BodyDetailInfo"`
2844+
} `xml:"BodyDetailInfos"`
2845+
CarDetailInfos struct {
2846+
CarDetailInfo []struct {
2847+
X string `xml:"X"`
2848+
Y string `xml:"Y"`
2849+
Width string `xml:"Width"`
2850+
Height string `xml:"Height"`
2851+
} `xml:"CarDetailInfo"`
2852+
} `xml:"CarDetailInfos"`
2853+
FaceDetailInfos struct {
2854+
FaceDetailInfo []struct {
2855+
X string `xml:"X"`
2856+
Y string `xml:"Y"`
2857+
Width string `xml:"Width"`
2858+
Height string `xml:"Height"`
2859+
} `xml:"FaceDetailInfo"`
2860+
} `xml:"FaceDetailInfos"`
2861+
PlateDetailInfos struct {
2862+
PlateDetailInfo []struct {
2863+
X string `xml:"X"`
2864+
Y string `xml:"Y"`
2865+
Width string `xml:"Width"`
2866+
Height string `xml:"Height"`
2867+
} `xml:"PlateDetailInfo"`
2868+
} `xml:"PlateDetailInfos"`
2869+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/url"
8+
"os"
9+
10+
"github.com/tencentyun/cos-go-sdk-v5"
11+
"github.com/tencentyun/cos-go-sdk-v5/debug"
12+
)
13+
14+
func log_status(err error) {
15+
if err == nil {
16+
return
17+
}
18+
if cos.IsNotFoundError(err) {
19+
// WARN
20+
fmt.Println("WARN: Resource is not existed")
21+
} else if e, ok := cos.IsCOSError(err); ok {
22+
fmt.Printf("ERROR: Code: %v\n", e.Code)
23+
fmt.Printf("ERROR: Message: %v\n", e.Message)
24+
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
25+
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
26+
// ERROR
27+
} else {
28+
fmt.Printf("ERROR: %v\n", err)
29+
// ERROR
30+
}
31+
}
32+
33+
// 图⽚⼈⻋通⽤识别功能(上传时)
34+
func imageTargetRecWhenUpload() {
35+
u, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com")
36+
b := &cos.BaseURL{BucketURL: u}
37+
c := cos.NewClient(b, &http.Client{
38+
Transport: &cos.AuthorizationTransport{
39+
SecretID: os.Getenv("COS_SECRETID"),
40+
SecretKey: os.Getenv("COS_SECRETKEY"),
41+
Transport: &debug.DebugRequestTransport{
42+
RequestHeader: true,
43+
RequestBody: false,
44+
ResponseHeader: true,
45+
ResponseBody: true,
46+
},
47+
},
48+
})
49+
50+
opt := &cos.ObjectPutOptions{
51+
ACLHeaderOptions: nil,
52+
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
53+
XOptionHeader: &http.Header{},
54+
},
55+
}
56+
pic := &cos.PicOperations{
57+
IsPicInfo: 1,
58+
Rules: []cos.PicOperationsRules{
59+
{
60+
FileId: "/pic/out.jpeg",
61+
Rule: "ci-process=ImageTargetRec&detect-type=car,face,plate,body&cover=1",
62+
},
63+
},
64+
}
65+
opt.XOptionHeader.Add("Pic-Operations", cos.EncodePicOperations(pic))
66+
name := "pic/cup.png"
67+
local_filename := "./test_output_02_000.jpg"
68+
res, _, err := c.CI.PutFromFile(context.Background(), name, local_filename, opt)
69+
log_status(err)
70+
fmt.Printf("%+v\n", res)
71+
fmt.Printf("%+v\n", res.OriginalInfo)
72+
fmt.Printf("%+v\n", res.ProcessResults)
73+
fmt.Printf("%+v\n", res.ImgTargetRecResult)
74+
}
75+
76+
// 图⽚⼈⻋通⽤识别功能(云上数据处理)
77+
func imageTargetRecWhenCloud() {
78+
u, _ := url.Parse("https://test-1234567890.ci.ap-chongqing.myqcloud.com")
79+
b := &cos.BaseURL{BucketURL: u}
80+
c := cos.NewClient(b, &http.Client{
81+
Transport: &cos.AuthorizationTransport{
82+
SecretID: os.Getenv("COS_SECRETID"),
83+
SecretKey: os.Getenv("COS_SECRETKEY"),
84+
Transport: &debug.DebugRequestTransport{
85+
RequestHeader: true,
86+
// Notice when put a large file and set need the request body, might happend out of memory error.
87+
RequestBody: false,
88+
ResponseHeader: true,
89+
ResponseBody: true,
90+
},
91+
},
92+
})
93+
94+
pic := &cos.PicOperations{
95+
IsPicInfo: 1,
96+
Rules: []cos.PicOperationsRules{
97+
{
98+
FileId: "/pic/cup_out.jpeg",
99+
Rule: "ci-process=ImageTargetRec&detect-type=car,face,plate,body&cover=1",
100+
},
101+
},
102+
}
103+
104+
key := "pic/cup.png"
105+
res, _, err := c.CI.ImageProcess(context.Background(), key, pic)
106+
log_status(err)
107+
fmt.Printf("%+v\n", res)
108+
fmt.Printf("%+v\n", res.ImgTargetRecResult)
109+
}
110+
111+
func main() {
112+
// imageTargetRecWhenUpload()
113+
imageTargetRecWhenCloud()
114+
}

0 commit comments

Comments
 (0)