2016-07-12 4 views
1

Encog를 사용 중이며 ocr 샘플을 실행했습니다. 그것은 잘 작동합니다. 그러나 이미지 파일 (png, jpg, ...)을 매개 변수로 전달하고 싶습니다. 이 이미지에는 인식 할 텍스트가 들어 있습니다. 그런 다음 시스템은 "동일한"텍스트가있는 문자열을 반환해야합니다.이미지에서 문자열로의 필기 인식

누군가 이미 비슷한 것을 했습니까? 어떻게 시작해야합니까?

감사합니다.

+0

당신은 무엇을하려고 않은 결과 확인? Encog의 API 문서를 읽었는지, 어떻게 사용할 수 있는지보기 위해 소스와 예제를 살펴 보았는가? – copeg

+0

예, 시도했습니다. 편지를 써서 훈련 세트로 사용할 수있는 샘플이 있습니다. 그런 다음 보조 패널에 글자를 그리고 시스템이이를 인식하는지 확인합니다. 클래스 SampleData를 가지고있는 것을 보았습니다. 아마도 이미지를 전달할 수있는 곳일 것입니다.하지만 아직 시도하지 않았고 이미지에서 내용을 추출하는 방법을 아직 보지 못했습니다. – Jas

답변

2

1 단계 : GUI에서 파일 입력을 생성하고 사용자로부터

JFileChooser fc; 
JButton b, b1; 
JTextField tf; 
FileInputStream in; 
Socket s; 
DataOutputStream dout; 
DataInputStream din; 
int i; 

public void actionPerformed(ActionEvent e) { 
try { 
    if (e.getSource() == b) { 
     int x = fc.showOpenDialog(null); 
     if (x == JFileChooser.APPROVE_OPTION) { 
      fileToBeSent = fc.getSelectedFile(); 
      tf.setText(f1.getAbsolutePath()); 
      b1.setEnabled(true); 
     } else { 
      fileToBeSent = null; 
      tf.setText(null;); 
      b1.setEnabled(false); 
     } 
    } 
    if (e.getSource() == b1) { 
     send(); 
    } 
} catch (Exception ex) { 
} 
} 

public void copy() throws IOException { 
    File f1 = fc.getSelectedFile(); 
    tf.setText(f1.getAbsolutePath()); 
    in = new FileInputStream(f1.getAbsolutePath()); 
    while ((i = in.read()) != -1) { 
     System.out.print(i); 
    } 
} 

public void send() throws IOException { 
    dout.write(i); 
    dout.flush(); 

} 

2 단계 파일을 : 아래 샘플을 그

private void processNetwork() throws IOException { 
    System.out.println("Downsampling images..."); 

    for (final ImagePair pair : this.imageList) { 
     final MLData ideal = new BasicMLData(this.outputCount); 
     final int idx = pair.getIdentity(); 
     for (int i = 0; i < this.outputCount; i++) { 
      if (i == idx) { 
       ideal.setData(i, 1); 
      } else { 
       ideal.setData(i, -1); 
      } 
     } 

     final Image img = ImageIO.read(fc.getFile()); 
     final ImageMLData data = new ImageMLData(img); 
     this.training.add(data, ideal); 
    } 

    final String strHidden1 = getArg("hidden1"); 
    final String strHidden2 = getArg("hidden2"); 

    this.training.downsample(this.downsampleHeight, this.downsampleWidth); 

    final int hidden1 = Integer.parseInt(strHidden1); 
    final int hidden2 = Integer.parseInt(strHidden2); 

    this.network = EncogUtility.simpleFeedForward(this.training 
      .getInputSize(), hidden1, hidden2, 
      this.training.getIdealSize(), true); 
    System.out.println("Created network: " + this.network.toString()); 
} 

3 단계 : 교육 집합 교육 시작

private void processTrain() throws IOException { 
    final String strMode = getArg("mode"); 
    final String strMinutes = getArg("minutes"); 
    final String strStrategyError = getArg("strategyerror"); 
    final String strStrategyCycles = getArg("strategycycles"); 

    System.out.println("Training Beginning... Output patterns=" 
      + this.outputCount); 

    final double strategyError = Double.parseDouble(strStrategyError); 
    final int strategyCycles = Integer.parseInt(strStrategyCycles); 

    final ResilientPropagation train = new ResilientPropagation(this.network, this.training); 
    train.addStrategy(new ResetStrategy(strategyError, strategyCycles)); 

    if (strMode.equalsIgnoreCase("gui")) { 
     TrainingDialog.trainDialog(train, this.network, this.training); 
    } else { 
     final int minutes = Integer.parseInt(strMinutes); 
     EncogUtility.trainConsole(train, this.network, this.training, 
       minutes); 
    } 
    System.out.println("Training Stopped..."); 
} 

4 단계 : 신경 네트워크에 샘플 파일을 내려주고

public void processWhatIs() throws IOException { 
    final String filename = getArg("image"); 
    final File file = new File(filename); 
    final Image img = ImageIO.read(file); 
    final ImageMLData input = new ImageMLData(img); 
    input.downsample(this.downsample, false, this.downsampleHeight, 
      this.downsampleWidth, 1, -1); 
    final int winner = this.network.winner(input); 
    System.out.println("What is: " + filename + ", it seems to be: " 
      + this.neuron2identity.get(winner)); 
} 

5 단계 :

+0

1 단계에서 GUI가 무슨 뜻입니까? 패키지 "org.encog.examples.neural.gui.ocr"에서 변경할 파일이거나 새 파일을 만들 필요가 있습니까? – Jas