konstantint / PassportEye

Extraction of machine-readable zone information from passports, visas and id-cards via OCR
MIT License
372 stars 109 forks source link

Wrong MRZ type for France ID card issued before 2021 #64

Open canklot opened 2 years ago

canklot commented 2 years ago

ID cards issued before 2021 by France has 2 lines with 36 characters. But the order of the fields are different from TD2. And the PassportEye identifies them as TD2 and outputs wrong results

https://en.wikipedia.org/wiki/National_identity_card_(France) https://www.doubango.org/SDKs/mrz/docs/MRZ_formats.html

canklot commented 2 years ago

An easy work around for others

def check_france(mrz):
    if mrz.type == "ID" and mrz.country == "FRA" and mrz.valid == False:
        mrz.mrz_type = "TDF"
        raw_text = mrz.aux['raw_text']
        mrz.last_name = raw_text[5:30].replace("<","")
        mrz.surname = mrz.last_name
        mrz.number = raw_text[37:49]
        mrz.check_number =  raw_text[49]
        mrz.names = raw_text[50:63].replace("<<"," ")
        mrz.date_of_birth = raw_text[64:70]
        mrz.check_date_of_birth = raw_text[70]
        mrz.sex = raw_text[71]
        mrz.check_composite = raw_text[72]

        # 731 check
        cal_check_numbers = calculate_checksum( mrz.number)
        cal_check_date_of_birth = calculate_checksum( mrz.date_of_birth)

        mrz.valid_date_of_birth = True if cal_check_date_of_birth  == int(mrz.check_date_of_birth)  else False
        mrz.valid_check_number = True if cal_check_numbers  == int(mrz.check_number)  else False

        mrz.expiration_date = " "
        mrz.nationality = " "

        fra_valid_score = 20
        if mrz.valid_date_of_birth : fra_valid_score += 35
        if mrz.valid_check_number : fra_valid_score += 35
        mrz.valid_score = fra_valid_score
    return mrz