2013-04-20 69 views
0

我搜索了很多,但我還沒有成功。我不想使用Tesseract medhod。使用Google Drive的Android中的OCR集成

我照着

https://developers.google.com/drive/quickstart-android

,當運行圖像得到了上傳到護目鏡文檔創建的項目。我收到了文件名稱成功上傳的消息。

下載數據我也跟着

public void downloadfile(File file) 
    { 
     String imageAsTextUrl = file.getExportLinks().get("text/plain"); 

     HttpClient client = new DefaultHttpClient(); 
     HttpGet get = new HttpGet(imageAsTextUrl); 
     HttpResponse response; 

     StringBuffer sb = new StringBuffer(); 
     BufferedReader in = null; 
     try 
     { 
      response = client.execute(get); 
      in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
      String str; 
      while ((str = in.readLine()) != null) 
      { 
       sb.append(str); 
      } 
      Log.e(" sb data ", sb.toString()); 
      in.close(); 
     } 
     catch (ClientProtocolException e) 
     { 
      e.printStackTrace(); 
     } 
     catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 
    } 

,我得到了回報數據

<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <title>Welcome to Google Docs</title><style type="text/css"> html, body, div, h1, h2, h3, h4, h5, h6, p, img, dl, dt, dd, ol, ul, li, table, tr, td, form, object, embed, article, aside, canvas, command, details, fieldset, figcaption, figure, footer, group, header, hgroup, legend, mark, menu, meter, nav, output, progress, section, summary, time, audio, video { margin: 0; padding: 0; border: 0; } article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } html { font: 81.25% arial, helvetica, sans-serif; background: #fff; color: #333; line-height: 1; direction: ltr; } a { color: #15c; text-decoration: none; } a:active { color: #d14836; } a:hover { text-decoration: underline; } h1, h2, h3, h4, h5, h6 { color: #222; font-size: 1.54em; font-weight: normal; line-height: 24px; margin: 0 0 .46em; } p { line-height: 17px; margin: 0 0 1em; } ol, ul { list-style: none; line-height: 17px; margin: 0 0 1em; } li { margin: 0 0 .5em; } table { border-collapse: collapse; border-spacing: 0; } strong { color: #222; }</style><style type="text/css"> html, body { position: absolute; height: 100%; min-width: 100%; } .wrapper { position: relative; min-height: 100%; } .wrapper + style + iframe { display: none; } .content { padding: 0 44px; } .topbar { text-align: right; padding-top: .5em; padding-bottom: .5em; } .google-header-bar { height: 71px; background: #f1f1f1; border-bottom: 1px solid #e5e5e5; overflow: hidden; } .header .logo { margin: 17px 0 0; float: left; } .header .signin, .header .signup { margin: 28px 0 0; float: right; font-weight: bold; } .header .signin-button, .header .signup-button { margin: 22px 0 0; float: right; } .header .signin-button a { font-size: 13px; font-weight: normal; } .header .signup-button a { position: relative; top: -1px; margin: 0 0 0 1em; } .main { margin: 0 auto; width: 650px; padding-top: 23px; padding-bottom: 100px; } .main h1:first-child { margin: 0 0 .92em; } .google-footer-bar { position: absolute; bottom: 0; height: 35px; width: 100%; border-top: 1px solid #ebebeb; overflow: hidden; } .footer { padding-top: 9px; font-size: .85em; white-space: nowrap; line-height: 0; } .footer ul { color: #999; float: left; max-width: 80%; } .footer ul li { display: inline; padding: 0 1.5em 0 0; } .footer a { color: #333; } .footer .lang-chooser-wrap { float: right; max-width: 20%; } .footer .lang-chooser-wrap img { vertical-align: middle; } .footer .attribution { float: right; } .footer .attribution span { vertical-align: text-top; } .redtext { color: #dd4b39; } .greytext { color: #555; } .secondary { font-size: 11px; color: #666; } .source { color: #093; } .hidden { display: none; } .announce-bar { position: absolute; bottom: 35px; height: 33px; z-index: 2; width: 100%; background: #f9edbe; border-top: 1px solid #efe1ac; border-bottom: 1px solid #efe1ac; overflow: hidden; } .announce-bar .message { font-size: .85em; line-height: 33px; margin: 0; } .announce-bar .message .separated { margin-left: 1.5em; } .announce-bar-ac { background: #eee; border-top: 1px solid #e5e5e5; border-bottom: 1px solid #e5e5e5; } .clearfix:after { visibility: hidden; display: block; font-size: 0; content: '.'; clear: both; height: 0; } * html .clearfix { zoom: 1; } *:first-child+html .clearfix { zoom: 1; } pre { font-family: monospace; position: absolute; left: 0; margin: 0; padding: 1.5em; font-size: 13px; background: #f1f1f1; border-top: 1px solid #e5e5e5; direction: ltr; }</style><style type="text/css"> button, input, select, textarea { font-family: inherit; font-size: inherit; } button::-moz-focus-inner, input::-moz-focus-inner { border: 0; } input[type=email], input[type=number], input[type=password], input[type=tel], input[type=text], input[type=url] { -webkit- "

但這並不返回圖像中的文本,我上傳。如何得到的文字,我上傳的圖像?

當我試過

Android Open and Save files to/from Google Drive SDK

下載,我在 「DriveRequest driveRequest = (DriveRequest) request;」 得到了一個錯誤,它可能不投的HttpRequest到DriveRequest

然後我試着用

DriveRequest driveRequest = DriveRequest.class.cast(request); 

,但我在此得到了崩潰行說ClassCastExcaption。

歡迎任何相關答案。提前致謝 。

回答

0

我加入

get.setHeader("Authorization", "Bearer " + credential.getToken()); 

downloadfile方法得到了我的答案正確。

由於我的身份驗證不正確,它返回了Google文檔歡迎頁面的HTML。添加這一行後,我得到了正確的識別文本。

相關問題