コード例 #1
0
# Import all necessary libraries.
import sys
import glob
import matplotlib.image as mpimg
import cv2
import copy

# NomeroffNet path
NOMEROFF_NET_DIR = os.path.abspath('../../')
sys.path.append(NOMEROFF_NET_DIR)

from NomeroffNet.YoloV5Detector import Detector

detector = Detector()
detector.load()

rootDir = '../images/*'

imgs = [mpimg.imread(img_path) for img_path in glob.glob(rootDir)]

for img in imgs:
    targetBoxes = detector.detect_bbox(copy.deepcopy(img))
    targetBoxes = targetBoxes

    # draw rect and 4 points
    for targetBox in targetBoxes:
        cv2.rectangle(img, (int(targetBox[0]), int(targetBox[1])),
                      (int(targetBox[2]), int(targetBox[3])), (0, 0, 0), -1)
    cv2.imshow("Display window", img)
    k = cv2.waitKey(0)
コード例 #2
0
detector = Detector()
detector.load()

from NomeroffNet.TextDetectors.eu import eu
from NomeroffNet.TextPostprocessing import textPostprocessing

# load models
textDetector = eu
textDetector.load("latest")

# Detect numberplate
img_path = '../images/example2.jpeg'
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

targetBoxes = detector.detect_bbox(img)

zones = []
regionNames = []
for targetBox in targetBoxes:
    x = int(min(targetBox[0], targetBox[2]))
    w = int(abs(targetBox[2] - targetBox[0]))
    y = int(min(targetBox[1], targetBox[3]))
    h = int(abs(targetBox[3] - targetBox[1]))

    image_part = img[y:y + h, x:x + w]
    zones.append(image_part)
    regionNames.append('eu')

# find text with postprocessing by standart
textArr = textDetector.predict(zones)