Как читать символы в прямоугольнике обнаруженных объектов? - PullRequest
0 голосов
/ 17 марта 2020

У меня получилось успешно с API обнаружения объектов tenorflow, как на картинке ниже.

tf numberplate detection

, но теперь я хочу прочитать символ внутри зеленой рамки, как сделать это?

Ответы [ 2 ]

0 голосов
/ 19 марта 2020
# Load image using OpenCV and
# expand image dimensions to have shape: [1, None, None, 3]
# i.e. a single-column array, where each item in the column has the pixel RGB value
image = cv2.imread(PATH_TO_IMAGE)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_expanded = np.expand_dims(image_rgb, axis=0)

# Perform the actual detection by running the model with the image as input
(boxes, scores, classes, num) = sess.run(
    [detection_boxes, detection_scores, detection_classes, num_detections],
    feed_dict={image_tensor: image_expanded})

# Draw the results of the detection (aka 'visulaize the results')

vis_util.visualize_boxes_and_labels_on_image_array(
    image,
    np.squeeze(boxes),
    np.squeeze(classes).astype(np.int32),
    np.squeeze(scores),
    category_index,
    use_normalized_coordinates=True,
    line_thickness=1,
    min_score_thresh=0.60)

# All the results have been drawn on image. Now display the image.
cv2.imshow('Object detector', image)
0 голосов
/ 17 марта 2020

Сначала вам нужно обрезать ограничивающие рамки тарелок, а затем вы можете использовать tesseract . Чтобы получить текст. Псевдокод вашей проблемы может выглядеть так:

import cv2
import pytesseract

original_img = cv2.imread("/path/to/your/img.png")

for plate in detected_plates:
     if plate.confidence > 0.98:
         b_box = plate.bounding_rect  # bounding box in [x, y, w, h]
         img_cropped = original_img[b_box[1]: b_box[1] + b_box[3], b_box[0]: b_box[0] + b_box[2]]
         print(pytesseract.image_to_string(img_cropped))
...