私はプリミティブなOCRプロジェクトを作成しています。私は、画像行列と数列を比較し、それらを「得点する」方法を書いた。最高の数値行列が最もよく一致する。ここに私の方法です:OCRの2つの配列を比較する
public double compareMatrices(int[][] num, int[][] img) {
int nNumRows = num.length;
int nNumCols = num[0].length;
int nImgRows = img.length;
int nImgCols = img[0].length;
double highest = 0;
for (int row = 0; row < nImgRows - nNumRows + 1; row++) {
for (int col = 0; col < nImgCols - nNumCols + 1; col++) {
double score = 0;
for
(int row_offset = 0; row_offset < nNumRows; row_offset++) {
for (int col_offset = 0;
col_offset < nNumCols; col_offset++) {
int imgRowIndex = row + row_offset;
int imgColIndex = col + col_offset;
int numV = num[row_offset][col_offset];
int imgV = img[imgRowIndex][imgColIndex];
if ((imgV == 1) && (numV == 1)) {
score +=1;
} else if ((numV == 1) & (imgV == 0)) {
score -= 0.25;
} else if ((numV == 0) && (imgV == 0)) {
score += 0.25;
}
}
}
if (score > highest) {
highest = score;
}
}
}
return highest;
}
今、私はcompareMatrices
方法からスコアを比較してベストマッチ数行列のかを判断する方法を記述しようとしています。私が持っているもの
はimgd0
はテスト画像であり、これは(?または私も、私はちょうどと比較する画像行列があるだろうと言うことができます画像を指定する必要がありますか?):
public String FindBestMatch() {
numFiles.getMatrix("zero");
compareMatrices(int[][] zero, imgd0);
numFiles.getMatrix("one");
compareMatrices(int[][] one, imgd0);
numFiles.getMatrix("two");
compareMatrices(int[][] two, imgd0);
numFiles.getMatrix("three");
compareMatrices(int[][] three, imgd0);
numFiles.getMatrix("four");
compareMatrices(int[][] four, imgd0);
numFiles.getMatrix("five");
compareMatrices(int[][] five, imgd0);
numFiles.getMatrix("six");
compareMatrices(int[][] six, imgd0);
numFiles.getMatrix("seven");
compareMatrices(int[][] seven, imgd0);
numFiles.getMatrix("eight");
compareMatrices(int[][] eight, imgd0);
numFiles.getMatrix("nine");
compareMatrices(int[][] nine, imgd0);
numFiles.getMatrixはから来ているメソッドです。
public class NumFiles {
private int[][] one = makeMatrix("one.txt");
private int[][] two= makeMatrix("two.txt");
private int[][] three= makeMatrix("three.txt");
private int[][] four= makeMatrix("four.txt");
private int[][] five= makeMatrix("five.txt");
private int[][] six= makeMatrix("six.txt");
private int[][] seven= makeMatrix("seven.txt");
private int[][] eight= makeMatrix("eight.txt");
private int[][] nine= makeMatrix("nine.txt");
private int[][] zero= makeMatrix("zero.txt");
public NumFiles() {
}
public int[][] getMatrix(String num){
if (num == "one") {
return one;
}
else if (num == "two"){
return two;
}
else if (num == "three"){
return three;
}
else if (num == "four") {
return four;
}
else if (num == "five") {
return five;
}
else if (num == "six") {
return six;
}
else if (num == "seven"){
return seven;
}
else if (num == "eight"){
return eight;
}
else if (num == "nine") {
return nine;
}
else if (num == "zero") {
return zero;
}
else {
int [][] k = {{-1},{-1}};
return k;
}
}
だから私は何を求めていることは、私のFindBestMatch
方法のためにあるすべての単一の番号マトリックスを通過するよりも、それを書くには良い方法があり、実行していますcompareMatrices
毎時1つのsiに対してテスト画像を確認するありがとう!
==ではなく、equalsメソッドを使用して文字列を比較します。 –
@GilbertLeBlanc ==私がしようとしていることに対してうまく動作します。私は実際には 'FindBestMatch'メソッドに問題があります – amizz
あなたの問題はどこですか?また、質問を改善するために、[最小限で完全で検証可能なサンプルを作成する方法](http://stackoverflow.com/help/mcve)をご覧ください。ありがとう! –