<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sivakumar Mahalingam</title>
    <description>The latest articles on DEV Community by Sivakumar Mahalingam (@sivakumar_mahalingam).</description>
    <link>https://dev.to/sivakumar_mahalingam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2629008%2Fa52df063-1ec6-4ea4-b7ff-5fd291b213c7.png</url>
      <title>DEV Community: Sivakumar Mahalingam</title>
      <link>https://dev.to/sivakumar_mahalingam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sivakumar_mahalingam"/>
    <language>en</language>
    <item>
      <title>FastMRZ 3 - Passport MRZ Extraction in Pure Python, No Tesseract</title>
      <dc:creator>Sivakumar Mahalingam</dc:creator>
      <pubDate>Sat, 21 Nov 2026 23:58:47 +0000</pubDate>
      <link>https://dev.to/sivakumar_mahalingam/fastmrz-3-passport-mrz-extraction-in-pure-python-no-tesseract-7h1</link>
      <guid>https://dev.to/sivakumar_mahalingam/fastmrz-3-passport-mrz-extraction-in-pure-python-no-tesseract-7h1</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftjhg77vx7warg10b1a9z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftjhg77vx7warg10b1a9z.png" alt=" " width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have ever built KYC onboarding, hotel check-in or border-control software, you know the MRZ: the two or three lines of &lt;code&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/code&gt;-padded text at the bottom of a passport, ID card or visa.&lt;/p&gt;

&lt;p&gt;Reading it sounds simple. It is 37 possible characters (A-Z, 0-9 and &lt;code&gt;&amp;lt;&lt;/code&gt;) in a fixed layout defined by ICAO 9303. In practice, most Python MRZ tools come with the same setup ritual:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Tesseract at system level&lt;/li&gt;
&lt;li&gt;Download a special MRZ traineddata file&lt;/li&gt;
&lt;li&gt;Copy it into the correct &lt;code&gt;tessdata&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Make sure all of that also exists in your Docker image, Lambda layer, CI runner and the Windows laptop of whoever joins the team next&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And after all that, it still struggles with phone photos that are skewed, blurred or badly lit.&lt;/p&gt;

&lt;p&gt;The first versions of FastMRZ had the same problem, because they used Tesseract under the hood. With FastMRZ 3, I removed Tesseract completely.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's new in FastMRZ 3
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No Tesseract.&lt;/strong&gt; FastMRZ now ships its own ONNX text recogniser, trained only for the MRZ character set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pure Python install.&lt;/strong&gt; The only dependencies are &lt;code&gt;numpy&lt;/code&gt;, &lt;code&gt;opencv-python-headless&lt;/code&gt; and &lt;code&gt;pymupdf&lt;/code&gt;. No system packages, no traineddata files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More accurate&lt;/strong&gt; than the Tesseract-based versions, because the recogniser only has to tell apart 37 characters in one fixed font, not every glyph in every language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More input types.&lt;/strong&gt; File paths, NumPy arrays, Base64 strings, raw bytes, PDFs and plain MRZ text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batch processing&lt;/strong&gt; in parallel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More document formats.&lt;/strong&gt; TD1, TD2, TD3, MRV-A and MRV-B.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install fastmrz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the whole setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick start
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastmrz&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;FastMRZ&lt;/span&gt;

&lt;span class="n"&gt;fast_mrz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastMRZ&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"passport.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;details&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output (trimmed):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mrz_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"TD3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"surname"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ERIKSSON"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"given_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ANNA MARIA"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"birth_date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1974-08-12"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"sex"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"F"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"expiry_date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2012-04-15"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SUCCESS"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;status&lt;/code&gt; is &lt;code&gt;SUCCESS&lt;/code&gt; only when the format and every ICAO 9303 check digit are valid. Otherwise it is &lt;code&gt;FAILURE&lt;/code&gt;, and &lt;code&gt;status_message&lt;/code&gt; tells you the first problem found. If no MRZ is found in the image at all, you get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"FAILURE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"status_message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"No MRZ detected"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No exceptions to catch, no silent garbage. Either the data passed the checksums or you're told why it didn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every input type you'll actually use
&lt;/h2&gt;

