<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sai Ashish on Medium]]></title>
        <description><![CDATA[Stories by Sai Ashish on Medium]]></description>
        <link>https://medium.com/@saiashish90?source=rss-ff7150adb9ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hN5Hsni4zpmohjD6JhRVhg.jpeg</url>
            <title>Stories by Sai Ashish on Medium</title>
            <link>https://medium.com/@saiashish90?source=rss-ff7150adb9ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 05:25:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saiashish90/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Training Tesseract-OCR with custom data.]]></title>
            <link>https://saiashish90.medium.com/training-tesseract-ocr-with-custom-data-d3f4881575c0?source=rss-ff7150adb9ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3f4881575c0</guid>
            <category><![CDATA[trains]]></category>
            <category><![CDATA[tesseract]]></category>
            <category><![CDATA[custom-tesseract]]></category>
            <category><![CDATA[ocr-train]]></category>
            <category><![CDATA[ocr]]></category>
            <dc:creator><![CDATA[Sai Ashish]]></dc:creator>
            <pubDate>Mon, 07 Jun 2021 16:56:55 GMT</pubDate>
            <atom:updated>2021-06-14T07:53:44.755Z</atom:updated>
            <content:encoded><![CDATA[<p>While trying to develop an OCR system for low-resolution images, I realized the shortcomings of the pre-trained tesseract models. For this reason, I decided to train it using my own data. Unfortunately, resources on how to do this on the internet are few and far between, and the ones you can find are not very detailed and are hard to understand for people with less experience. This is a detailed guide on how to set up the image files and train a custom tesseract model.</p><h3>Steps involved:</h3><ul><li>Gathering and naming image files.</li><li>Generating Box files.</li><li>Annotating Box files.</li><li>Training Tesseract.</li></ul><h4>Gathering and naming image files.</h4><p>The first task of finding all the image files that you want to use to train your custom model. This can be a full-page document or a single line of cropped text. The important part is to pick training images that accurately represent the data that your model is likely to receive. This way we can be sure that the model will produce accurate results after training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*bWLOF54eOUmSCJqlKUV7yw.png" /><figcaption>Entire Page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*RrtWE9XOu7NL0gQ7LkDJUA.jpeg" /><figcaption>A single line of text</figcaption></figure><p>After gathering these images, create a file structure as shown and place them in the data folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*9xVGwXC1ULS9kyHv0T1ReA.png" /><figcaption>File structure</figcaption></figure><p>After gathering all the images, we need to rename them to a format that tesseract can understand.</p><p><strong><em>[language name].[font name].exp[number].[file extension]</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20f7af01f1bd5a91776898d1a3cc2ddc/href">https://medium.com/media/20f7af01f1bd5a91776898d1a3cc2ddc/href</a></iframe><h4>Generating Box files.</h4><p>Once we gather the images, we can make tesseract generate box files for the text in the images. Tesseract will try its best to draw boxes around the characters and to identify them. This obviously won&#39;t be 100% accurate because otherwise, we wouldn&#39;t need to train tesseract.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e913445bbc8270d7f2f7bad5bc2cb97/href">https://medium.com/media/1e913445bbc8270d7f2f7bad5bc2cb97/href</a></iframe><p>This will produce a list of box files for each image file with the file format.<strong><em>[language name].[font name].exp[number].box</em></strong></p><p>These box files will contain boxes around the characters in the image and what each character is.</p><h4>Annotating Box files.</h4><p>Now comes the manual work of annotating the box files. We can use a program like <a href="https://github.com/nguyenq/jTessBoxEditor/releases/tag/Release-2.3.1">jTessBoxEditor</a> to open each image file and check the bounding boxes that tesseract has made. We can correct the boxes and the character in them. We can also add new boxes around characters that tesseract has missed.</p><p>This is the most important task as any mistakes will reduce the accuracy of the trained models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lKz_LYCHwTnkzZy4E9PC8w.png" /></figure><h4>Training Tesseract.</h4><p>Once all the images have been annotated. We can start with the final training.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffa3dfa2dc1b39a9fed3dfb6f4a9830a/href">https://medium.com/media/ffa3dfa2dc1b39a9fed3dfb6f4a9830a/href</a></iframe><ol><li>First, we read all the box files and images and create a tuple.</li></ol><p>2. ‎‎ ‎For every image/boxfile in the list, we first check if train-data was generated for the image, if not we run</p><pre>tesseract {srcdir}/{image} {destdir}/{image[:-4]} nobatch box.train</pre><p>This will create .tr files in the .<strong>trainfiles</strong> directory.</p><p>We also append the box file to the<strong> c</strong>ommand.</p><p><strong><em>unicharset_extractor — output_unicharset ../../{destdir}/unicharset</em></strong></p><p>This command will later extract all the characters from all the box files and add them to a file called <strong><em>unicharset.</em></strong></p><p>3. Once we generate train files. We write a file called <strong><em>font_properties.</em></strong></p><p>Each line of the font_properties file is formatted as follows: fontname italic bold fixed serif fraktur.<br> where fontname is a string naming the font (no spaces allowed!), and italic, bold, fixed, serif and fraktur are all simple 0 or 1 flags indicating whether the font has the named property. Like ocrb 0 0 0 1 0</p><p>You can edit this file based on the font in your images.</p><p>4. Next we append all the files to the mftraining and cntraining commands and run them. This will give us a charset file for our language and 4 other files on the <strong>trainoutput</strong> directory.</p><p>5. Finally we can combine all the files into one <strong><em>.traineddata</em></strong> file. To use this copy the file to the tesseract source directory and use the -lang option to use the trained result. tesseract image.png -l [lang]</p><p>Note: Use purge file to remove all the train data and start from scratch.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/231461d33582c878a0b45a5373a603a5/href">https://medium.com/media/231461d33582c878a0b45a5373a603a5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3f4881575c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Facial similarity using OpenCV and DLib.]]></title>
            <link>https://saiashish90.medium.com/facial-similarity-using-opencv-and-dlib-dc03f745cf10?source=rss-ff7150adb9ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc03f745cf10</guid>
            <category><![CDATA[dlib]]></category>
            <category><![CDATA[facedetection]]></category>
            <category><![CDATA[face-similarity]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sai Ashish]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 18:36:35 GMT</pubDate>
            <atom:updated>2021-04-16T18:37:41.580Z</atom:updated>
            <content:encoded><![CDATA[<p>About a month ago, I had to develop a software that compares pictures and checks if they are the same person. After scouring the internet for tutorials on how to do this, I gave up and decided to do it on my own. I decided to write this blog post to help out anyone who needs to implement facial similarity in their project.</p><h3>Steps involved:</h3><ul><li>Extracting the face using a hog detector.</li><li>Computing embeddings for the given face.</li><li>Finding the euclidean distance between the 2 faces to check similarity.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*y4vu8uj2ujhcurUP.jpg" /></figure><h4>Extracting the face.</h4><p>Given an input picture, we must first locate the face that is present in the picture. To do this, we are going to use a <a href="https://www.pyimagesearch.com/2014/11/10/histogram-oriented-gradients-object-detection/">Histogram of Oriented Gradients (HOG) detector</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1134c8e9a6915ea62bf514d6845a827/href">https://medium.com/media/b1134c8e9a6915ea62bf514d6845a827/href</a></iframe><h4>Computing embedding.</h4><p>Once we get the location of the face using the hog detector from <a href="http://dlib.net/">dlib</a>. We will use this to get the pose of the face in 3D. This will help us normalize faces that are in different orientations. Once we get the pose using a 68 point pose predictor, we will use the <a href="https://cmusatyalab.github.io/openface/">openface</a> 128-dimensional embedding model to get a 128D vector that describes the given face.</p><p><a href="https://github.com/davisking/dlib-models/blob/master/shape_predictor_68_face_landmarks_GTX.dat.bz2">Pose Predictor Model</a>, <a href="https://github.com/ksachdeva/face-embeddings-generator/blob/master/models/dlib_face_recognition_resnet_model_v1.dat">128D embedding model</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be99ff2754e5c955d17b6261932bc6e5/href">https://medium.com/media/be99ff2754e5c955d17b6261932bc6e5/href</a></iframe><h4>Find Similarity between the faces.</h4><p>Once we get the embeddings for both the faces, we can use this to compute the euclidean distance between the faces since the vector represents the features of the faces. If the distance between the faces is large, we can say that they are not the same person.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4082a1739dd2e918c27ee516ce622594/href">https://medium.com/media/4082a1739dd2e918c27ee516ce622594/href</a></iframe><h3>Conclusion.</h3><p>Once we get the distance between the two faces, we can use this to see if the faces are of the same person or of two different people. The default threshold for the distance is ‘.6’. If the distance is greater than this then the faces belong to different people, and if it is lower then they are the same person.</p><p>We can modify this threshold to make the detection more strict or more lenient.</p><h3>Complete code.</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cb64f3373c052eda464c8b44f4966b6/href">https://medium.com/media/2cb64f3373c052eda464c8b44f4966b6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc03f745cf10" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>