I've been struggling to make the tess-two OCR project work, and when I finally did, it did recognize text when it's clear and when there are multiple lines there.
The whole point of this is that I need to use OCR to extract credit card number when the user takes a photo of it.
Here is an example of a credit card number:
This is just an example I used many pictures. for instance with this image I got the following text:
1238 5578 8875 5877
1238 5578 8875 5877
1238 5578 8875 5877
Here is the code I use for this:
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init("/mnt/sdcard/tesseract-ocr", "eng");
baseApi.setImage(bm);
baseApi.setPageSegMode(6);
String whiteList = "/1234567890";
baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, whiteList);
String recognizedText = baseApi.getUTF8Text();
baseApi.end();
Any help would be much appreciated.
Thanks !
Maybe some preprocessing steps of the image would make tesseract have a better performance.
I could suggest you a whole paper(http://wbieniec.kis.p.lodz.pl/research/files/07_memstech_ocr.pdf)
If you have time, if not, try to play with the image's contrast for example.
Here are also some ideas that can fit your issue:
http://www.ocr-it.com/user-scenario-process-digital-camera-pictures-and-ocr-to-extract-specific-numbers
Example images are allready fit for OCR, but as far as i see you're using tesseract's built-in "eng.traineddata" model and its not suitable (in terms of accuracy / performance) for credit card scanning. (Credit cards use the font "OCR-A"). Thus you'll need to either find pretrained model and replace it on initialization of tessApi or train it yourself from stratch.
For training tesseract model with custom font, see Yash Modi's answer at
here
Related
I need a (really fast) way to check if a JPG file is in RGB format (or any other format that Android can show).
Actually, at this moment, I just know if a JPG file can be show when I try to convert it to Bitmap using BitmapFactory.
I think this should not be the fastest way. So I try to get it by using ExifInterface. Unfortunately, ExifInterface (from Android) does not have any tag that indicates that the jpg can be shown in Android (color space tag or something).
Then, I think I have 2 ways:
1) A fast way to get bitmap from jpg: any tip of how to do it?
2) Or try to read Exif tags by my self, but without adding any other lib to the project: I don't have any idea of how to do it!
Ok so I did some looking around and I may have a solution for you but it may require a little work. The link is a pure java library that I think you can use in your project or at least modify and include a few classes. I have not worked with this yet but it looks like it will work.
http://commons.apache.org/proper/commons-imaging
final ImageInfo imageInfo = Imaging.getImageInfo(File file);
if(imageInfo.getColorType() == ImageInfo.COLOR_TYPE_CMYK){
}
else {
}
My goal is to validate some XML document against Schematron file in Android.
At the moment I am trying to use this library for Java.
So far, it doesn't seem to be working at all, I simply get empty array as the result of transform. This is piece of code from the library method I adjusted a bit.
Source xsltSource = (Source) jur.resolve( "iso_svrl_for_xslt2.xsl", null );
Source schemaSource = new StreamSource(this.schemaAsStream);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltSource);
transformer.transform(xsltSource, new StreamResult( baos ));
Does anyone have an idea how to get Transformer working for Android?
Thanks in advance.
The Extensible Stylesheet Language Transformations (XSLT) APIs can be used for many purposes. For example, with a sufficiently intelligent stylesheet, you could generate PDF or PostScript output from the XML data. But generally, XSLT is used to generate formatted HTML output (that we can consume in our Android Webview), or to create an alternative XML representation of the data. This will help you.
I've been trying to figure out how to display a photo on Android. I can create an ImageView and display a picture, but the functionality is limited (no zoom, pan or share). Is there a demo or tutorial with code out there on how to do this? I've been searching all week with no luck.
Thanks.
P.S.> Please No Snark!
Maybe I don't understand how to create a uri correctly or how to make my resource available to the viewer. I have a resource ID, R.drawable.opal, I'm using to display different minerals and gems for a science project. If the student clicks the small sample photo, then I want to bring up a bigger and better viewer for the photo to allow them to compare to their collected rock.
Unless you really need to build your own you should probably just use the gallery's viewer. Send it the picture by using the view intent like so:
Intent viewImageIntent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(viewImageIntent);
Replace "uri" with the image's uri of course. Writing your own viewer is really involved and would include threading, physics calculations and handling touch inputs.
HI,
I am currently studying how Android decode and image file. When I checked the code, it seems like it is calling the SKIA library. But, how do I know what are the image file format supported by android/skia basing on the source code?
I am not an expert in programming, so I am still trying to understand C++ and Java language.
I am now lost at SkImageDecoder* decoder = SkImageDecoder::Factory(stream); inside the BitmapFactory.cpp (JNI file). SkImageDecoder::Factory(stream) seems to be a template.
Anyone can explain me what is happening inside SKImageDecoder::Factory()? Any feedback will be greatly appreciated.
Thanks,
artsylar
In skia/include/images/SkImageDecoder.h file, there is the image list decoding supported by Skia:
enum Format {
kUnknown_Format,
kBMP_Format,
kGIF_Format,
kICO_Format,
kJPEG_Format,
kPNG_Format,
kWBMP_Format,
kWEBP_Format,
kLastKnownFormat = kWEBP_Format
};
In SkImageDecoder::Factory(stream) function, it will new a decoder instance according to analyze the Stream's header.
By looking at the source codes of Android, I think the following image formats are supported.
ICO (Windows ICON image format), BMP, JPEG, WBMP, GIF, and PNG.
Please correct me if I am wrong. Thank you.
PNG, JPEG, and GIF are the supported formats. The primary formats used on Android are PNG and JPEG.
I guess this question has been asked before, but I can't seem to find a proper answer/solution.
Have a note-taking app, which allows to take pictures. For that I start an intent, that starts up the built-in camera-app. So far so good.
But when I show that image in my app, it's in a much smaller format :(
The funny/weird thing is, that the camera-app did take a full-resolution picture! But for some reason I can't get the full version to show in my app???
So, when I use the standard Android Gallery app, and go to that picture, it is very obvious that it's full size (I can zoom in and see details I really can't see when I zoom in, in my own app). Also, the dimensions are really those of the original picture, taken with the 5MP camera.
In my app, they are very small. My phone has Android 2.2, but the same happens on my emulator (Android 2.1).
How should I retrieve the pictures in my app??? Tried a couple of ways, but none works :( Don't need a complete example (allthough that's very welcome), just a few clues are enough to search for myself.
Tx in advance!!
Greetingz,
Koen<
Very weird, I found the solution/answer by looking at the _ID-values that were being inserted in my own database. First I noticed that when I selected an existing image (via the build-in Android Gallery), I did get the full size image.
When I first took a picture, I got a scaled image. So where was the difference. Apparantly at the location where the _ID of the picture got stored in my database. In my case, and probably most cases, this happens in the onActivityResult procedure.
First take a look at what I initially had:
if(requestCode == REQUEST_CAMERA && resultCode == RESULT_OK){
String timestamp = Long.toString(System.currentTimeMillis());
// get the picture
mPicture = (Bitmap)result.getExtras().get("data");
//save image to gallery
String pictureUrl = MediaStore.Images.Media.insertImage(getContentResolver(), mPicture, getResources().getString(R.string.app_name_short), timestamp);
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(Uri.parse(pictureUrl).getLastPathSegment()));
The "insertPictureAttachment"-method does the actual inserting into the database.
Looking backwards, this was a bit weird anyway ... make a picture, so I could make an URI of it, and then get the last path segment (which is the _ID), so I could insert that into my database.
Eventually, it turns out that I can replace the above code with just one line:
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(result.getData().getLastPathSegment()));
Much shorter, and actually makes more sense ... rather than getting the info from result.getExtras().get("data"), I get my info from result.getData(), which gives the _ID of the original, full-size image.
I will do some further research on this though, cause it's not clear to me yet why I actually don't have to call MediaStore.Images.Media.insertImage(...) ... maybe I will have to if I want specific features (like a custom file location or something like that).
Greetingz,
Koen<