You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like it to ignore the top non-English letters as I don't need them, but I don't know how to ignore them. I thought about removing the index of these areas but unfortunately the index is not the same for all plate numbers so it's not going to work. Does anyone know how I can take the contours of the numbers and the bottom English letters only without the top non-English letters. I would highly appreciate your help.
The image:
The code:
`
import cv2
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import gridspec
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
img = cv2.imread('c1.png')
img1 = img.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(7,7),0)
I would like it to ignore the top non-English letters as I don't need them, but I don't know how to ignore them. I thought about removing the index of these areas but unfortunately the index is not the same for all plate numbers so it's not going to work. Does anyone know how I can take the contours of the numbers and the bottom English letters only without the top non-English letters. I would highly appreciate your help.
The image:
The code:
`
import cv2
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import gridspec
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
img = cv2.imread('c1.png')
img1 = img.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(7,7),0)
binary = cv2.threshold(blur, 180, 255,cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
kernel3 = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
thre_mor = cv2.morphologyEx(binary, cv2.MORPH_DILATE, kernel3)
contours, hierarchy = cv2.findContours(thre_mor,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
def sort_contours(cnts,reverse = False):
i = 0
boundingBoxes = [cv2.boundingRect(c) for c in cnts]
(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),key=lambda b: b[1][i], reverse=reverse))
return cnts
cont, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
crop_characters = []
digit_w, digit_h = 30, 60
for c in sort_contours(cont):
(x, y, w, h) = cv2.boundingRect(c)
ratio = h/w
if 1<=ratio<=10:
print("Detect {} letters...".format(len(crop_characters)))
fig = plt.figure(figsize=(10,6))
plt.axis(False)
plt.imshow(img1)
plt.show()`
The output:
The text was updated successfully, but these errors were encountered: