提交修改
This commit is contained in:
parent
b6858d489a
commit
b95a32c9fd
@ -27,17 +27,15 @@ public class ARecognizeVideoCharacterHandle extends AlibabaBaseHandle<ARecognize
|
||||
|
||||
@Override
|
||||
public String check(ARecognizeVideoCharacterRequest aRecognizeVideoCharacterRequest) {
|
||||
if (StringUtils.isBlank(aRecognizeVideoCharacterRequest.getUrl())) {
|
||||
return "视频url不能为空";
|
||||
}
|
||||
return null;
|
||||
|
||||
return checkUrlBase64(aRecognizeVideoCharacterRequest);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RecognizeVideoCharacterResponse run(ARecognizeVideoCharacterRequest aRecognizeVideoCharacterRequest, RuntimeOptions runtime) throws Exception {
|
||||
RecognizeVideoCharacterRequest request = new RecognizeVideoCharacterRequest();
|
||||
request.setVideoURL(aRecognizeVideoCharacterRequest.getUrl());
|
||||
request.setVideoURL(aRecognizeVideoCharacterRequest.getImageUrl());
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
return client.recognizeVideoCharacterWithOptions(request, runtime);
|
||||
}
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
package com.heyu.api.alibaba.request.common.text;
|
||||
|
||||
import com.heyu.api.alibaba.request.ACommonTextRequest;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ARecognizeVideoCharacterRequest {
|
||||
public class ARecognizeVideoCharacterRequest extends ACommonTextRequest {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 视频url
|
||||
*/
|
||||
private String url;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
package com.heyu.api.controller.certificate.video;
|
||||
|
||||
|
||||
import com.aliyun.ocr20191230.models.RecognizeVideoCharacterResponse;
|
||||
import com.aliyun.ocr20191230.models.RecognizeVideoCharacterResponseBody;
|
||||
import com.heyu.api.alibaba.handle.common.text.ARecognizeVideoCharacterHandle;
|
||||
import com.heyu.api.alibaba.request.common.text.ARecognizeVATInvoiceRequest;
|
||||
import com.heyu.api.alibaba.request.common.text.ARecognizeVideoCharacterRequest;
|
||||
import com.heyu.api.controller.BaseController;
|
||||
import com.heyu.api.controller.request.video.RecognizeVideoCharacterReq;
|
||||
import com.heyu.api.controller.resp.video.RecognizeVideoCharacterResp;
|
||||
import com.heyu.api.controller.resp.video.RecognizeVideoCharacterTextResp;
|
||||
import com.heyu.api.data.annotation.CacheResult;
|
||||
import com.heyu.api.data.annotation.NotIntercept;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/video/character")
|
||||
@NotIntercept
|
||||
public class RecognizeVideoCharacterController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ARecognizeVideoCharacterHandle arRecognizeVideoCharacterHandle;
|
||||
|
||||
|
||||
@RequestMapping("/recognize")
|
||||
@CacheResult
|
||||
public R recognize(RecognizeVideoCharacterReq request) {
|
||||
List<RecognizeVideoCharacterResp> resp = new ArrayList<>();
|
||||
ARecognizeVideoCharacterRequest aRecognizeVideoCharacterRequest = new ARecognizeVideoCharacterRequest();
|
||||
|
||||
aRecognizeVideoCharacterRequest.setImageBase64(request.getVideoBase64());
|
||||
aRecognizeVideoCharacterRequest.setImageUrl(request.getVideoURL());
|
||||
ApiR<RecognizeVideoCharacterResponse> aR = arRecognizeVideoCharacterHandle.handle(aRecognizeVideoCharacterRequest);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
RecognizeVideoCharacterResponseBody.RecognizeVideoCharacterResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
List<RecognizeVideoCharacterResponseBody.RecognizeVideoCharacterResponseBodyDataFrames> framesList = responseBodyData.getFrames();
|
||||
for (RecognizeVideoCharacterResponseBody.RecognizeVideoCharacterResponseBodyDataFrames frames : framesList) {
|
||||
RecognizeVideoCharacterResp recognizeVideoCharacterResp = new RecognizeVideoCharacterResp();
|
||||
recognizeVideoCharacterResp.setTimestamp(frames.getTimestamp());
|
||||
List<RecognizeVideoCharacterTextResp> textResps = new ArrayList<>();
|
||||
for (RecognizeVideoCharacterResponseBody.RecognizeVideoCharacterResponseBodyDataFramesElements element : frames.getElements()) {
|
||||
RecognizeVideoCharacterTextResp recognizeVideoCharacterTextResp = new RecognizeVideoCharacterTextResp();
|
||||
recognizeVideoCharacterTextResp.setText(element.getText());
|
||||
textResps.add(recognizeVideoCharacterTextResp);
|
||||
}
|
||||
recognizeVideoCharacterResp.setRecognizeVideoCharacterTextRespList(textResps);
|
||||
|
||||
resp.add(recognizeVideoCharacterResp);
|
||||
}
|
||||
R.ok().setData(resp);
|
||||
}
|
||||
return R.error(aR.getErrorMsg());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.heyu.api.controller.request.video;
|
||||
|
||||
|
||||
import com.heyu.api.data.dto.BaseRequest;
|
||||
import com.heyu.api.data.dto.BaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RecognizeVideoCharacterReq extends BaseRequest {
|
||||
|
||||
|
||||
/***
|
||||
* 视频 URL 地址。推荐使用上海地域的 OSS 链接,对于文件在本地或者非上海地域 OSS 链接的情况,请参见文件 URL 处理。
|
||||
*
|
||||
* 示例值:
|
||||
* http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/RecognizeVideoCharacter/xxxx.mp4
|
||||
*/
|
||||
private String videoURL;
|
||||
|
||||
|
||||
/**
|
||||
* 视频的base64
|
||||
*/
|
||||
private String videoBase64;
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.heyu.api.controller.resp.video;
|
||||
|
||||
|
||||
import com.heyu.api.data.dto.BaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/***
|
||||
* https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeVideoCharacter?tab=DOC&lang=JAVA
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class RecognizeVideoCharacterResp extends BaseResp {
|
||||
|
||||
|
||||
/***
|
||||
* 帧时间戳,单位毫秒。
|
||||
*
|
||||
* 注意 请注意,该值为 Long 类型,在某些语言中可能存在精度丢失的风险,请小心使用。
|
||||
* 示例值:
|
||||
* 6124533574
|
||||
*/
|
||||
private Long timestamp;
|
||||
|
||||
/***
|
||||
* 文字内容。
|
||||
*
|
||||
* 示例值:
|
||||
* 在桃花盛开的地方
|
||||
*/
|
||||
private List<RecognizeVideoCharacterTextResp> recognizeVideoCharacterTextRespList;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.heyu.api.controller.resp.video;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RecognizeVideoCharacterTextResp {
|
||||
|
||||
|
||||
|
||||
|
||||
private String text;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user