&lt;p&gt;In real systems, images rarely arrive as files on disk. They come from an upload endpoint, a camera frame or a scanned PDF. FastMRZ takes all of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Raw MRZ text instead of parsed fields&lt;/span&gt;
&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"passport.jpg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ignore_parse&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# OpenCV / camera frame (BGR or grayscale ndarray)&lt;/span&gt;
&lt;span class="n"&gt;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"numpy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# From a web or mobile client&lt;/span&gt;
&lt;span class="n"&gt;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b64_string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"base64"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Straight from an upload or S3 object&lt;/span&gt;
&lt;span class="n"&gt;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"bytes"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Scanned PDF - uses the first page with an MRZ&lt;/span&gt;
&lt;span class="n"&gt;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"scan.pdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"pdf"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Already have the MRZ string? Parse and validate only&lt;/span&gt;
&lt;span class="n"&gt;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mrz_string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two more helpers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Check digits only&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;validate_mrz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mrz_string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# {"is_valid": ..., "status_message": ...}&lt;/span&gt;

&lt;span class="c1"&gt;# Get the rectified MRZ crop, useful for audit logs or manual review&lt;/span&gt;
&lt;span class="n"&gt;strip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_mrz_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"passport.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Batch processing
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details_batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"a.jpg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"b.jpg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"c.jpg"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Results come back in input order&lt;/li&gt;
&lt;li&gt;Runs in parallel. &lt;code&gt;workers&lt;/code&gt; defaults to your CPU count, capped at 8&lt;/li&gt;
&lt;li&gt;Expect roughly 1.5x the throughput of a plain loop on a 4-core CPU&lt;/li&gt;
&lt;li&gt;A file that can't be read doesn't stop the batch. Its entry just comes back as &lt;code&gt;FAILURE&lt;/code&gt; with a message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It takes the same options as &lt;code&gt;get_details&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;get_details_batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"imagepath"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ignore_parse&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                  &lt;span class="n"&gt;include_checkdigit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;workers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Locate.&lt;/strong&gt; OpenCV contour detection plus an ONNX model find the MRZ region, even when the document isn't perfectly aligned in the photo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rectify.&lt;/strong&gt; The MRZ strip is cropped, deskewed and normalised.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recognise.&lt;/strong&gt; A small ONNX model reads the characters. Because it only has to handle the 37 MRZ symbols in the OCR-B font, it can be far smaller and more reliable on this job than a general-purpose OCR engine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate.&lt;/strong&gt; Every check digit defined by ICAO 9303 is verified, and the fields are parsed into clean, structured output.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Everything runs locally on CPU. No document image ever leaves your machine, which matters when you're handling passports.&lt;/p&gt;

&lt;h2&gt;
  
  
  Supported documents
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Used on&lt;/th&gt;
&lt;th&gt;Lines x chars&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;TD1&lt;/td&gt;
&lt;td&gt;ID cards&lt;/td&gt;
&lt;td&gt;3 x 30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TD2&lt;/td&gt;
&lt;td&gt;Older ID cards, some visas&lt;/td&gt;
&lt;td&gt;2 x 36&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TD3&lt;/td&gt;
&lt;td&gt;Passports&lt;/td&gt;
&lt;td&gt;2 x 44&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MRV-A&lt;/td&gt;
&lt;td&gt;Visas (large)&lt;/td&gt;
&lt;td&gt;2 x 44&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MRV-B&lt;/td&gt;
&lt;td&gt;Visas (small)&lt;/td&gt;
&lt;td&gt;2 x 36&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Migrating from PassportEye
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# PassportEye&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;passporteye&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;read_mrz&lt;/span&gt;
&lt;span class="n"&gt;mrz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read_mrz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"passport.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# FastMRZ&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastmrz&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;FastMRZ&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastMRZ&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"passport.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No Tesseract install, and the &lt;code&gt;status&lt;/code&gt; field tells you whether the checksums passed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upgrading from FastMRZ 1.x / 2.x
&lt;/h2&gt;

