Giter Club home page Giter Club logo

Comments (28)

DoDoENT avatar DoDoENT commented on August 16, 2024

Hi CroatianIDFrontSide is an example which shows how Templating API can be used to scan any document. You can modify it as you wish for your use case. The documentation for Templating API can help you understand what is being done inside the demo and demo is there to back the documentation with well-commented example.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

Ok, I will try it. Now we just close the issue, after that if got any problem, I will reopen or create another issue, is that ok?

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

Sure.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

OK thanks alot.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

already defined DetectorSettings
Hi, I already follow the step but still not working. I
already set BlinkOCRRecognizerSettings
already set setDecodingInfos
I just want to scan one kind of the card so i skip then Classifier Class.

But now, when I want to scan the card, the screen do not have any respond, means never scan the card.
May I know what are the steps that missed cause it cannot scan the card?
How to get the result after the scan done?

thank you

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

Does the demo app work for you? Can you provide a minimal Android Studio project which demonstrates the issue?

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

Can I post the code for the template class I created to let you check?

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

Please do so.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

public class CustomiseCard {
private static final String NAME = "name";
private static final String PASSPORT_NUMBER = "passportNumber";
private static final String DATE_OF_BIRTH = "dateOfBirth";
private static final String GENDER = "gender";
private static final String ADDRESS = "address";
private static final String CARD = "card";
private static final String TAG = "CustomiseCard";

private static void setupName(TemplatingRecognizerSettings settings, List<DecodingInfo> card){


    //String name = firstName ? NAME : NAME;
    String name = NAME;
    //int dewarpHeight = firstName ? 150:100;
   /**
    * For extracting first and last names, we will use regex parser with regular expression which
    * attempts to extract as may uppercase words as possible from single line.
    */
    RegexParserSettings nameParser = new RegexParserSettings("([A-Z]+ ?)+");

    /**
     * add parser to parser group
     */
    settings.addParserToParserGroup(name, name, nameParser);

    Rectangle locationName = new Rectangle(0.565f, 0.259f, 0.412f, 0.056f);
    card.add(new DecodingInfo(locationName, 350, name ));
}

private static void setupDateOfBirth(TemplatingRecognizerSettings settings, List<DecodingInfo> card){
    card.add(new DecodingInfo(new Rectangle(0.565f, 0.389f, 0.176f, 0.056f),150, DATE_OF_BIRTH));

    settings.addParserToParserGroup(DATE_OF_BIRTH,DATE_OF_BIRTH, new DateParserSettings());
}

private static void setupPassportNumber(TemplatingRecognizerSettings settings, List<DecodingInfo> card){
    card.add(new DecodingInfo(new Rectangle(0.565f, 0.315f, 0.412f, 0.056f), 350, PASSPORT_NUMBER));

    RegexParserSettings documentNumberParser = new RegexParserSettings("\\d{9}");
    settings.addParserToParserGroup(PASSPORT_NUMBER,PASSPORT_NUMBER,documentNumberParser );
}

private static void setupAddress(TemplatingRecognizerSettings settings, List<DecodingInfo> card){
    card.add(new DecodingInfo(new Rectangle(0.565f, 0.556f, 0.412f, 0.241f), 350, ADDRESS));

    RegexParserSettings passportParser = new RegexParserSettings("([A-Z]+ ?)+");
    settings.addParserToParserGroup(PASSPORT_NUMBER,PASSPORT_NUMBER,passportParser );
}

private static void setupGender(TemplatingRecognizerSettings settings, List<DecodingInfo> card) {
    card.add(new DecodingInfo(new Rectangle(0.565f, 0.389f, 0.176f, 0.056f), 150, GENDER));

    RegexParserSettings genderParser = new RegexParserSettings("[M]/[F]");
    settings.addParser(GENDER, genderParser);
    genderParser.getOcrEngineOptions().addCharToWhitelist('M', OcrFont.OCR_FONT_ANY)
            .addCharToWhitelist('F', OcrFont.OCR_FONT_ANY);
    genderParser.setMustEndWithWhitespace(true);
    genderParser.setMustStartWithWhitespace(true);

    settings.addParserToParserGroup(GENDER,GENDER, genderParser);
}

public static BlinkOCRRecognizerSettings buildICardRecogniserSettings(){
    BlinkOCRRecognizerSettings settings = new BlinkOCRRecognizerSettings();

    List<DecodingInfo> cardDecodingInfos =  new ArrayList<>();
    setupName(settings, cardDecodingInfos);
    setupDateOfBirth(settings, cardDecodingInfos);
    setupPassportNumber(settings, cardDecodingInfos);
    setupAddress(settings, cardDecodingInfos);
    setupGender(settings, cardDecodingInfos);

    // setup card detector
    DocumentSpecification idSpec = DocumentSpecification.createFromPreset(DocumentSpecificationPreset.DOCUMENT_SPECIFICATION_PRESET_ID1_CARD);

    /*// set decoding info objects inherent to this document specification
    idSpec.setDecodingInfos(TemplatingUtils.listToArray(classificationDecodingInfos));*/

    // create card detector with single document specification
    DocumentDetectorSettings dds = new DocumentDetectorSettings(new DocumentSpecification[]{idSpec});

    // ensure this detector will be used when performing object detection
    settings.setDetectorSettings(dds);

    settings.setParserDecodingInfos(TemplatingUtils.listToArray( cardDecodingInfos),CARD );

    settings.setAllowFlippedRecognition(true);
    return settings;
}

}

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

