调用腾讯ORC接口识别图片文字

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

腾讯API: https://cloud.tencent.com/document/product/460/9519

准备

在下面网页中添加图片 https://console.cloud.tencent.com/ci/bucket

调用腾讯ORC接口识别图片文字_第1张图片

 

使用方法:

 function testorc()
 {    
    var data = {
        "appid":"123456abc",
        "bucket":"test",
        "url":"http://test-123456abc.picsh.myqcloud.com/test.jpg",
         };  
            
    $.ajax({
         type: "POST",
         beforeSend: function (xhr) {
             xhr.setRequestHeader ("Authorization","N2MXuNZg8kGaJqfIRbkRB3JBetphPTEyNTMzMTA1NDgmaz1BS0lEa2ZVQW1FNmRlV0NoMEJPNHZwYkRhcnd1b2NFbWFOVE4mZT0xNTE1MTTMyJnQ9MTUxMjUxOTEzMiZyPTI3MDQ5NDY0NyZ1PSZmPQ==");
            },
         url: "http://recognition.image.myqcloud.com/ocr/general",
         contentType:"application/json",  
         data:JSON.stringify(data),
         success: function(json) {
            var data=eval("("+json+")");
            alert(data);
          }
    });   
}

需要注意的地方:

1.获取appid,SecretId,SecretKey

获取地址: https://console.qcloud.com/capi

2. 生成 鉴权签名

生成方法说明:  https://cloud.tencent.com/document/product/275/3805

直接使用AJAX的方式来操作的话,经过测试需要使用V1版本的签名算法。只需要把官方的php的demo代码复制下来,简单修改下对应的超时时间即可。

V1版的生成鉴权签名代码:(需要了解 a k e t r f 分别代表什么 ,V2版本介绍里有)


~       

3.在html的head头中添加Authorization的方法

beforeSend: function (xhr) {
	        	 xhr.setRequestHeader ("Authorization","N2MXuNZg8kGaJqfIRbkRB3JBetphPTEyNTMzMTA1NDgmaz1BS0lEa2ZVQW1FNmRlV0NoMEJPNHZwYkRhcnd1b2NFbWFOVE4mZT0xNTE1MTExMTMyJnQ9MTUxMjUxOTEzMiZyPTI3MDQ5NDY0NyZ1PSZmPQ==");
},

4.发送的数据格式要根据官方要求来写

具体参考ajax的写法。

测试图片:

083419_hTuF_2290420.png

测试结果:

{
    "code":0,
    "message":"OK",
    "data":{
        "session_id":"1253310548977883657",
        "items":[
            {
                "itemcoord":{
                    "x":53,
                    "y":0,
                    "width":41,
                    "height":10
                },
                "itemstring":"1中-e",
                "words":[
                    {
                        "character":"1",
                        "confidence":0.28456753492355347
                    },
                    {
                        "character":"中",
                        "confidence":0.5753018856048584
                    },
                    {
                        "character":"-",
                        "confidence":0.694950520992279
                    },
                    {
                        "character":"e",
                        "confidence":0.4864801466464997
                    }
                ]
            },
            {
                "itemcoord":{
                    "x":31,
                    "y":26,
                    "width":217,
                    "height":24
                },
                "itemstring":"我在上大学的时候,就看她的视频了",
                "words":[
                    {
                        "character":"我",
                        "confidence":0.9999849796295166
                    },
                    {
                        "character":"在",
                        "confidence":0.9999985694885254
                    },
                    {
                        "character":"上",
                        "confidence":0.999993085861206
                    },
                    {
                        "character":"大",
                        "confidence":0.9995139837265016
                    },
                    {
                        "character":"学",
                        "confidence":0.99998939037323
                    },
                    {
                        "character":"的",
                        "confidence":0.9999998807907104
                    },
                    {
                        "character":"时",
                        "confidence":0.99998939037323
                    },
                    {
                        "character":"候",
                        "confidence":0.9999817609786988
                    },
                    {
                        "character":",",
                        "confidence":0.9864382743835448
                    },
                    {
                        "character":"就",
                        "confidence":0.9999992847442628
                    },
                    {
                        "character":"看",
                        "confidence":0.99922776222229
                    },
                    {
                        "character":"她",
                        "confidence":0.9997465014457704
                    },
                    {
                        "character":"的",
                        "confidence":0.9999988079071044
                    },
                    {
                        "character":"视",
                        "confidence":0.9999635219573976
                    },
                    {
                        "character":"频",
                        "confidence":0.9999231100082397
                    },
                    {
                        "character":"了",
                        "confidence":0.9999946355819702
                    }
                ]
            }
        ]
    }
}

 

转载于:https://my.oschina.net/aslanjia/blog/1585406

你可能感兴趣的:(json,php,python)