简介
本文档提供关于对象存储图片二维码相关的 API 概览以及 SDK 示例代码。
API | 操作描述 |
二维码识别 | 二维码识别功能可识别图片中有效二维码的位置及内容,输出图像中二维码包含的文本信息(每个二维码对应的 URL 或文本),并可对识别出的二维码添加马赛克 |
图片二维码
上传时识别二维码
功能说明
识别图片中有效二维码的位置及内容,输出图像中二维码包含的文本信息(每个二维码对应的 URL 或文本),并可对识别出的二维码添加马赛克。
方法原型
CosResult PutImage(const PutImageByFileReq& request, PutImageByFileResp* response);
请求示例
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";
PicOperation pic_operation;PicRules rule1;// 处理结果的文件路径名称,如以/开头rule1.fileid = "/" + object_name + "_put_qrcode";// 二维码识别处理参数rule1.rule = "QRcode/cover/1";pic_operation.AddRule(rule1);req.SetPicOperation(pic_operation);
qcloud_cos::CosResult result = cos.GetObject(req, &resp);if (result.IsSucc()) { // 调用成功,调用 resp 的成员函数获取返回内容 std::cout << "ProcessResult: " << resp.GetUploadResult().to_string() << std::endl;} else { // 调用失败,调用 result 的成员函数获取错误信息}
参数说明
参数 | 参数描述 | 类型 | 是否必填 |
req | PutImage 操作的请求 | PutImageByFileReq | 是 |
resp | PutImage 操作的响应 | PutImageByFileReq | 是 |
req涉及到如下结构:
struct PicRules { std::string bucket; // 存储结果的目标存储桶名称,格式为 BucketName-APPID,如果不指定的话默认保存到当前存储桶 std::string fileid; // 处理结果的文件路径名称,如以/开头,则存入指定文件夹中,否则,存入原图文件存储的同目录 std::string rule; // 处理参数,参见对象存储图片处理API。若按指定样式处理,则以style/开头,后加样式名,如样式名为test,则 rule 字段为style/test};
class PicOperation { public: PicOperation() : is_pic_info(true) {} virtual ~PicOperation() {} void AddRule(const PicRules& rule) { rules.push_back(rule); } void TurnOffPicInfo() { is_pic_info = false; } private: boolis_pic_info; // 是否返回原图信息,0不返回原图信息,1返回原图信息,默认为0 std::vector<PicRules> rules; //处理规则,一条规则对应一个处理结果(目前支持五条规则),不填则不进行图片处理};
resp涉及到如下结构:
struct CodeLocation { std::vector<std::string> points; // 二维码坐标点};
struct QRcodeInfo { std::string code_url; // 二维码的内容。可能识别不出 CodeLocation code_location; // 图中识别到的二维码位置坐标
};
struct Object { std::string key; // 文件名 std::string location; // 图片路径 std::string format; // 图片格式 int width; // 图片宽度 int height; // 图片高度 int size; // 图片大小 int quality; // 图片质量 std::string etag; // 处理结果图 ETag 信息 int code_status; // 二维码识别结果。0表示未识别到二维码,1表示识别到二维码 int watermark_status; // 当 type // 为2时返回该字段,表示提取到全盲水印的可信度。 // 具体为0-100的数字,75分以上表示确定有盲水印,60-75表示疑似有盲水印,60以下可认为未提取到盲水印 std::vector<QRcodeInfo> qr_code_info; // 二维码识别结果,可能有多个};
struct ProcessResults { std::vector<Object> objects; // 可能有多个对象};
struct ImageInfo { std::string format; // 格式 int width; // 图片宽度 int height; // 图片高度 int quality; // 图片质量 std::string ave; // 图片主色调 int orientation; // 图片旋转角度};
struct UploadResult { OriginalInfo original_info; // 原图信息 ProcessResults process_result; // 图片处理结果};
下载时识别二维码
功能说明
下载图片时识别二维码。
方法原型
CosResult GetQRcode(const GetQRcodeReq& request, GetQRcodeResp* response);
请求示例
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";
GetQRcodeReq req(bucket_name, object_name);GetQRcodeResp resp;
CosResult result = cos.GetQRcode(req, &resp);if (result.IsSucc()) { // 调用成功,调用 resp 的成员函数获取返回内容 std::cout << "ProcessResult: " << resp.GetUploadResult().to_string() << std::endl;} else { // 调用失败,调用 result 的成员函数获取错误信息}
参数说明
参数 | 参数描述 | 类型 | 是否必填 |
req | GetQRcode 操作的请求 | GetQRcodeReq | 是 |
resp | GetQRcode 操作的响应 | GetQRcodeResp | 是 |
req涉及到如下结构:
struct PicRules { std::string bucket; // 存储结果的目标存储桶名称,格式为 BucketName-APPID,如果不指定的话默认保存到当前存储桶 std::string fileid; // 处理结果的文件路径名称,如以/开头,则存入指定文件夹中,否则,存入原图文件存储的同目录 std::string rule; // 处理参数,参见对象存储图片处理API。若按指定样式处理,则以style/开头,后加样式名,如样式名为test,则 rule 字段为style/test};
class PicOperation { public: PicOperation() : is_pic_info(true) {} virtual ~PicOperation() {} void AddRule(const PicRules& rule) { rules.push_back(rule); } void TurnOffPicInfo() { is_pic_info = false; } private: boolis_pic_info; // 是否返回原图信息,0不返回原图信息,1返回原图信息,默认为0 std::vector<PicRules> rules; //处理规则,一条规则对应一个处理结果(目前支持五条规则),不填则不进行图片处理};
resp 涉及到如下结构:
struct CodeLocation { std::vector<std::string> points; // 二维码坐标点 }};
struct QRcodeInfo { std::string code_url; // 二维码的内容。可能识别不出 CodeLocation code_location; // 图中识别到的二维码位置坐标};
struct GetQRcodeResult { int code_status; // 二维码识别结果。0表示未识别到二维码,1表示识别到二维码 std::vector<QRcodeInfo> qr_code_info; // 二维码识别结果,可能有多个 std::string result_image; // 处理后的图片 base64数据,请求参数 cover 为1时返回};
对象存储官网1折活动,限时活动,即将结束,速速收藏
同尘科技为腾讯云授权服务中心。
购买腾讯云产品享受折上折,更有现金返利。同意关联立享优惠
转转请注明出处:https://www.yunxiaoer.com/145494.html