# Obtain only text and numbers

**URL:** <https://forum.opencv.org/t/obtain-only-text-and-numbers/2707>\
**Category:** Python\
**Tags:** ocr, imgproc, text, tesseract\
**Created:** [April 10, 2021, 11:52pm UTC](https://forum.opencv.org/t/obtain-only-text-and-numbers/2707 "2021-04-10T23:52:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![salman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/salman/32/1760_2.png) [@salman](https://forum.opencv.org/u/salman)\
**Post date:** [April 10, 2021, 11:52pm UTC](https://forum.opencv.org/t/obtain-only-text-and-numbers/2707/1 "2021-04-10T23:52:10Z")

</div>

i work on a car plate recognition project i did some preprocessing before passing cropped image to tesseract but there still lot of unwanted noise and lines that affect the plate number recognition for example i have this original [image](https://ibb.co/ydmqsxr)

after aplying this code

```
#----------------------------OCR---------------------------------------------------------------
#cropping detected objects and passing into tesseract OCR
A = []
for i in indices:
 i = i[0]
 box = boxes[i]
 x = box[0]
 y = box[1]
 w = box[2]
 h = box[3]
 crop_img = image[y:y+h, x:x+w]
 cv2.imwrite("Crop/crop__" + str(i) + ".jpg",crop_img)
 #Resize the image
 img = cv2.resize(crop_img, None, fx=5, fy=5, interpolation=cv2.INTER_CUBIC)
 #Convert image to grayscale
 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 #Convert image to black and white
 roi = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 69, 1)
 
 #saving the roi regions
 cv2.imwrite("Crop/roi__" + str(i) + ".jpg",roi)

 roi = cv2.threshold(roi,0,255,cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
 #bluring
 roi = cv2.GaussianBlur(roi, (7, 7), 8)
 #passing to tesseract
 c = py.image_to_string(roi, config = ' --psm 13 ')
 #c = py.image_to_string(roi)

 for x in c:
   if x.isdigit():
     A.append(x)
 cv2_imshow(roi)

```

i get this result which is affecting badly tesseract (output is 13 0 cs3405)} )  
 ![téléchargement](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/436da727ce41065431aac576e7ddedab7c1fc634.png)

Any suggestions to get the cropped image to a perfect state suitable for the plate recognition ?
