Как сделать проверку на детектирование номера автомобиля?
Номер хранится в переменной pred_texts, при этом вывод происходит достаточно часто, меняется только одна буква/цифра
if ret:
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
with_cascade = face_cascade.detectMultiScale(image, 1.3, 7)
for i, (x, y, w, h) in enumerate(with_cascade):
roi_color = image[y:y + h, x:x + w]
r = 300.0 / roi_color.shape[1]
dim = (400, int(roi_color.shape[0] * r))
resized = cv2.resize(roi_color, dim, interpolation=cv2.INTER_AREA)
w_resized = resized.shape[0]
h_resized = resized.shape[1]
image[380:380 + w_resized, 235:235 + h_resized] = resized
letters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'O',
'P', 'T', 'X', 'Y']
def decode_batch(out):
ret = []
for j in range(out.shape[0]):
out_best = list(np.argmax(out[j, 2:], 1))
out_best = [k for k, g in itertools.groupby(out_best)]
outstr = ''
for c in out_best:
if c < len(letters):
outstr += letters[c]
ret.append(outstr)
return ret
paths = 'model1_nomer.tflite'
interpreter = tf.lite.Interpreter(model_path=paths)
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
img = resized
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, (128, 64))
img = img.astype(np.float32)
img /= 255
img1 = img.T
img1.shape
X_data1 = np.float32(img1.reshape(1, 128, 64, 1))
input_index = (interpreter.get_input_details()[0]['index'])
interpreter.set_tensor(input_details[0]['index'], X_data1)
interpreter.invoke()
net_out_value = interpreter.get_tensor(output_details[0]['index'])
pred_texts = decode_batch(net_out_value)
if a != pred_texts:
a = pred_texts
print(a)
else:
print("Номер не распознан")
Каким образом сделать "некую" проверку? Допустим, если номер три раза одинаковый, то его вывести?