> For the complete documentation index, see [llms.txt](https://capellac.gitbook.io/opencv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://capellac.gitbook.io/opencv/week1/opencv-basics/optical-character-recognition-ocr-tesseract.md).

# Optical Character Recognition(OCR)-Tesseract

[OFFICIAL DOCUMENTATION](https://tesseract-ocr.github.io/tessdoc/)

| PLATFORM | HOW TO                                                                                  |
| -------- | --------------------------------------------------------------------------------------- |
| WINDOWS  | [download binaries for windows](https://tesseract-ocr.github.io/tessdoc/Downloads.html) |
| LINUX    | Tesseract is included in most Linux distributions. ("sudo apt install tesseract-ocr")   |

{% hint style="success" %}
FILE -> PROJECT INTERPRETER -> install pytesseract package
{% endhint %}

{% hint style="success" %}
import pytesseract
{% endhint %}

{% hint style="danger" %}
While you're working with pytesseract, your src image should be in RBG format not BGR.
{% endhint %}

## EACH CHARACTER

![Drawing Rectangle and Recognizing each Character](/files/-MAQieA41xqQw4-TtEv2)

```
import cv2
import pytesseract


img = cv2.imread("1.png")
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
print(pytesseract.image_to_string(imgRGB))
cv2.imshow("Output", imgRGB)


cv2.waitKey(0) 
```

## EACH WORD

![](/files/-MAQii4wwL0WSjFcdkHR)

```
import cv2
import pytesseract

img = cv2.imread("1.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
hImg, wImg, _ = img.shape
listOfPoints = pytesseract.image_to_boxes(img)

for b in listOfPoints.splitlines():
    b = b.split(' ')
    print(b)
    x,y,w,h = int(b[1]), int(b[2]), int(b[3]), int(b[4])
    cv2.rectangle(img, (x, hImg-y), (w, hImg-h), (0,0,255), 3)
    cv2.putText(img, b[0], (x, hImg-y+25), cv2.FONT_HERSHEY_COMPLEX, 1, (50,50,255), 2)

cv2.imshow("Output", img)
cv2.waitKey(0)
```
