使用Android上的Tesseract为每个角色获取边界框

时间:2014-05-08 09:21:45

标签: android eclipse image-processing tesseract

我成功地使用Tesseract库从图像中提取文本。现在我想要实现的是从每个角色的边界框中对每个角色进行分割。我就像编写一些教程一样编写代码,这里是我的源代码:

String SourceImage = cursor.getString(URIImage);
Bitmap OutputImagePicker = BitmapFactory.decodeFile(SourceImage); 

TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setDebug(true);
baseApi.init(Path, Language);
baseApi.setImage(OutputImagePicker);
String Text = baseApi.getUTF8Text();

final ResultIterator iterator = baseApi.getResultIterator();
String lastUTF8Text;
     float lastConfidence;
     int[] lastBoundingBox;
     int count = 0;
     iterator.begin();
     do {
         lastUTF8Text = iterator.getUTF8Text(PageIteratorLevel.RIL_WORD);
         lastConfidence = iterator.confidence(PageIteratorLevel.RIL_WORD);
         lastBoundingBox = iterator.getBoundingBox(PageIteratorLevel.RIL_WORD);
         count++;
         } 
     while (iterator.next(PageIteratorLevel.RIL_WORD));

 baseApi.end(); 

 RecognizedText.setText(Text);
 ImageOutput.setImageBitmap(OutputImagePicker);

但是,结果是图片位图没有行边界框???我的来源有什么问题?我很困惑,我已经搜索了一些关于此的教程,但是没有人解释它。有谁知道如何实现它???请????

EDITED

我从Nguyenq得到了建议,我需要在lastBoundingBox中使用coordinat绘制rect,这是我的代码来绘制它:

      Canvas canvas = new Canvas(OutputImagePicker);

      // Draw bounding boxes around each word         
      for (int i = 0; i < lastBoundingBox.length; i++) {
        paint.setAlpha(0xFF);
        paint.setColor(Color.RED);
        paint.setStyle(Style.STROKE);
        paint.setStrokeWidth(2);
        int Rect = lastBoundingBox.length;
        canvas.drawRect(Rect, paint);
      } 

但是,它仍然会出错,它说&#34; Canvas类型中的方法drawRect(Rect Paint)不适用于参数int paint&#34;,如下所示,....我应该怎么做做????

0 个答案:

没有答案