2017-09-08 2 views
0

안녕하세요 OCR 응용 프로그램을 내가 자산에서 내 데이터를로드 훈련 데이터애셋에서 여러 데이터를 읽으려면 어떻게해야합니까?

의 두 가지 언어를 사용할 필요가

를 만들기 위해 TESS-이 API를 사용하려고하지만 여러 데이터를로드 할 수 없습니다 수행하는 방법

private void checkFile(File dir) { 
    if (!dir.exists()&& dir.mkdirs()){ 
     copyFiles(); 
    } 
    if(dir.exists()) { 
     String datafilepath = datapath+ "/tessdata/eng.traineddata"; 
     File datafile = new File(datafilepath); 

     if (!datafile.exists()) { 
      copyFiles(); 
     } 
    } 
} 

private void copyFiles() { 
    try { 
     String filepath = datapath + "/tessdata/eng.traineddata"; 
     AssetManager assetManager = getAssets(); 

     InputStream instream = assetManager.open("tessdata/eng.traineddata"); 
     OutputStream outstream = new FileOutputStream(filepath); 

     byte[] buffer = new byte[1024]; 
     int read; 
     while ((read = instream.read(buffer)) != -1) { 
      outstream.write(buffer, 0, read); 
     } 


     outstream.flush(); 
     outstream.close(); 
     instream.close(); 

     File file = new File(filepath); 
     if (!file.exists()) { 
      throw new FileNotFoundException(); 
     } 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

가 어떻게 여러 데이터를 복사 할 변경할 수 있습니다 : 그것은

에서이 내 코드는?

답변

0

당신은 큰 배경 스레드에서 파일 (AsyncTask를 또는 스레드)를 복사해야합니다, 당신은 여러 trainedData 파일을 복사하는 논리를 사용할 수 있습니다 : 나는 당신의 대답에 대한 감사 가지고

private void checkFile(File dir) { 
     if (!dir.exists()) { 
      dir.mkdirs(); 
     } 
     if (dir.exists()) { 
      copyFiles("/tessdata/eng.traineddata"); 
      copyFiles("/tessdata/hin.traineddata"); 
      copyFiles("/tessdata/fra.traineddata"); 
     } 
    } 

    private void copyFiles(String path) { 
     try { 
      String filepath = datapath + path; 
      if (!new File(filepath).exists()) { 
       AssetManager assetManager = getAssets(); 

       InputStream instream = assetManager.open(path); 
       OutputStream outstream = new FileOutputStream(filepath); 

       byte[] buffer = new byte[1024]; 
       int read; 
       while ((read = instream.read(buffer)) != -1) { 
        outstream.write(buffer, 0, read); 
       } 


       outstream.flush(); 
       outstream.close(); 
       instream.close(); 

       File file = new File(filepath); 
       if (!file.exists()) { 
        throw new FileNotFoundException(); 
       } 
      } 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
+0

확인 –

관련 문제