<?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 Rahul Kochar on Medium]]></title>
        <description><![CDATA[Stories by Rahul Kochar on Medium]]></description>
        <link>https://medium.com/@kocharrahul2015?source=rss-cc5fe05ca0c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-QOAQiZycEiQP6EjWNyxmQ.jpeg</url>
            <title>Stories by Rahul Kochar on Medium</title>
            <link>https://medium.com/@kocharrahul2015?source=rss-cc5fe05ca0c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:03:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kocharrahul2015/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[Optical Character Recognition using PyTesseract OpenCV]]></title>
            <link>https://medium.com/ieee-ras-vit/optical-character-recognition-using-pytesseract-opencv-6be0f6ca2829?source=rss-cc5fe05ca0c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6be0f6ca2829</guid>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[pytesseract]]></category>
            <category><![CDATA[character-recognition]]></category>
            <category><![CDATA[ocr]]></category>
            <dc:creator><![CDATA[Rahul Kochar]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 18:29:47 GMT</pubDate>
            <atom:updated>2020-11-29T18:29:47.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sSA03FcTEw3tq6TJWhrneQ.jpeg" /><figcaption><strong>Character Recognition</strong></figcaption></figure><p>Heard of Google Lens? Want to find out the key aspect of the latest feature of copying the text from paper documents and saving it into your phone or PC? If yes then let just dive into this article on Optical Character Recognition using OpenCV.</p><p>Optical character recognition (OCR) converts a two-dimensional image of text which contains handwritten or machine-printed text into machine-readable text i.e. it extracts the text from the image and displays it. The sub-processes of OCR are:</p><p><strong><em>· Pre-processing of images</em></strong></p><p><strong><em>· Text Localisation</em></strong></p><p><strong><em>· Character segmentation</em></strong></p><p><strong><em>· Character recognition</em></strong></p><p><strong><em>· Post-processing</em></strong></p><h3>OpenCV:</h3><p>OpenCV was started at Intel in the year 1999 by Gary Bradsky. OpenCV stands for Open Source Computer Vision Library. OpenCV Python is too fast due to the background code written in C/C++ and it is easy to understand and deploy as it is wrapped in python which makes the complex task easier to perform.</p><h3>PyTesseract:</h3><p>PyTesseract is an Optical Character Recognition tool for python which reads the text in the images and prints it in the editor. It is the wrapper of the Google tesseract OCR engine. It can easily read all the image types such as jpg, png, gif, etc. It can be installed using: pip install PyTesseract.</p><p>To run this in the editor we have to download tesseract.exe and add the path to the PyTesseract path where the software or the editor has been installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*daUpi1EsDeqy5sbdNmWCbQ.png" /><figcaption><strong>OCR Process Flow</strong></figcaption></figure><h3><strong>Optical Character Recognition using PyTesseract OCR steps:</strong></h3><h4><strong>Importing libraries:</strong></h4><pre><strong>import cv2<br>import pytesseract</strong></pre><h4><strong>Reading of the image:</strong></h4><pre><strong>img=cv2.imread(&#39;Sample_image.JPG&#39;)</strong></pre><h4><strong>Converting the image text into String:</strong></h4><p>Pytesseract has a built-in function where it converts the text in the image to a string. The function is:</p><p>text=pytesseract.image_to_string(image)</p><pre><strong>def ocr(img):<br>    text=pytesseract.image_to_string(img)<br>    return text</strong></pre><h4><strong>Printing of the text in the editor:</strong></h4><pre><strong>print(ocr(img))</strong></pre><h4><strong>Testing Input:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*iwOswigtRG5Jr5rH4ueY7Q.png" /><figcaption><strong>Input Text</strong></figcaption></figure><h4><strong>Result:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_tcYKpbWfeEGXI067pbs2Q.png" /><figcaption><strong>Unexpected Results</strong></figcaption></figure><p>As you can see that the text in the image cannot be read so it is not 100% accurate so we need to do some pre-processing of the image to get better results.</p><h3><strong>Pre-processing of the image:</strong></h3><h4><strong>Convert the image into a gray-scale image:</strong></h4><p>Images are converted to gray-scale as it is easier to process the image due to less number of pixels.</p><p>cv2.cvtColor(source,cv2.COLOR_BGR2GRAY)</p><pre><strong>def get_grayscale(image):<br>    return cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)</strong></pre><h4><strong>Thresholding of images:</strong></h4><p>In thresholding, each pixel is converted into a black pixel if the image intensity is less than a specified value constant.</p><p>cv2.threshold(source,thresholdValue,maxValue,thresholdingTechnique)</p><pre><strong>def thresholding(image):<br>   return cv2.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]</strong></pre><h4><strong>Removal of noise:</strong></h4><p>The image is blurred by a Gaussian function to reduce image noise.</p><p>cv2.GaussianBlur(source,kernal-size,sigmaX)</p><pre><strong>def remove_noise(image):<br>   return cv2.GaussianBlur(image,(5,5),0)</strong></pre><h4><strong>Resize of the image:</strong></h4><p>It helps in reducing the number of pixels in the image to decrease the complexity and increase accuracy.</p><pre><strong>img = cv2.resize(img, None, fx=5.0, fy=5.0, interpolation=cv2.INTER_CUBIC)</strong></pre><h4><strong>Testing Input:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*iwOswigtRG5Jr5rH4ueY7Q.png" /><figcaption><strong>Input Text</strong></figcaption></figure><h4><strong>Result:</strong></h4><pre>print(ocr(img))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ZoHIHfPHunlP3Rfwx5w5xQ.png" /><figcaption><strong>Expected Results</strong></figcaption></figure><h3><strong>The full Source Code is:</strong></h3><pre>import cv2<br>import pytesseract<br>pytesseract.pytesseract.tesseract_cmd = &#39;C:\Program Files (x86)\Tesseract-OCR/tesseract&#39;<br><br>def ocr(img):<br>    text=pytesseract.image_to_string(img)<br>    return text<br><br>img=cv2.imread(&#39;Sample_image.JPG&#39;)<br>img = cv2.resize(img, None, fx=5.0, fy=5.0, interpolation=cv2.INTER_CUBIC)<br><br>def get_grayscale(image):<br>    return cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)<br><br>def remove_noise(image):<br>    return cv2.GaussianBlur(image,(5,5),0)<br><br>def thresholding(image):<br>    return cv2.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]<br><br>img=get_grayscale(img)<br>img=thresholding(img)<br>img=remove_noise(img)<br><br>print(ocr(img))</pre><h3><strong>Conclusion</strong></h3><p>Character and handwriting recognition has impacted every facet of computer vision. The OCR engine is built on a Long Short-term Memory network which is kind of a Recurrent Neural Network. This deep learning method has managed to recognized text with more accuracy. Feel free to interact with it and use it in Invoice Imaging, Banking, Captcha generation, Google lens, etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6be0f6ca2829" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ieee-ras-vit/optical-character-recognition-using-pytesseract-opencv-6be0f6ca2829">Optical Character Recognition using PyTesseract OpenCV</a> was originally published in <a href="https://medium.com/ieee-ras-vit">IEEE-RAS VIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>