问题
Basically am designing an application that will capture an image from the android devices default camera and will display that image in an image view! works fine! good enough!
capt_but.setOnClickListener(new View.OnClickListener()
{
//@Override
// TODO Auto-generated method stub
public void onClick(View v)
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
My next task is to apply tess4j OCR functionality that will basically extract characters from the image i captured! tess4j is basically a java wrapper for the tesseract OCR! Am Programming in ECLIPSE! Here is the link for it!
tess4j.sourceforge.net
I added all the jars i could find in the open source files and added them to a folder i made that is lib to the main project directory in eclipse! i selected them all and also added them to build path!
then i copied all the dll's i could find to the main project directory! Then using one example on the same link above i programmed my code as follows:
public void myfunction(Intent data)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
File imageFile = new File("myimage.tif");
try
{
String result = instance.doOCR(imageFile)
System.out.println(result);
}
catch (TesseractException e)
{
System.err.println(e.getMessage());
}
}
My project is picking up the tesseract jar's and is enabling me to browse function directory on . operator! However on line,
String result = instance.doOCR(imageFile)
am getting the error that is:
The type java.awt.image.BufferedImage cannot be resolved. It is indirectly referenced from required .class files
the quick fix is: Configure build path!
I cnt figure out what is the problem! am trying hard to figure out the problem! am i missing something from the steps i mentioned above? the tess4j i downloaded also had other files! kindly helper download the tess4j from the link above to examine the files that are in the download! any xml problem? or any build path problem??
回答1:
The type java.awt.image.BufferedImage cannot be resolved.
From that error message, it seems that BufferedImage
class is not supported on Android platform. Android API does not include the java.awt.image
package.
回答2:
As others have said BufferedImage
is not supported by Android platform.
The solution is to use Tess-two, which is Tess4j equivalent Tesseract wrapper api for android.
For Ref: OCR in android using tess-two
Though this is pretty old, sharing so that others may find it useful.
回答3:
I know this question is really old. But to fix your error navigate to properties>java build path> Libraries> Add Library and include JRE system library. :)
来源:https://stackoverflow.com/questions/13198909/ocr-for-android-application-tess4j