Search code examples
pythonc++opencvtesseractgoogle-cloud-vision

Methods for detecting vertical texts in an image using OpenCV


I want to detect text in containers such as this container with vertical texts

I tried OpenCV examples such as textdetection.cpp

Those are capable of detecting horizontal text only. Is there other solutions than cloud vision ocr to address such situations.


Solution

  • You can use tesseract instead , as it has capability of reading text vertically align as well : Here is a sample code :

    import Image
    import pytesseract
    # provide the cropped area with text
    def GetOCR(tempFilepath,languages ='eng'):
        img = Image.open(tempFilepath)
        #img= img.convert('L')
        # filters can be applied optionally for reading the proper text from the image
        img.load()
        # -psm 5 will assume the text allinged vertically 
        text = pytesseract.image_to_string(img,lang = languages,config='-psm 6')
        print "text :{0}".format(text)
    

    Note : The above sample will work , provided you should have pytesseract module installed , and tesseract-ocr exe installed in your machine . Hope this helps :)