cannot upload the file because not supported by github even I compressed it become zip file. So i post it in the comment.

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

From the quick look, the offending line would be

 /*// set decoding info objects inherent to this document specification
 idSpec.setDecodingInfos(TemplatingUtils.listToArray(classificationDecodingInfos));*/

This line is commented-out in your code, yet it contains decoding infos which are essential to determine the type of document, see the documentation. If you are only targeting single type of document, then decoding infos should be set in commented-out line. If you are targeting multiple types of documents, then with this line you set the decoding infos of locations which you use for classification of the document and then after classifier returns the classification result, you use decoding infos for that type of document set with setParserDecodingInfos.

Basically, this means that in your code, you should this line

settings.setParserDecodingInfos(TemplatingUtils.listToArray( cardDecodingInfos),CARD );

replace with this line:

idSpec.setDecodingInfos(TemplatingUtils.listToArray(cardDecodingInfos));

Just make sure you set decoding infos to IDSpec before using it to create DocumentDetectorSettings.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

Oh yea.. its work!! now got respond already. But now it cannot recognize the card. I will prompt out a dialog ask me to re-scan the card if it cannot be recognize.
Is it because the position of the information that I want to scan not match with the exact value of the information on the card?

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

and for the position of the address, basically address have few lines in identity card, so it will auto scan through all the lines in the position?

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

and one more question is can I straight away use the MyKadRecognitionResult after the scanning done? If can, I just change the name in the template?

for example:

private static final String NAME = "name";

change to

private static final String NAME = "ownerFullName";

ownerFullName is the name get from MyKadRecognitionResult class

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

Is it because the position of the information that I want to scan not match with the exact value of the information on the card?

Yes, you need to define locations very precisely. Also, if card is mis-detected, then relative positions are also calculated incorrectly. You should take this into account.

and for the position of the address, basically address have few lines in identity card, so it will auto scan through all the lines in the position?

The OCR is performed on entire decoding location. For filtering-out patterns you truly need, you should define a good regular expression in regex parser or use specialised parsers, like date parser.

and one more question is can I straight away use the MyKadRecognitionResult after the scanning done?

MyKadRecognitionResult is result of MyKad recognizer. After obtaining the result of your card, you can reconfigure RecognizerView and set it to use only MyKad recognizer.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

Yes, you need to define locations very precisely.

the spacing between 2 information I want to get is only 1-2mm only, is it too small? the calculation I made I just take 3 decimal places which are follow the template.

MyKadRecognitionResult is result of MyKad recognizer. After obtaining the result of your card, you can reconfigure RecognizerView and set it to use only MyKad recognizer.

So I need to create my own RecognitionResult class? and inside the class add all the method for example getName(), getAddress(), etc...

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