&lt;p&gt;Remove Tesseract from your Dockerfile and setup scripts. You no longer need it. If you still pass the old &lt;code&gt;tesseract_path&lt;/code&gt; or &lt;code&gt;tessdata_path&lt;/code&gt; arguments, FastMRZ 3 ignores them and raises a &lt;code&gt;FutureWarning&lt;/code&gt;, so you can clean them up at your own pace.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it fits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;KYC and customer onboarding in banking and fintech&lt;/li&gt;
&lt;li&gt;Hotel, airline and car-rental check-in&lt;/li&gt;
&lt;li&gt;Travel, immigration and visa processing&lt;/li&gt;
&lt;li&gt;Any back-office workflow where staff type passport details by hand today&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it, break it, tell me
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/sivakumar-mahalingam/fastmrz" rel="noopener noreferrer"&gt;https://github.com/sivakumar-mahalingam/fastmrz&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI: &lt;a href="https://pypi.org/project/fastmrz/" rel="noopener noreferrer"&gt;https://pypi.org/project/fastmrz/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;FastMRZ is open source under Apache-2.0.&lt;/p&gt;

&lt;p&gt;The most useful thing you can send me is a failure case. If FastMRZ can't read one of your documents, open an issue with a redacted sample and I'll use it to improve the model. And if it saves you a Tesseract install, a star on GitHub helps other developers find it.&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>computervision</category>
      <category>programming</category>
    </item>
    <item>
      <title>Introducing FastMRZ – Effortless MRZ Extraction Made Simple</title>
      <dc:creator>Sivakumar Mahalingam</dc:creator>
      <pubDate>Tue, 31 Dec 2024 15:20:58 +0000</pubDate>
      <link>https://dev.to/sivakumar_mahalingam/introducing-fastmrz-effortless-mrz-extraction-made-simple-3ikd</link>
      <guid>https://dev.to/sivakumar_mahalingam/introducing-fastmrz-effortless-mrz-extraction-made-simple-3ikd</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In today's world, where speed is everything, sensitive document processing has to be automated. Be it passport, visa, or ID card, extraction of MRZ data with accuracy and speed is very significant for developing reliable applications. This is where &lt;code&gt;fastmrz&lt;/code&gt; comes into play as a lightweight and efficient Python package in making this MRZ data extraction from document images much easier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/sivakumar-mahalingam/fastmrz" rel="noopener noreferrer"&gt;FastMRZ Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PyPI:&lt;/strong&gt; &lt;a href="https://pypi.org/project/fastmrz" rel="noopener noreferrer"&gt;FastMRZ Python Package&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is FastMRZ?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;FastMRZ&lt;/code&gt; is a Python package that uses computer vision techniques to extract MRZ information from images of documents. It provides an easy-to-use implementation that enables the extraction of MRZ, making it easier for developers who build systems for FinTech, security, and identity verification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use FastMRZ?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Ease of Use:&lt;/strong&gt; With a simple API, fastmrz gets you up and running in no time and does not require a steep learning curve.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Speed:&lt;/strong&gt; Optimized for performance, it processes images fast enough to ensure the least latency in your applications. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Accuracy:&lt;/strong&gt; It is designed to reliably detect and extract MRZ data, even from challenging image conditions. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Lightweight:&lt;/strong&gt; It is built to keep dependencies at a minimum, hence easily integrable into any project. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Open Source:&lt;/strong&gt; It is free and open-source, hence the community contributes and improves the package.&lt;/p&gt;

