Skip to content

Commit

Permalink
updated Javadoc for Tesseract config and parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarana-Parekh committed Jun 30, 2016
1 parent bc6667c commit 6773d42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,14 @@ public void setTimeout(int timeout) {
this.timeout = timeout;
}

/** @see #setTimeout(int timeout)*/
/** @see #setTimeout(int timeout)
* @return timeout value for Tesseract */
public int getTimeout() {
return timeout;
}

/** @see #setEnableImageProcessing(boolean) */
/** @see #setEnableImageProcessing(boolean)
* @return image processing is enabled or not */
public int isEnableImageProcessing() {
return enableImageProcessing;
}
Expand All @@ -282,12 +284,12 @@ public int getDensity() {
}

/**
* @param density the density to set
* @param density the density to set. Valid range of values is 150-1200.
* Default value is 300.
*/
public void setDensity(int density) {
if(density < 150 || density > 1200) {
throw new IllegalArgumentException("Invalid density value");
throw new IllegalArgumentException("Invalid density value. Valid range of values is 150-1200.");
}
this.density = density;
}
Expand All @@ -300,7 +302,7 @@ public int getDepth() {
}

/**
* @param depth the depth to set
* @param depth the depth to set. Valid values are 2, 4, 8, 16, 32, 64, 256, 4096.
* Default value is 4.
*/
public void setDepth(int depth) {
Expand All @@ -311,7 +313,7 @@ public void setDepth(int depth) {
return;
}
}
throw new IllegalArgumentException("Invalid depth value");
throw new IllegalArgumentException("Invalid depth value. Valid values are 2, 4, 8, 16, 32, 64, 256, 4096.");
}

/**
Expand All @@ -329,7 +331,7 @@ public void setColorspace(String colorspace) {
if(!colorspace.equals(null)) {
this.colorspace = colorspace;
} else {
throw new IllegalArgumentException("Invalid colorspace value");
throw new IllegalArgumentException("Colorspace value cannot be null.");
}
}

Expand All @@ -341,12 +343,13 @@ public String getFilter() {
}

/**
* @param filter the filter to set
* @param filter the filter to set. Valid values are point, hermite, cubic, box, gaussian, catrom, triangle, quadratic and mitchell.
* Default value is triangle.
*/
public void setFilter(String filter) {
if(filter.equals(null)) {
throw new IllegalArgumentException("Invalid filter value");
throw new IllegalArgumentException("Filter value cannot be null. Valid values are point, hermite, "
+ "cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
}

String[] allowedFilters = {"Point", "Hermite", "Cubic", "Box", "Gaussian", "Catrom", "Triangle", "Quadratic", "Mitchell"};
Expand All @@ -356,7 +359,8 @@ public void setFilter(String filter) {
return;
}
}
throw new IllegalArgumentException("Invalid filter value");
throw new IllegalArgumentException("Invalid filter value. Valid values are point, hermite, "
+ "cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
}

/**
Expand All @@ -367,7 +371,7 @@ public int getResize() {
}

/**
* @param resize the resize to set
* @param resize the resize to set. Valid range of values is 100-900.
* Default value is 900.
*/
public void setResize(int resize) {
Expand All @@ -377,17 +381,19 @@ public void setResize(int resize) {
return;
}
}
throw new IllegalArgumentException("Invalid resize value");
throw new IllegalArgumentException("Invalid resize value. Valid range of values is 100-900.");
}

/** @see #setImageMagickPath(String ImageMagickPath)*/
/** @see #setImageMagickPath(String ImageMagickPath)
* @return path to ImageMagick file. */
public String getImageMagickPath() {

return ImageMagickPath;
}

/**
* Set the path to the ImageMagick executable, needed if it is not on system path.
* @param path to ImageMagick file.
*/
public void setImageMagickPath(String ImageMagickPath) {
if(!ImageMagickPath.isEmpty() && !ImageMagickPath.endsWith(File.separator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean hasTesseract(TesseractOCRConfig config) {

}

public boolean hasImageMagick(TesseractOCRConfig config) {
private boolean hasImageMagick(TesseractOCRConfig config) {
// Fetch where the config says to find ImageMagick Program
String ImageMagick = config.getImageMagickPath() + getImageMagickProg();

Expand All @@ -155,7 +155,7 @@ public boolean hasImageMagick(TesseractOCRConfig config) {

}

public boolean hasPython() {
private boolean hasPython() {
// check if python is installed and if the rotation program path has been specified correctly

boolean hasPython = false;
Expand Down Expand Up @@ -261,8 +261,8 @@ public void parseInline(InputStream stream, XHTMLContentHandler xhtml, Tesseract
* This method is used to process the image to an OCR-friendly format.
* @param streamingObject input image to be processed
* @param config TesseractOCRconfig class to get ImageMagick properties
* @throws IOException
* @throws TikaException
* @throws IOException if an input error occurred
* @throws TikaException if an exception timed out
*/
private void processImage(File streamingObject, TesseractOCRConfig config) throws IOException, TikaException {

Expand Down Expand Up @@ -292,7 +292,10 @@ private void processImage(File streamingObject, TesseractOCRConfig config) throw
}

// process the image - parameter values can be set in TesseractOCRConfig.properties
String line = "convert -density " + config.getDensity() + " -depth " + config.getDepth() + " -colorspace " + config.getColorspace() + " -filter " + config.getFilter() + " -resize " + config.getResize() + "% -rotate "+ angle + " " + streamingObject.getAbsolutePath() + " " + streamingObject.getAbsolutePath();
String line = "convert -density " + config.getDensity() + " -depth " + config.getDepth() +
" -colorspace " + config.getColorspace() + " -filter " + config.getFilter() +
" -resize " + config.getResize() + "% -rotate "+ angle + " " + streamingObject.getAbsolutePath() +
" " + streamingObject.getAbsolutePath();
cmdLine = CommandLine.parse(line);
try {
executor.execute(cmdLine);
Expand Down

0 comments on commit 6773d42

Please sign in to comment.