Skip to content

Commit 0d8107c

Browse files
author
lilang
committed
CI17
1 parent 6c34926 commit 0d8107c

File tree

4 files changed

+259
-6
lines changed

4 files changed

+259
-6
lines changed

ci_media.go

Lines changed: 140 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ type Subtitles struct {
448448

449449
// Subtitle TODO
450450
type Subtitle struct {
451-
Url []Subtitle `xml:"Url,omitempty"`
451+
Url string `xml:"Url,omitempty"`
452+
Embed string `xml:"Embed,omitempty"`
453+
FontType string `xml:"FontType,omitempty"`
454+
FontSize string `xml:"FontSize,omitempty"`
455+
FontColor string `xml:"FontColor,omitempty"`
456+
OutlineColor string `xml:"OutlineColor,omitempty"`
457+
VMargin string `xml:"VMargin,omitempty"`
452458
}
453459

454460
// VideoTag TODO
@@ -753,6 +759,9 @@ type MediaProcessJobOperation struct {
753759
VocalScoreResult *VocalScoreResult `xml:"VocalScoreResult,omitempty"`
754760
ImageInspect *ImageInspect `xml:"ImageInspect,omitempty"`
755761
ImageInspectResult *ImageInspectResult `xml:"ImageInspectResult,omitempty"`
762+
SnapshotPrefix string `xml:"SnapshotPrefix,omitempty"`
763+
ImageOCR *ImageOCRTemplate `xml:"ImageOCR,omitempty"`
764+
Detection *ImageOCRDetection `xml:"Detection,omitempty"`
756765
}
757766

758767
// CreatePicJobsOptions TODO
@@ -887,11 +896,12 @@ type WorkflowExecutionNotifyBody struct {
887896
ObjectCount int `xml:"ObjectCount"`
888897
SpriteObjectCount int `xml:"SpriteObjectCount"`
889898
ObjectInfo []struct {
890-
ObjectName string `xml:"ObjectName"`
891-
ObjectUrl string `xml:"ObjectUrl"`
892-
InputObjectName string `xml:"InputObjectName"`
893-
Code string `xml:"Code"`
894-
Message string `xml:"Message"`
899+
ObjectName string `xml:"ObjectName"`
900+
ObjectUrl string `xml:"ObjectUrl"`
901+
InputObjectName string `xml:"InputObjectName"`
902+
Code string `xml:"Code"`
903+
Message string `xml:"Message"`
904+
ImageOcrResult *ImageOCRDetection `xml:"ImageOcrResult,omitempty"`
895905
} `xml:"ObjectInfo,omitempty"`
896906
SpriteObjectInfo []struct {
897907
ObjectName string `xml:"ObjectName"`
@@ -1731,6 +1741,9 @@ type NodeOperation struct {
17311741
Condition *WorkflowNodeCondition `xml:"Condition,omitempty" json:"Condition,omitempty"`
17321742
SegmentVideoBody *SegmentVideoBody `xml:"SegmentVideoBody,omitempty" json:"SegmentVideoBody,omitempty"`
17331743
ImageInspect *ImageInspect `xml:"ImageInspect,omitempty" json:"ImageInspect,omitempty"`
1744+
TranscodeConfig *struct {
1745+
FreeTranscode string `xml:"FreeTranscode,omitempty" json:"FreeTranscode,omitempty"`
1746+
} `xml:"TranscodeConfig,omitempty" json:"TranscodeConfig,omitempty"`
17341747
}
17351748

17361749
// Node TODO
@@ -2327,6 +2340,7 @@ type Template struct {
23272340
NoiseReduction *NoiseReduction `xml:"NoiseReduction,omitempty" json:"NoiseReduction,omitempty"`
23282341
VideoEnhance *VideoEnhance `xml:"VideoEnhance,omitempty" json:"VideoEnhance,omitempty"`
23292342
VideoTargetRec *VideoTargetRec `xml:"VideoTargetRec,omitempty" json:"VideoTargetRec,omitempty"`
2343+
ImageOCR *ImageOCRTemplate `xml:"ImageOCR,omitempty" json:"ImageOCR,omitempty"`
23302344
}
23312345

23322346
// CreateMediaSnapshotTemplate 创建截图模板
@@ -3072,6 +3086,7 @@ type InventoryTriggerJobOperation struct {
30723086
Tag string `xml:"Tag,omitempty"`
30733087
JobParam *InventoryTriggerJobOperationJobParam `xml:"JobParam,omitempty"`
30743088
Output *JobOutput `xml:"Output,omitempty"`
3089+
FreeTranscode string `xml:"FreeTranscode,omitempty"`
30753090
}
30763091

30773092
// InventoryTriggerJobOperationJobParam TODO
@@ -3110,6 +3125,8 @@ type InventoryTriggerJobOperationJobParam struct {
31103125
VocalScoreResult *VocalScoreResult `xml:"VocalScoreResult,omitempty"`
31113126
ImageInspect *ImageInspect `xml:"ImageInspect,omitempty"`
31123127
ImageInspectResult *ImageInspectResult `xml:"ImageInspectResult,omitempty"`
3128+
ImageOCR *ImageOCRTemplate `xml:"ImageOCR,omitempty"`
3129+
Detection *ImageOCRDetection `xml:"Detection,omitempty"`
31133130
}
31143131

31153132
// InventoryTriggerJob TODO
@@ -3711,3 +3728,120 @@ func (s *CIService) CosImageInspect(ctx context.Context, name string, opt *CosIm
37113728
resp, err := s.client.send(ctx, &sendOpt)
37123729
return &res, resp, err
37133730
}
3731+
3732+
// CreateOCRTemplateOptions TODO
3733+
type CreateOCRTemplateOptions struct {
3734+
XMLName xml.Name `xml:"Request"`
3735+
Tag string `xml:"Tag,omitempty"`
3736+
Name string `xml:"Name,omitempty"`
3737+
ImageOCR *ImageOCRTemplate `xml:"ImageOCR,omitempty" json:"ImageOCR,omitempty"`
3738+
}
3739+
3740+
// ImageOCRTemplate TODO
3741+
type ImageOCRTemplate struct {
3742+
Type string `xml:"Type,omitempty"`
3743+
LanguageType string `xml:"LanguageType,omitempty"`
3744+
IsPdf string `xml:"IsPdf,omitempty"`
3745+
PdfPageNumber string `xml:"PdfPageNumber,omitempty"`
3746+
IsWord string `xml:"IsWord,omitempty"`
3747+
EnableWordPolygon string `xml:"EnableWordPolygon,omitempty"`
3748+
}
3749+
3750+
// CreateOCRTemplate 创建OCR模板
3751+
func (s *CIService) CreateOCRTemplate(ctx context.Context, opt *CreateOCRTemplateOptions) (*CreateMediaTemplateResult, *Response, error) {
3752+
var res CreateMediaTemplateResult
3753+
sendOpt := sendOptions{
3754+
baseURL: s.client.BaseURL.CIURL,
3755+
uri: "/template",
3756+
method: http.MethodPost,
3757+
body: opt,
3758+
result: &res,
3759+
}
3760+
resp, err := s.client.send(ctx, &sendOpt)
3761+
return &res, resp, err
3762+
}
3763+
3764+
// UpdateOCRTemplate 更新OCR模板
3765+
func (s *CIService) UpdateOCRTemplate(ctx context.Context, opt *CreateOCRTemplateOptions, templateId string) (*CreateMediaTemplateResult, *Response, error) {
3766+
var res CreateMediaTemplateResult
3767+
sendOpt := sendOptions{
3768+
baseURL: s.client.BaseURL.CIURL,
3769+
uri: "/template/" + templateId,
3770+
method: http.MethodPut,
3771+
body: opt,
3772+
result: &res,
3773+
}
3774+
resp, err := s.client.send(ctx, &sendOpt)
3775+
return &res, resp, err
3776+
}
3777+
3778+
// ImageOCRDetection TODO
3779+
type ImageOCRDetection struct {
3780+
InputObjectName string `xml:"InputObjectName,omitempty"`
3781+
InputObjectUrl string `xml:"InputObjectUrl,omitempty"`
3782+
ObjectName string `xml:"ObjectName,omitempty"`
3783+
ObjectUrl string `xml:"ObjectUrl,omitempty"`
3784+
Code string `xml:"Code,omitempty"`
3785+
State string `xml:"State,omitempty"`
3786+
Message string `xml:"Message,omitempty"`
3787+
TextDetections []ImageOCRTextDetections `xml:"TextDetections,omitempty"`
3788+
Language string `xml:"Language,omitempty"`
3789+
Angel string `xml:"Angel,omitempty"`
3790+
PdfPageSize int `xml:"PdfPageSize,omitempty"`
3791+
}
3792+
3793+
// ImageOCRTextDetections TODO
3794+
type ImageOCRTextDetections struct {
3795+
DetectedText string `xml:"DetectedText,omitempty"`
3796+
Confidence int `xml:"Confidence,omitempty"`
3797+
Polygon []ImageOCRTextPolygon `xml:"Polygon,omitempty"`
3798+
ItemPolygon []ImageOCRTextItemPolygon `xml:"ItemPolygon,omitempty"`
3799+
Words []ImageOCRTextWords `xml:"Words,omitempty"`
3800+
WordPolygon []ImageOCRTextWordPolygon `xml:"WordPolygon,omitempty"`
3801+
}
3802+
3803+
// ImageOCRTextPolygon TODO
3804+
type ImageOCRTextPolygon struct {
3805+
X int `xml:"X,omitempty"`
3806+
Y int `xml:"Y,omitempty"`
3807+
}
3808+
3809+
// ImageOCRTextItemPolygon TODO
3810+
type ImageOCRTextItemPolygon struct {
3811+
X int `xml:"X,omitempty"`
3812+
Y int `xml:"Y,omitempty"`
3813+
Width int `xml:"Width,omitempty"`
3814+
Height int `xml:"Height,omitempty"`
3815+
}
3816+
3817+
// ImageOCRTextWords TODO
3818+
type ImageOCRTextWords struct {
3819+
Confidence int `xml:"Confidence,omitempty"`
3820+
Character string `xml:"Character,omitempty"`
3821+
WordCoordPoint []struct {
3822+
WordCoordinate []struct {
3823+
X int `xml:"X,omitempty"`
3824+
Y int `xml:"Y,omitempty"`
3825+
} `xml:"WordCoordinate,omitempty"`
3826+
} `xml:"WordCoordPoint,omitempty"`
3827+
}
3828+
3829+
// ImageOCRTextWordPolygon TODO
3830+
type ImageOCRTextWordPolygon struct {
3831+
LeftTop []struct {
3832+
X int `xml:"X,omitempty"`
3833+
Y int `xml:"Y,omitempty"`
3834+
} `xml:"LeftTop,omitempty"`
3835+
RightTop []struct {
3836+
X int `xml:"X,omitempty"`
3837+
Y int `xml:"Y,omitempty"`
3838+
} `xml:"RightTop,omitempty"`
3839+
LeftBottom []struct {
3840+
X int `xml:"X,omitempty"`
3841+
Y int `xml:"Y,omitempty"`
3842+
} `xml:"LeftBottom,omitempty"`
3843+
RightBottom []struct {
3844+
X int `xml:"X,omitempty"`
3845+
Y int `xml:"Y,omitempty"`
3846+
} `xml:"RightBottom,omitempty"`
3847+
}

ci_media_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,3 +3409,64 @@ func TestCIService_CosImageInspect(t *testing.T) {
34093409
t.Fatalf("CI.CosImageInspect returned error: %v", err)
34103410
}
34113411
}
3412+
3413+
func TestCIService_CreateOCRTemplate(t *testing.T) {
3414+
setup()
3415+
defer teardown()
3416+
3417+
wantBody := "<Request><Tag>ImageOCR</Tag><Name>ImageOCR-123</Name><ImageOCR><Type>general</Type><LanguageType>zh</LanguageType><IsPdf>false" +
3418+
"</IsPdf><IsWord>true</IsWord><EnableWordPolygon>true</EnableWordPolygon></ImageOCR></Request>"
3419+
3420+
mux.HandleFunc("/template", func(w http.ResponseWriter, r *http.Request) {
3421+
testMethod(t, r, http.MethodPost)
3422+
testBody(t, r, wantBody)
3423+
})
3424+
3425+
opt := &CreateOCRTemplateOptions{
3426+
Tag: "ImageOCR",
3427+
Name: "ImageOCR-123",
3428+
ImageOCR: &ImageOCRTemplate{
3429+
Type: "general",
3430+
LanguageType: "zh",
3431+
IsPdf: "false",
3432+
IsWord: "true",
3433+
EnableWordPolygon: "true",
3434+
},
3435+
}
3436+
3437+
_, _, err := client.CI.CreateOCRTemplate(context.Background(), opt)
3438+
if err != nil {
3439+
t.Fatalf("CI.CreateOCRTemplate returned error: %v", err)
3440+
}
3441+
}
3442+
3443+
func TestCIService_UpdateOCRTemplate(t *testing.T) {
3444+
setup()
3445+
defer teardown()
3446+
3447+
tplId := "t1460606b9752148c4ab182f55163ba7cd"
3448+
wantBody := "<Request><Tag>ImageOCR</Tag><Name>ImageOCR-123</Name><ImageOCR><Type>efficient</Type><LanguageType>zh</LanguageType><IsPdf>false" +
3449+
"</IsPdf><IsWord>true</IsWord><EnableWordPolygon>true</EnableWordPolygon></ImageOCR></Request>"
3450+
3451+
mux.HandleFunc("/template/"+tplId, func(w http.ResponseWriter, r *http.Request) {
3452+
testMethod(t, r, http.MethodPut)
3453+
testBody(t, r, wantBody)
3454+
})
3455+
3456+
opt := &CreateOCRTemplateOptions{
3457+
Tag: "ImageOCR",
3458+
Name: "ImageOCR-123",
3459+
ImageOCR: &ImageOCRTemplate{
3460+
Type: "efficient",
3461+
LanguageType: "zh",
3462+
IsPdf: "false",
3463+
IsWord: "true",
3464+
EnableWordPolygon: "true",
3465+
},
3466+
}
3467+
3468+
_, _, err := client.CI.UpdateOCRTemplate(context.Background(), opt, tplId)
3469+
if err != nil {
3470+
t.Fatalf("CI.CreateOCRTemplate returned error: %v", err)
3471+
}
3472+
}

example/CI/workflow_and_job/jobs.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,23 @@ func InvokeImageInspectJob() {
10791079
fmt.Printf("%+v\n", createJobRes.JobsDetail)
10801080
}
10811081

1082+
// InvokeImageOCRJob 提交一个OCR任务
1083+
func InvokeImageOCRJob() {
1084+
c := getClient()
1085+
createJobOpt := &cos.CreateJobsOptions{
1086+
Tag: "ImageOCR",
1087+
Input: &cos.JobInput{
1088+
Object: "pic/ocr.png",
1089+
},
1090+
Operation: &cos.MediaProcessJobOperation{
1091+
TemplateId: "t1a545cd125ea04ec7a3cd455065d601cc",
1092+
},
1093+
}
1094+
createJobRes, _, err := c.CI.CreateJob(context.Background(), createJobOpt)
1095+
log_status(err)
1096+
fmt.Printf("%+v\n", createJobRes.JobsDetail)
1097+
}
1098+
10821099
// JobNotifyCallback 解析任务回调
10831100
func JobNotifyCallback() {
10841101
taskBody := "<Response><EventName>TaskFinish</EventName><JobsDetail><Code>Success</Code><CreationTime>2022-06-30T19:30:20+0800</CreationTime><EndTime>2022-06-30T19:31:56+0800</EndTime><Input><BucketId>test-123456789</BucketId><Object>input/demo.mp4</Object><Region>ap-chongqing</Region><CosHeaders><Key>Content-Type</Key><Value>video/mp4</Value></CosHeaders><CosHeaders><Key>x-cos-request-id</Key><Value>NjJiZDYwYTFfNjUzYTYyNjRfZjEwZl8xMmZhYzY5</Value></CosHeaders><CosHeaders><Key>EventName</Key><Value>cos:ObjectCreated:Put</Value></CosHeaders><CosHeaders><Key>Size</Key><Value>1424687</Value></CosHeaders></Input><JobId>j06668dc0f86811ecb90d0b03267ce0e5</JobId><Message/><Operation><DigitalWatermark><IgnoreError>false</IgnoreError><Message>123456789ab</Message><State>Failed</State><Type>Text</Type><Version>V1</Version></DigitalWatermark><MediaInfo><Format><Bitrate>8867.172000</Bitrate><Duration>13.654000</Duration><FormatLongName>QuickTime / MOV</FormatLongName><FormatName>mov,mp4,m4a,3gp,3g2,mj2</FormatName><NumProgram>0</NumProgram><NumStream>2</NumStream><Size>15134046</Size><StartTime>0.000000</StartTime></Format><Stream><Audio><Bitrate>128.726000</Bitrate><Channel>2</Channel><ChannelLayout>stereo</ChannelLayout><CodecLongName>AAC (Advanced Audio Coding)</CodecLongName><CodecName>aac</CodecName><CodecTag>0x6134706d</CodecTag><CodecTagString>mp4a</CodecTagString><CodecTimeBase>1/44100</CodecTimeBase><Duration>13.652993</Duration><Index>1</Index><Language>und</Language><SampleFmt>fltp</SampleFmt><SampleRate>44100</SampleRate><StartTime>0.000000</StartTime><Timebase>1/44100</Timebase></Audio><Subtitle/><Video><AvgFps>25.000000</AvgFps><Bitrate>9197.180000</Bitrate><CodecLongName>H.265 / HEVC (High Efficiency Video Coding)</CodecLongName><CodecName>hevc</CodecName><CodecTag>0x31766568</CodecTag><CodecTagString>hev1</CodecTagString><CodecTimeBase>1/12800</CodecTimeBase><ColorPrimaries>bt470bg</ColorPrimaries><ColorRange>tv</ColorRange><ColorTransfer>smpte170m</ColorTransfer><Duration>12.960000</Duration><FieldOrder>progressive</FieldOrder><Fps>25.000000</Fps><HasBFrame>2</HasBFrame><Height>1920</Height><Index>0</Index><Language>und</Language><Level>120</Level><NumFrames>324</NumFrames><PixFormat>yuv420p</PixFormat><Profile>Main</Profile><RefFrames>1</RefFrames><Rotation>0.000000</Rotation><StartTime>0.000000</StartTime><Timebase>1/12800</Timebase><Width>1088</Width></Video></Stream></MediaInfo><MediaResult><OutputFile><Bucket>test-123456789</Bucket><Md5Info><Md5>852883012a6ba726e6ed8d9b984edfdf</Md5><ObjectName>output/super_resolution.mp4</ObjectName></Md5Info><ObjectName>output/super_resolution.mp4</ObjectName><ObjectPrefix/><Region>ap-chongqing</Region></OutputFile></MediaResult><Output><Bucket>test-123456789</Bucket><Object>output/super_resolution.${ext}</Object><Region>ap-chongqing</Region></Output><TemplateId>t1f1ae1dfsdc9ds41dsb31632d45710642a</TemplateId><TemplateName>template_superresolution</TemplateName><TranscodeTemplateId>t156c107210e7243c5817354565d81b578</TranscodeTemplateId><UserData>This is my SuperResolution job.</UserData><JobLevel>0</JobLevel><WatermarkTemplateId>t143ae6e040af6431aa772c9ec3f0a3f36</WatermarkTemplateId><WatermarkTemplateId>t12a74d11687d444deba8a6cc52051ac27</WatermarkTemplateId></Operation><QueueId>p2242ab62c7c94486915508540933a2c6</QueueId><StartTime>2022-06-30T19:30:21+0800</StartTime><State>Success</State><Progress>100</Progress><SubTag>DigitalWatermark</SubTag><Tag>SuperResolution</Tag><Workflow><Name>SuperResolution_1581665960537</Name><RunId>ic90edd59f84f11ec9d4f525400a3c59f</RunId><WorkflowId>web6ac56c1ef54dbfa44d7f4103203be9</WorkflowId><WorkflowName>workflow-test</WorkflowName></Workflow></JobsDetail></Response>"

example/CI/workflow_and_job/template.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,5 +964,46 @@ func UpdateNoiseReductionTemplate() {
964964
fmt.Printf("%+v\n", updateTplRes.Template)
965965
}
966966

967+
// UpdateOCRTemplate 创建OCR模板
968+
func CreateOCRTemplate() {
969+
c := getClient()
970+
rand.Seed(time.Now().UnixNano())
971+
createTplOpt := &cos.CreateOCRTemplateOptions{
972+
Tag: "ImageOCR",
973+
Name: "ImageOCR-" + strconv.Itoa(rand.Intn(100)),
974+
ImageOCR: &cos.ImageOCRTemplate{
975+
Type: "general",
976+
LanguageType: "zh",
977+
IsPdf: "false",
978+
IsWord: "true",
979+
EnableWordPolygon: "true",
980+
},
981+
}
982+
createTplRes, _, err := c.CI.CreateOCRTemplate(context.Background(), createTplOpt)
983+
log_status(err)
984+
fmt.Printf("%+v\n", createTplRes.Template)
985+
}
986+
987+
// UpdateOCRTemplate 更新OCR模板
988+
func UpdateOCRTemplate() {
989+
c := getClient()
990+
rand.Seed(time.Now().UnixNano())
991+
updateTplOpt := &cos.CreateOCRTemplateOptions{
992+
Tag: "ImageOCR",
993+
Name: "ImageOCR-" + strconv.Itoa(rand.Intn(100)),
994+
ImageOCR: &cos.ImageOCRTemplate{
995+
Type: "efficient",
996+
LanguageType: "zh",
997+
IsPdf: "false",
998+
IsWord: "true",
999+
EnableWordPolygon: "true",
1000+
},
1001+
}
1002+
templateId := "t1a545cd125ea04ec7a3cd455065d601cc"
1003+
updateTplRes, _, err := c.CI.UpdateOCRTemplate(context.Background(), updateTplOpt, templateId)
1004+
log_status(err)
1005+
fmt.Printf("%+v\n", updateTplRes.Template)
1006+
}
1007+
9671008
func main() {
9681009
}

0 commit comments

Comments
 (0)