Package: apsisocr
apsis-ocrApsis-OCR is a Mixed language ocr system for Printed Documents developed atApsis Solutions limitedThe full system is build with 3 components:Text detection : DBNetText recognition:Bangla Text : ApsisNetApsisNet is a model developed at Apsis Solutions Limited.It is used bybbOCRas the recognition modelApsisNet is found to be the best among other available recognition models (such as tesseract and easyOCR) in the linkedpaperEnglish Text : SVTR-LCNetText classification : DenseNet121InstallationAs module/pypi packagecpu installationpipinstallapsisocr
pipinstallonnxruntime
pipinstallfastdeploy-python-fhttps://www.paddlepaddle.org.cn/whl/fastdeploy.htmlgpu installationIt is recommended to use conda environment . Specially for GPU.installing cudatoolkit and cudnn:condainstallcudatoolkit
condainstallcudnninstalling packagespipinstallapsisocr
pipinstallonnxruntime-gpu
python-mpipinstall-Ufastdeploy-gpu-python-fhttps://www.paddlepaddle.org.cn/whl/fastdeploy.htmlexporting environment variablesmkdir-p$CONDA_PREFIX/etc/conda/activate.decho'export LD_LIBRARY_PATH=$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH'>>$CONDA_PREFIX/etc/conda/activate.d/env_vars.shBuilding from source : Linux/UbuntuIt is recommended to use conda environment .clone the repository:gitclonehttps://github.com/mnansary/apsisOCR.gitcdapsisOCRcreate a conda environment:condacreate-napsisocrpython=3.9activate conda environment:condaactivateapsisocrcpu installation:bashinstall.shcpugpu installation:bashinstall.shgpuUseageApsisnet : Bangla RecognizeruseagefromapsisocrimportApsisNetbnocr=ApsisNet()bnocr.infer(crops)docstring forApsisNet.infer"""Perform inference on image crops.Args:crops (list[np.ndarray]): List of image crops.batch_size (int): Batch size for inference (default: 32).normalize_unicode (bool): Flag to normalize unicode (default: True).Returns:list[str]: List of inferred texts."""SVTR-LCNet : English RecognizerfromapsisocrimportSVTRLCNetenocr=SVTRLCNet()enocr.infer(crops)docstring forSVTRLCNet.infer"""Perform inference on image crops.Args:crops (list[np.ndarray]): List of image crops.batch_size (int): Batch size for inference.Returns:list[str]: List of recognized texts."""DenseNet121BnEnClassifier : Language classifierfromapsisocrimportDenseNet121BnEnClassifierlang=DenseNet121BnEnClassifier()lang.infer(crops)docstring forDenseNet121BnEnClassifier.infer"""Perform inference on image crops.Args:crops (list[np.ndarray]): List of image crops.batch_size (int): Batch size for inference (default: 32).Returns:list[str]: List of inferred languages."""PaddleDBNet : Text DetectorcheckpaddleOCRofficial website for better understanding of the model# initializationfromapsisocrimportPaddleDBNetdetector=PaddleDBNet()# getting word boxesword_boxes=detector.get_word_boxes(img)# getting line boxesline_boxes=detector.get_line_boxes(img)# getting crop with either of the resultscrops=detector.get_crops(img,word_boxes)ApsisOCR : Overall SystemfromapsisocrimportApsisOCRocr=ApsisOCR()results=ocr(img_path)docstring forApsisOCR.__call__"""Perform OCR on an image.Args:img_path (str): Path to the image file.Returns:dict: OCR results containing recognized text and associated information. The dictionary has the following structre{"text" : multiline text with newline separators"result" : list a dictionaries that contains the following structre:{"line_no" : the line number of the word"word_no" : the word number in the line"poly"    : the four point polygonal bounding box of the word in the image"text"    : the recognized text"lang"    : the classified language code}}"""checkuseage/useage.ipynbfor examplesDeploymentcd deployment: change directory to deployment folderchange the configs as required inconfig.py# This port will be used by the api_ocr.pyOCR_API_PORT=3032# This api address is diplayed after deploying api_ocr.py and this is used in app.pyOCR_API="http://172.20.4.53:3032/ocr"running the api and app:pythonapi_ocr.py# deploys at port 3032 by defautlstreamlitrunapp.py--server.port3033# deploys streamlit built frontend at 3033 portTheapi_ocr.pylets the api to be used without any UI (a postman screenshot is attached below)Theapp.pyruns a streamlit UITESTED GPU INFERENCE SERVER CONFIGOS:Ubuntu20.04.6LTSMemory:62.4GiBProcessor:Intel®Xeon(R)Silver4214RCPU@2.40GHz×24Graphics:NVIDIARTXA6000/PCIe/SSE2Gnome:3.36.8LicenseContents of this repository are restricted to non-commercial research purposes only under theCreative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).Change Log0.0.1 (24/09/2023)added useage and examples0.0.2 (24/09/2023)added liscencing0.0.3 (05/11/2023)added base application without line and word number