Hi I am trying to read car permits area but tesseract doens’t read some areas completely.
Here is my code and processes;
- I firstly align image with template. (I will add the template.)
- set image dpi with below code;
Code;
def set_image_dpi(file_path):
IMAGE_SIZE = 1800
im = Image.open(file_path)
length_x, width_y = im.size
factor = max(1, int(IMAGE_SIZE / length_x))
size = factor * length_x, factor * width_y
# size = (1800, 1800)
im_resized = im.resize(size, Image.ANTIALIAS)
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.jpg')
temp_filename = temp_file.name
im_resized.save(temp_filename, dpi=(300, 300))
return temp_filename
- Then I remove noise and crop the confident boxes;
code;
def remove_noise(image):
return cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 15)
if box.conf[0] > 0.20:
class_name = classes_names[int(box.cls[0])]
custom = False
custom_config_str = ""
[x1, y1, x2, y2] = box.xyxy[0]
# convert to int
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
cropped = frame[y1:y2, x1:x2]
cropped = remove_noise(cropped)
cropped = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
# blur
blur = cv2.GaussianBlur(cropped, (0, 0), sigmaX=99, sigmaY=99)
# divide
cropped = cv2.divide(cropped, blur, scale=255)
Then tesseract code;
text = pytesseract.image_to_string(
cropped,
config=None if custom != True else "-psm 6,
lang="tur")
here is the saved results that I can share and raw text results. What Can cause the misrecognizing text and what processes I can add to get more clear results? Because the images are really clean but many sometimes I can not get any data from them.
text: DJTICARIADI n
text: DIMARKASI nRENALLI
text: /Y.3/KULLANIMAMACI n YOLCUNAKLİ-HUSUSİİ