This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo.knn; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.atomic.AtomicInteger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo.knn; | |
/** | |
* @author Engleang | |
* Distance calculator using Euclidean fomula | |
* | |
* */ | |
public final class DistanceCalculator { | |
public final static double getDistance(double[] data1, double[] data2) { | |
if (data1.length != data2.length) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo.knn; | |
/** | |
* @author | |
* Data class for storing the number represent bit(0,1) of the handwriting data. | |
* | |
* */ | |
public class SampleData { | |
private final double []data; | |
private final String identifier; | |
private final String fileName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo.knn; | |
/** | |
* @author Engleang | |
* Data class for storing distance value between test and sample . | |
* */ | |
public class SampleDistanceValue { | |
private final String identifier; | |
private final double value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo.knn; | |
import java.util.*; | |
import java.util.concurrent.*; | |
/** | |
* @author Engleang | |
* Knn Classifer is for classifying data using kNN algorithm | |
* | |
* */ | |
public class KnnClassifier { | |
private int k; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.demo.knn.*; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.ExecutionException; | |
/** | |
* @author Engleang | |
* Demo kNN application class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
testCompile group: 'junit', name: 'junit', version: '4.12' | |
compile group: 'net.sourceforge.tess4j', name: 'tess4j', version: '4.5.1' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static final int DELTA = 3; | |
public static boolean isEligible(BufferedImage img, int x, int y){ | |
int left = x-1; | |
while ( left < 0 && x -left < 2* DELTA) { | |
if( img.getRGB(left,y) == Color.WHITE.getRGB()) { | |
break; | |
} | |
left --; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BufferedImage image = ImageIO.read( new File("sample/captcha-sample-1.png")); | |
BufferedImage clean = cleanImage(image); | |
ImageIO.write(clean, "png",new File("sample/clean.png")); | |
Tesseract tesseract = new Tesseract(); | |
tesseract.setDatapath("D:\\ProgramFiles\\Tesseract-OCR\\tessdata"); | |
String result = tesseract.doOCR( clean); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String cleanResult(String result){ | |
StringBuilder sb = new StringBuilder(); | |
for(int i =0;i<result.length();i++){ | |
if( Character.isAlphabetic( result.charAt(i)) || Character.isDigit( result.charAt(i))) { | |
sb.append( result.charAt(i)); | |
} | |
} | |
return sb.toString(); | |
} |
OlderNewer