&lt;p&gt;Also this python package,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Supports various document formats (passports, visas, ID cards).&lt;/li&gt;
&lt;li&gt;Compatible with a wide range of image resolutions and formats.&lt;/li&gt;
&lt;li&gt;Robust against skewed or distorted images.&lt;/li&gt;
&lt;li&gt;Pythonic API for seamless integration.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Features
&lt;/h2&gt;

&lt;p&gt;FastMRZ is unique in many ways with the combination of powerful features:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Intelligent MRZ Detection:&lt;/strong&gt; The library applies sophisticated contour detection methods in order to find the exact position of the MRZ area within document images to accurately extract even if document orientation is not perfect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Custom ONNX Models:&lt;/strong&gt; We have integrated our very own, custom-trained ONNX models for improved recognition accuracy by availing the powers of machine learning while maintaining rapid speeds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Built-in Validation:&lt;/strong&gt; It features comprehensive checksum logic that will verify the extracted data, helping to catch any potential recognition errors or document tampering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Flexible Output Formats:&lt;/strong&gt; Whether it's structured JSON for easy integration with other systems or even raw text for simple processing, FastMRZ has you covered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under the Hood
&lt;/h2&gt;

&lt;p&gt;FastMRZ is built on a very robust technical foundation, using several leading technologies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OpenCV&lt;/strong&gt; for image processing and MRZ region detection&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tesseract OCR&lt;/strong&gt; for text recognition, with custom-trained data for MRZ-specific characters&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NumPy&lt;/strong&gt; for efficient numerical operations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ONNX&lt;/strong&gt; to run optimized machine learning models.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;You can install fastmrz via pip:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;fastmrz  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to Use fastmrz
&lt;/h3&gt;

&lt;p&gt;Here’s a quick example to get started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastmrz&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastMRZ&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;fast_mrz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastMRZ&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;passport_mrz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_mrz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;../data/passport_uk.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;JSON:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;passport_mrz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;passport_mrz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast_mrz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_mrz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;../data/passport_uk.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TEXT:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;passport_mrz&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mrz_type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TD3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;document_type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;P&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;country_code&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GBR&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;surname&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PUDARSAN&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;given_name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;HENERT&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;document_number&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;707797979&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;nationality&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GBR&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;date_of_birth&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1995-05-20&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sex&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;M&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;date_of_expiry&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2017-04-22&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SUCCESS&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="n"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;GBRPUDARSAN&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;HENERT&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;
&lt;span class="mi"&gt;7077979792&lt;/span&gt;&lt;span class="n"&gt;GBR9505209M1704224&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Understanding MRZ Types
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;FastMRZ&lt;/code&gt; supports various MRZ formats, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TD-1 format&lt;/strong&gt; (3 lines, 30 characters each) commonly used in ID cards&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TD-2 format&lt;/strong&gt; (2 lines, 36 characters each) found in some visas and older IDs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TD-3 format&lt;/strong&gt; (2 lines, 44 characters each) used in international passports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The library automatically detects the format and processes it accordingly, making it versatile for different document types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applications
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identity Verification:&lt;/strong&gt; Automate ID validation processes in security and travel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FinTech:&lt;/strong&gt; Enhance KYC processes with seamless document verification.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Travel and Immigration:&lt;/strong&gt; Streamline data capture for passports and visas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Government Applications:&lt;/strong&gt; Assist in border control and other regulatory activities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;FastMRZ&lt;/code&gt; enables more accessibility and efficiency of document processing. Be it the implementation of a border control system, working on identity verification software, or any document processing application-the MRZ extraction definitely will be done with confidence by using the power of FastMRZ.&lt;/p&gt;

&lt;p&gt;You can fork the project on GitHub and star it, if you find it useful. Your stars help drive the continued development of this open-source tool.&lt;/p&gt;

</description>
      <category>python</category>
      <category>machinelearning</category>
      <category>opensource</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