private static void setupDateOfBirth(TemplatingRecognizerSettings settings, List card){
card.add(new DecodingInfo(new Rectangle(0.565f, 0.389f, 0.176f, 0.056f),150, DATE_OF_BIRTH));

the parameter for 150 is for what value? range??

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

So I need to create my own RecognitionResult class? and inside the class add all the method for example getName(), getAddress(), etc...

No, you will obtain results as written in documentation, using parser group/parser name strings you used when configuring parser groups (aka decoding infos) and parsers.

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

the parameter for 150 is for what value?

This is the dewarp height of the location in pixels. Generally it should be set to number of expected text lines * 100, but feel free to experiment with different values until you get the best results.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

Cannot find parser group for location 'address'. Will not perform OCR and parsing of that location!

This message mean my calculation got problem?

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

the coding below is the coding after on

public  Customer onScanningDone(RecognitionResults results){
    Customer customer = null;
    BaseRecognitionResult[] dataArray = results.getRecognitionResults();
    for(BaseRecognitionResult baseResult : dataArray) {
        if(baseResult instanceof BlinkOCRRecognitionResult) {
            BlinkOCRRecognitionResult result = (BlinkOCRRecognitionResult) baseResult;
            // you can use getters of BlinkOCRRecognitionResult class to
            // obtain scanned information
            if(result.isValid() && !result.isEmpty()) {
                // use the parser name provided to BlinkOCRRecognizerSettings to
                // obtain parsed result provided by given parser
                // obtain result of "myAmountParser" in default parsing group
                Log.i(TAG, "card result is valid!!");
                String name = result.getParsedResult("name");
                String passport = result.getParsedResult("passportNumber");
                String dob = result.getParsedResult("dateOfBirth");
                String gender = result.getParsedResult("gender");
                String address = result.getParsedResult("address");

                Log.i(TAG, "Scan From ---> Name ))) " + name);
                Log.i(TAG, "Scan From ---> passport ))) " + passport);
                Log.i(TAG, "Scan From ---> dob ))) " + dob);
                Log.i(TAG, "Scan From i---> gender ))) " + gender);
                Log.i(TAG, "Scan From ---> address ))) " + address);

                customer.setName(name);
                customer.setGender(gender);
                customer.setPassport(passport);
                customer.setDob(dob);
                customer.setAddress(address);
            }
        }
    }
    return customer;
}

for Date I use DateParserSettings
for other value I use RegexParserSettings

private static void setupDateOfBirth(TemplatingRecognizerSettings settings, List<DecodingInfo> card){
    card.add(new DecodingInfo(new Rectangle(0.565f, 0.389f, 0.176f, 0.056f),100, DATE_OF_BIRTH));

    settings.addParserToParserGroup(DATE_OF_BIRTH,DATE_OF_BIRTH, new DateParserSettings());
    Log.i(TAG, "Scan DOB");
}


private static void setupPassportNumber(TemplatingRecognizerSettings settings, List<DecodingInfo> card){
    card.add(new DecodingInfo(new Rectangle(0.565f, 0.315f, 0.412f, 0.056f), 100, PASSPORT_NUMBER));

    RegexParserSettings documentNumberParser = new RegexParserSettings("\\d{9}");
    settings.addParser(PASSPORT_NUMBER,documentNumberParser );
    Log.i(TAG, "Scan Passport");
}

the coding above are two function in my program. is that any problem?
because after the scanning done, my application will crash. and I cannot get the value after scanning done.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

is it need use addParserToParseGroup? because after I use it, the scanned image got detected each character already. but now the problem is it said that the result is not valid or empty, ask me scan again.

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

Cannot find parser group for location 'address'. Will not perform OCR and parsing of that location!
This message mean my calculation got problem?

No, this means that you have created decoding info with name 'address', and have not set any parsers to parser group called 'address'.

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

the coding above are two function in my program. is that any problem?
because after the scanning done, my application will crash. and I cannot get the value after scanning done.

It should not be. Which crash are you having?

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

is it need use addParserToParseGroup? because after I use it, the scanned image got detected each character already. but now the problem is it said that the result is not valid or empty, ask me scan again.

Yes, each decoding info / location on detected document represents a new parser group and only parsers added to parser group of same name as decoding info name will run on OCR result obtained on that location.

For more information about parser groups, please read this. For more information how parser group fit into Templating API, please read this. For a detailed explanation of code examples, please check this whitepaper.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

yea.. I got it already. now just need to adjust the position for the information. THANKS A LOT!!

from blinkid-android.

DoDoENT avatar DoDoENT commented on August 16, 2024

If that solved your problem, please close this issue. If you run into a new problem, please open a new issue.

from blinkid-android.

leeyikkong avatar leeyikkong commented on August 16, 2024

ok thanks for your help.

from blinkid-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.