圖片縮?。?>怎么能讓這個圖縮?。ㄔ趺纯梢宰?a target="_blank" href="http://m.bai1xia.com/news/tags-139.html"style="font-weight:bold;">圖片縮小)
1016
2022-05-30
1. 前言
平時工作中編寫開發技術文檔,或者學生在編寫論文時,經常會上網搜索一些參考文獻、文檔。
比如: 上網搜索相似的內容參考一下或者引用別人的一段文字,有時候看到一篇較好的內容想要保存等等。
這個過程中會發現,很多網站的提供的頁面都是不能復制粘貼的,或者直接是圖片形式提供,為了方便能獲取這些文字,當前就利用華為云提供的 通用文字識別接口,識別圖片里的文本內容,方便復制文字。這個功能QQ上也集成了,使用很方便,這里利用華為云的接口實現一個與QQ類似的功能,截圖之后識別圖片里包含的文本內容。
這個文字識別接口里不僅僅有通用文字識別功能,還支持很多其他功能:比如身份證、駕駛證、保險單、手寫文本、火車票,行駛證…等等功能。還支持用戶自定義識別模板,指定需要識別的關鍵字段,實現用戶特定格式圖片的自動識別和結構化提取。
2. 文本識別接口使用介紹
2.1 開通服務
地址: https://console.huaweicloud.com/ocr/?region=cn-north-4#/ocr/overview
這個文字識別服務是按調用次數計費的,每個用戶每月有1000次的免費調用次數,開通服務后就可以使用。
2.2 接口地址
官網幫助文檔: https://support.huaweicloud.com/api-ocr/ocr_03_0042.html
POST https://{endpoint}/v2/{project_id}/ocr/general-text 示例: https://ocr.cn-north-4.myhuaweicloud.com/v2/0e5957be8a00f53c2fa7c0045e4d8fbf/ocr/general-text 請求頭: { "X-Auth-Token": "******", "Content-Type": "application/json;charset=UTF-8" } 請求體: { "image": ----這是圖片的bas64編碼 } 響應結果: { "result": { "words_block_count": 13, "words_block_list": [ { "words": "撤,還是不撤?", "location": [ [ 43, 39 ], [ 161, 39 ], [ 161, 60 ], [ 43, 60 ] ] }, { "words": "讓我更驕傲的是公司在大災面前的表現。", "location": [ [ 72, 95 ], [ 332, 95 ], [ 332, 113 ], [ 72, 113 ] ] }, { "words": "2011年3月11日14時46分,日本東北部海域發生里氏9.0級", "location": [ [ 71, 122 ], [ 482, 122 ], [ 482, 142 ], [ 71, 142 ] ] }, { "words": "地震并引發海嘯。那一刻,我們正在距離東京100公里的熱海開會,", "location": [ [ 41, 149 ], [ 481, 149 ], [ 481, 171 ], [ 41, 171 ] ] }, { "words": "感覺“咚”", "location": [ [ 42, 180 ], [ 114, 180 ], [ 114, 199 ], [ 42, 199 ] ] }, { "words": "地被震了一下。面對地震,", "location": [ [ 115, 178 ], [ 296, 178 ], [ 296, 199 ], [ 115, 199 ] ] }, { "words": "大家都很鎮定,", "location": [ [ 300, 179 ], [ 400, 179 ], [ 400, 197 ], [ 300, 197 ] ] }, { "words": "直到看到電", "location": [ [ 405, 179 ], [ 483, 179 ], [ 483, 196 ], [ 405, 196 ] ] }, { "words": "視上觸目驚心的畫面:15時 25 分,海嘯到達陸前高田市海岸;15時", "location": [ [ 41, 206 ], [ 485, 206 ], [ 485, 228 ], [ 41, 228 ] ] }, { "words": "26分,海嘯到達陸前高田市中心;15時43分,陸前高田市依稀只能", "location": [ [ 40, 234 ], [ 486, 234 ], [ 486, 258 ], [ 40, 258 ] ] }, { "words": "看到四層高的市府大樓的屋頂,一瞬間,城鎮就變成了汪洋……對", "location": [ [ 40, 262 ], [ 487, 262 ], [ 487, 287 ], [ 40, 287 ] ] }, { "words": "我來說,地震跟家常便飯一樣,可眼前的災難比以往任何一次都要", "location": [ [ 40, 292 ], [ 487, 292 ], [ 487, 317 ], [ 40, 317 ] ] }, { "words": "慘烈,完全超出了我的預期。", "location": [ [ 41, 326 ], [ 231, 326 ], [ 231, 345 ], [ 41, 345 ] ] } ], "direction": -1 } }
2.3 在線調試接口
地址: https://apiexplorer.developer.huaweicloud.com/apiexplorer/debug?product=OCR&api=RecognizeGeneralText
使用調試接口想體驗識別效果,圖片的數據支持base64編碼、http網絡圖片地址傳入,測試非常方便。
關于獲取圖片base64編碼的方式,在文檔里也有介紹,直接通過瀏覽器獲取。
3. 實現代碼
代碼采用QT編寫的,請求API接口實現調用。其他語言方法是一樣的。
3.1 實現效果
3.2 核心代碼
//解析反饋結果 void Widget::replyFinished(QNetworkReply *reply) { QString displayInfo=""; int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); //讀取所有數據 QByteArray replyData = reply->readAll(); qDebug()<<"狀態碼:"<
AI
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。