I want to pre-process the patent plate and then enter an OCR.
In the part that I am, I have to do things in general, because I am working only with one image, but later they will be more and at different angles.
I am in the part where I insert filters, I wonder if the next part is to find the contours or straighten it (for this I am using hough transform).
Working on colab:
!pip install pytesseract
import cv2
import numpy as np
import matplotlib.pyplot as plt
import pytesseract
plt.style.use('dark_background')
crop_img = cv2.imread('/content/0.png')
#IMG2GRAY
gray = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
plt.imshow(gray)
#tresh
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
plt.imshow(thresh)
# Otsu's thresholding after Gaussian filtering
blur = cv2.GaussianBlur(thresh,(5,5),0)
th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
plt.imshow(th3)
plt.show()
The output I have, which I think this is bad:
And this is the image:
And this is the output when I rotate the image with HoughTransform:
The final result should be something like this (but remember that I will use the same preprocessing for other images):




