百度ai图像识别

◇◆丶佛笑我妖孽 提交于 2019-11-27 18:10:49

require 'restclient'
require 'open-uri'
require 'nokogiri'
require 'json'
require 'yaml'
require 'fileutils'
require 'base64'

def extract_phone(image_src) 
  url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
  access_token = "24.0bbbc3338fcf9df41f26b42ff2a077.2593200.15323228.282335-11449805"
  content_type = "application/x-www-form-urlencoded"
  file = open(image_src).read
  image = Base64.encode64(file)
  RestClient.post(url, {access_token: access_token, image: image}, {content_type: content_type}) do |response|
    body = JSON.parse(response.body)
    return raise unless body['error_code'].nil?
    return body["words_result"][0]["words"]
  end
end

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!