資源簡介
Java使用Tess4J 進行圖片文字識別

代碼片段和文件信息
/**
?*?JDeskew
?*/
package?com.recognition.software.jdeskew;
import?java.awt.image.BufferedImage;
public?class?ImageDeskew?{
????/**
?????*?Representation?of?a?line?in?the?image.
?????*/
????public?class?HoughLine?{
????????//?count?of?points?in?the?line
????????public?int?count?=?0;
????????//?index?in?matrix.
????????public?int?index?=?0;
????????//?the?line?is?represented?as?all?x?y?that?solve?y?*?cos(alpha)?-?x?*
????????//?sin(alpha)?=?d
????????public?double?alpha;
????????public?double?d;
????}
????//?the?source?image
????private?BufferedImage?cImage;
????//?the?range?of?angles?to?search?for?lines
????private?double?cAlphaStart?=?-20;
????private?double?cAlphaStep?=?0.2;
????private?int?cSteps?=?40?*?5;
????//?pre-calculation?of?sin?and?cos
????private?double[]?cSinA;
????private?double[]?cCosA;
????//?range?of?d
????private?double?cDMin;
????private?double?cDStep?=?1.0;
????private?int?cDCount;
????//?count?of?points?that?fit?in?a?line
????private?int[]?cHMatrix;
????//?constructor
????public?ImageDeskew(BufferedImage?image)?{
????????this.cImage?=?image;
????}
????//?calculate?the?skew?angle?of?the?image?cImage
????public?double?getSkewAngle()?{
????????ImageDeskew.HoughLine[]?hl;
????????double?sum?=?0.0;
????????int?count?=?0;
????????//?perform?Hough?Transformation
????????calc();
????????//?top?20?of?the?detected?lines?in?the?image
????????hl?=?getTop(20);
????????if?(hl.length?>=?20)?{
????????????//?average?angle?of?the?lines
????????????for?(int?i?=?0;?i?19;?i++)?{
????????????????sum?+=?hl[i].alpha;
????????????????count++;
????????????}
????????????return?(sum?/?count);
????????}?else?{
????????????return?0.0d;
????????}
????}
????//?calculate?the?count?lines?in?the?image?with?most?points
????private?ImageDeskew.HoughLine[]?getTop(int?count)?{
????????ImageDeskew.HoughLine[]?hl?=?new?ImageDeskew.HoughLine[count];
????????for?(int?i?=?0;?i?????????????hl[i]?=?new?ImageDeskew.HoughLine();
????????}
????????ImageDeskew.HoughLine?tmp;
????????for?(int?i?=?0;?i?(this.cHMatrix.length?-?1);?i++)?{
????????????if?(this.cHMatrix[i]?>?hl[count?-?1].count)?{
????????????????hl[count?-?1].count?=?this.cHMatrix[i];
????????????????hl[count?-?1].index?=?i;
????????????????int?j?=?count?-?1;
????????????????while?((j?>?0)?&&?(hl[j].count?>?hl[j?-?1].count))?{
????????????????????tmp?=?hl[j];
????????????????????hl[j]?=?hl[j?-?1];
????????????????????hl[j?-?1]?=?tmp;
????????????????????j--;
????????????????}
????????????}
????????}
????????int?alphaIndex;
????????int?dIndex;
????????
????????for?(int?i?=?0;?i?????????????dIndex?=?hl[i].index?/?cSteps;?//?integer?division?no
????????????//?remainder
????????????alphaIndex?=?hl[i].index?-?dIndex?*?cSteps;
????????????hl[i].alpha?=?getAlpha(alphaIndex);
????????????hl[i].d?=?dIndex?+?cDMin;
????????}
????????re
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-09-22?11:07??Tess4J\
?????目錄???????????0??2013-09-22?11:07??Tess4J\dist\
?????目錄???????????0??2013-09-21?08:34??Tess4J\lib\
?????目錄???????????0??2013-09-21?08:35??Tess4J\nbproject\
?????目錄???????????0??2013-02-28?22:17??Tess4J\nbproject\private\
?????目錄???????????0??2013-02-28?22:17??Tess4J\src\
?????目錄???????????0??2013-02-28?22:17??Tess4J\src\com\
?????目錄???????????0??2013-02-28?22:17??Tess4J\src\com\recognition\
?????目錄???????????0??2013-02-28?22:17??Tess4J\src\com\recognition\software\
?????目錄???????????0??2013-02-28?22:17??Tess4J\src\com\recognition\software\jdeskew\
?????目錄???????????0??2013-02-28?22:17??Tess4J\src\net\
?????目錄???????????0??2013-09-21?12:06??Tess4J\src\net\sourceforge\
?????目錄???????????0??2013-09-21?12:06??Tess4J\src\net\sourceforge\tess4j\
?????目錄???????????0??2013-09-21?12:06??Tess4J\src\net\sourceforge\vietocr\
?????目錄???????????0??2013-09-21?12:12??Tess4J\tessdata\
?????目錄???????????0??2013-02-28?22:17??Tess4J\tessdata\configs\
?????目錄???????????0??2013-02-28?22:17??Tess4J\test\
?????目錄???????????0??2013-02-28?22:17??Tess4J\test\net\
?????目錄???????????0??2013-09-21?08:52??Tess4J\test\net\sourceforge\
?????目錄???????????0??2013-09-21?08:52??Tess4J\test\net\sourceforge\tess4j\
?????目錄???????????0??2013-09-21?08:52??Tess4J\test\net\sourceforge\tess4j\utiltities\
?????文件????????5153??2013-08-31?10:01??Tess4J\build.xm
?????文件????????1322??2013-09-22?11:07??Tess4J\dist\README.TXT
?????文件???????69037??2013-09-22?11:07??Tess4J\dist\tess4j.jar
?????文件??????102464??2013-02-28?22:17??Tess4J\eurotext.bmp
?????文件???????20359??2013-02-28?22:17??Tess4J\eurotext.gif
?????文件???????13065??2013-02-28?22:17??Tess4J\eurotext.pdf
?????文件???????14854??2013-02-28?22:17??Tess4J\eurotext.png
?????文件??????102598??2013-02-28?22:17??Tess4J\eurotext.tif
?????文件??????204383??2013-02-28?22:17??Tess4J\eurotext_deskew.png
?????文件???????31679??2013-02-28?22:17??Tess4J\lib\ghost4j-0.3.1.jar
............此處省略35個文件信息
評論
共有 條評論