Skip to content

Commit

Permalink
Add a test case for UNLV zone file
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenq committed Mar 8, 2015
1 parent c2f0417 commit 7154fbd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@
<artifactId>platform</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<version>3.0.9</version>
</dependency>
<dependency>
<groupId>net.java.dev.jai-imageio</groupId>
<artifactId>jai-imageio-core-standalone</artifactId>
Expand Down
31 changes: 29 additions & 2 deletions src/test/java/net/sourceforge/tess4j/Tesseract1Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void tearDown() {

/**
* Test of doOCR method, of class Tesseract1.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -83,6 +84,27 @@ public void testDoOCR_File() throws Exception {

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
public void testDoOCR_UNLV_Zone_File() throws Exception {
System.out.println("doOCR on a PNG image with UNLV zone file .uzn");
//UNLV zone format: left top width height label
String filename = String.format("%s/%s", this.testResourcesDataPath, "eurotext_unlv.png");
File imageFile = new File(filename);
String expResult = "& duck/goose, as 12.5% of E-mail\n\n"
+ "from aspammer@website.com is spam.\n\n"
+ "The (quick) [brown] {fox} jumps!\n"
+ "Over the $43,456.78 <lazy> #90 dog";
String result = instance.doOCR(imageFile);
System.out.println(result);
assertEquals(expResult, result.trim());
}

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -100,6 +122,7 @@ public void testDoOCR_File_With_Configs() throws Exception {

/**
* Test of doOCR method, of class Tesseract1.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -116,6 +139,7 @@ public void testDoOCR_File_Rectangle() throws Exception {

/**
* Test of doOCR method, of class Tesseract1.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -132,12 +156,13 @@ public void testDoOCR_List_Rectangle() throws Exception {

/**
* Test of doOCR method, of class Tesseract1.
*
* @throws java.lang.Exception
*/
@Test
public void testDoOCR_BufferedImage() throws Exception {
System.out.println("doOCR on a buffered image of a GIF");
String filename = String.format("%s/%s", this.testResourcesDataPath, "eurotext.gif");
System.out.println("doOCR on a buffered image of a PNG");
String filename = String.format("%s/%s", this.testResourcesDataPath, "eurotext.png");
File imageFile = new File(filename);
BufferedImage bi = ImageIO.read(imageFile);
String expResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78 <lazy> #90 dog";
Expand All @@ -148,6 +173,7 @@ public void testDoOCR_BufferedImage() throws Exception {

/**
* Test of deskew algorithm.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -170,6 +196,7 @@ public void testDoOCR_SkewedImage() throws Exception {

/**
* Test of extending Tesseract1.
*
* @throws java.lang.Exception
*/
@Test
Expand Down
30 changes: 28 additions & 2 deletions src/test/java/net/sourceforge/tess4j/TesseractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void tearDown() {

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -74,6 +75,27 @@ public void testDoOCR_File() throws Exception {

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
public void testDoOCR_UNLV_Zone_File() throws Exception {
System.out.println("doOCR on a PNG image with UNLV zone file .uzn");
//UNLV zone format: left top width height label
String filename = String.format("%s/%s", this.testResourcesDataPath, "eurotext_unlv.png");
File imageFile = new File(filename);
String expResult = "& duck/goose, as 12.5% of E-mail\n\n"
+ "from aspammer@website.com is spam.\n\n"
+ "The (quick) [brown] {fox} jumps!\n"
+ "Over the $43,456.78 <lazy> #90 dog";
String result = instance.doOCR(imageFile);
System.out.println(result);
assertEquals(expResult, result.trim());
}

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -92,6 +114,7 @@ public void testDoOCR_File_With_Configs() throws Exception {

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -108,6 +131,7 @@ public void testDoOCR_File_Rectangle() throws Exception {

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
Expand All @@ -124,12 +148,13 @@ public void testDoOCR_List_Rectangle() throws Exception {

/**
* Test of doOCR method, of class Tesseract.
*
* @throws java.lang.Exception
*/
@Test
public void testDoOCR_BufferedImage() throws Exception {
System.out.println("doOCR on a buffered image of a GIF");
String filename = String.format("%s/%s", this.testResourcesDataPath, "eurotext.gif");
System.out.println("doOCR on a buffered image of a PNG");
String filename = String.format("%s/%s", this.testResourcesDataPath, "eurotext.png");
File imageFile = new File(filename);
BufferedImage bi = ImageIO.read(imageFile);
String expResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78 <lazy> #90 dog";
Expand All @@ -140,6 +165,7 @@ public void testDoOCR_BufferedImage() throws Exception {

/**
* Test of deskew algorithm.
*
* @throws java.lang.Exception
*/
@Test
Expand Down
Binary file removed src/test/resources/test-data/eurotext.gif
Binary file not shown.
Binary file added src/test/resources/test-data/eurotext_unlv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/test/resources/test-data/eurotext_unlv.uzn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
97 162 747 50 ThirdLine
97 209 828 55 FourthLine
92 56 810 107 First2Line2

0 comments on commit 7154fbd

Please sign in to comment.