2016-07-12 9 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

関連する問題