2013-04-02 58 views
0

我正試圖在tess4j分配中運行當前的單元測試。致命錯誤:無法寫入核心轉儲

TessBaseAPIGetIterator 
# 
# A fatal error has been detected by the Java Runtime Environment: 
# 
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6718f834, pid=5612, tid=3592 
# 
# JRE version: 7.0_17-b02 
# Java VM: Java HotSpot(TM) Client VM (23.7-b01 mixed mode, sharing windows-x86) 
# Problematic frame: 
# C [libtesseract302.dll+0xf834] tesseract::TessBaseAPI::Init+0x34 
# 
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows 
# 
# An error report file with more information is saved as: 
# G:\Final year project\eclipse stuff\Testings\hs_err_pid5612.log 
# 
# If you would like to submit a bug report, please visit: 
# http://bugreport.sun.com/bugreport/crash.jsp 
# The crash happened outside the Java Virtual Machine in native code. 
# See problematic frame for where to report the bug. 
# 

我能請得到的幫助:雖然運行單元測試之一,JAVA,出現以下錯誤崩潰?我相當確信該DLL文件沒有損壞,我的硬盤也不是。我使用Windows 8操作系統和最新版本的eclipse來構建項目。

的代碼是:

import java.io.File; 
import net.sourceforge.tess4j.*; 

import com.sun.jna.Pointer; 
import com.sun.jna.ptr.PointerByReference; 
import java.awt.image.BufferedImage; 
import java.io.*; 
import java.nio.*; 
import java.util.Arrays; 
import javax.imageio.ImageIO; 
    import net.sourceforge.tess4j.TessAPI1.*; 
import net.sourceforge.vietocr.ImageIOHelper; 
import org.junit.After; 
import org.junit.AfterClass; 
import org.junit.Before; 
import org.junit.BeforeClass; 
import org.junit.Test; 
import static org.junit.Assert.*; 

public class TesseractExample{ 
String datapath = "G:\\Final year project\\eclipse stuff\\tessdemo\\tessdata"; 
String language = "eng"; 
String expOCRResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78 <lazy> #90 dog"; 

TessAPI1.TessBaseAPI handle; 

public void testResultIterator() throws Exception { 
    System.out.println("TessBaseAPIGetIterator"); 
    String lang = "eng"; 
    File tiff = new File("eurotext.tif"); 
    BufferedImage image = ImageIO.read(new FileInputStream(tiff)); // require jai-imageio lib to read TIFF 
    ByteBuffer buf = ImageIOHelper.convertImageData(image); 
    int bpp = image.getColorModel().getPixelSize(); 
    int bytespp = bpp/8; 
    int bytespl = (int) Math.ceil(image.getWidth() * bpp/8.0); 
    TessAPI1.TessBaseAPIInit3(handle, datapath, lang); 
    TessAPI1.TessBaseAPISetPageSegMode(handle, TessAPI1.TessPageSegMode.PSM_AUTO); 
    TessAPI1.TessBaseAPISetImage(handle, buf, image.getWidth(), image.getHeight(), bytespp, bytespl); 
    TessAPI1.TessBaseAPIRecognize(handle, null); 
    TessAPI1.TessResultIterator ri = TessAPI1.TessBaseAPIGetIterator(handle); 
    TessAPI1.TessPageIterator pi = TessAPI1.TessResultIteratorGetPageIterator(ri); 
    TessAPI1.TessPageIteratorBegin(pi); 
    System.out.println("Bounding boxes:\nchar(s) left top right bottom confidence font-attributes"); 

    int height = image.getHeight(); 
    do { 
     Pointer ptr = TessAPI1.TessResultIteratorGetUTF8Text(ri, TessAPI1.TessPageIteratorLevel.RIL_WORD); 
     String word = ptr.getString(0); 
     TessAPI1.TessDeleteText(ptr); 
     float confidence = TessAPI1.TessResultIteratorConfidence(ri, TessAPI1.TessPageIteratorLevel.RIL_WORD); 
     IntBuffer leftB = IntBuffer.allocate(1); 
     IntBuffer topB = IntBuffer.allocate(1); 
     IntBuffer rightB = IntBuffer.allocate(1); 
     IntBuffer bottomB = IntBuffer.allocate(1); 
     TessAPI1.TessPageIteratorBoundingBox(pi, TessAPI1.TessPageIteratorLevel.RIL_WORD, leftB, topB, rightB, bottomB); 
     int left = leftB.get(); 
     int top = topB.get(); 
     int right = rightB.get(); 
     int bottom = bottomB.get(); 
     System.out.print(String.format("%s %d %d %d %d %f", word, left, top, right, bottom, confidence)); 
     System.out.println(String.format("%s %d %d %d %d", str, left, height - bottom, right, height - top)); // training box coordinates  

     IntBuffer boldB = IntBuffer.allocate(1); 
     IntBuffer italicB = IntBuffer.allocate(1); 
     IntBuffer underlinedB = IntBuffer.allocate(1); 
     IntBuffer monospaceB = IntBuffer.allocate(1); 
     IntBuffer serifB = IntBuffer.allocate(1); 
     IntBuffer smallcapsB = IntBuffer.allocate(1); 
     IntBuffer pointSizeB = IntBuffer.allocate(1); 
     IntBuffer fontIdB = IntBuffer.allocate(1); 
     String fontName = TessAPI1.TessResultIteratorWordFontAttributes(ri, boldB, italicB, underlinedB, 
       monospaceB, serifB, smallcapsB, pointSizeB, fontIdB); 
     boolean bold = boldB.get() == TessAPI1.TRUE; 
     boolean italic = italicB.get() == TessAPI1.TRUE; 
     boolean underlined = underlinedB.get() == TessAPI1.TRUE; 
     boolean monospace = monospaceB.get() == TessAPI1.TRUE; 
     boolean serif = serifB.get() == TessAPI1.TRUE; 
     boolean smallcaps = smallcapsB.get() == TessAPI1.TRUE; 
     int pointSize = pointSizeB.get(); 
     int fontId = fontIdB.get(); 
     System.out.println(String.format(" font: %s, size: %d, font id: %d, bold: %b," + 
        " italic: %b, underlined: %b, monospace: %b, serif: %b, smallcap: %b", 
       fontName, pointSize, fontId, bold, italic, underlined, monospace, serif, smallcaps));    
    } while (TessAPI1.TessPageIteratorNext(pi, TessAPI1.TessPageIteratorLevel.RIL_WORD) == TessAPI1.TRUE); 


} 

public static void main(String[] args) { 
    TesseractExample instance=new TesseractExample(); 

    try { 

instance.testResultIterator(); 

    } catch (Exception e) { 
     System.err.println(e.getMessage()); 
    } 
} 
} 

謝謝!

回答

0

看起來像handle尚未初始化。

handle = TessAPI1.TessBaseAPICreate(); 
+0

非常感謝! :) –