Articles

OCR with Python

# Purpose: To make OCR on a directory containing image files,  #          recognized texts are stored in the text files of a target directory. Step 1 : Install  tesseract for Python : ==> https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/ Step 2 : Eventually install additional language packs ==> https://ocrmypdf.readthedocs.io/en/latest/languages.html Source code for example :  from PIL import Image import pytesseract import os DirIn = 'C:/TestIn'     # Directory containing scanned pictures DirOut = 'C:/TestOut'   # Output directory FileList = [ f for f in os.listdir(DirIn) if os.path.isfile(os.path.join(DirIn,f)) ] for i in range(0,len(FileList)): inFile = FileList[i] inFileFullPath = DirIn + '/' + FileList[i] target = inFile.replace('.gif','.txt') target = DirOut + '/' + target      outFile = open(target,'wb')     # German tex...

SQL script to HTML

Python file: Export_MPD.py # Purpose: Generate an HTML file listing descriptions of tables in a SQL Server database #          from a base creation script (exported from SQL Server Management Studio) # Input file:  BaseTest.SQL # Output file: BaseTest.HTML def getHtmlHead(): return """<!DOCTYPE html> <html lang="en">   <head>     <meta charset="utf-8">   </head>      <body>     <font size="4" color="black"><u><b>""" def transform(source, target): inFile = open(source, 'r') outFile = open(target,'a') while 1 : tLine = inFile.readline() if tLine == '': break elif 'CREATE TABLE [dbo].[' in tLine: tLine = tLine.replace('CREATE TABLE [dbo].[','') tLine = tLine.replace('](','') htmlText = getHtmlHead() + 'Table: '+t...