Exemple #1
0
def run_lpr():
    logging.info(f'Debug mode {app.debug}')

    if request.method == 'POST':
        file = request.files['file']
        img_bytes = file.read()
        file.close()

        if(img_bytes is not None):
            nparr = np.fromstring(img_bytes, np.uint8)
            inputImage = cv.imdecode(nparr, cv.IMREAD_COLOR)

            # TODO: state management: avoid loading net for every request
            yolo = Yolo(img_width=1056, img_height=576, 
                        debug=DEBUG, confidence_threshold=0.6, non_max_supress_theshold=0.4,
                        classes_filename='../config/classes.names',
                        model_architecture_filename="../config/yolov3_license_plates.cfg", 
                        model_weights_filename="../config/yolov3_license_plates_last.weights",
                        output_directory='../debug/')                   

            roi_imgs = yolo.detect(inputImage)

            ocr = OCR(model_filename="../config/emnist_net_custom.pt", num_classes=36, use_cuda=False, debug=DEBUG)

            index = 0
            for roi_img in roi_imgs:
                logging.info(f'\n\nProcessing ROI {index}')
                box = [yolo.bounding_boxes[index][0], yolo.bounding_boxes[index][1], yolo.bounding_boxes[index][2], yolo.bounding_boxes[index][3]]
                predict(yolo.img, roi_img, box, str(index), (0,255,0), ocr)
                index += 1

            # API response: the highest confidence one
            logging.info(f'\n\n---Processing the Highest Confidence ROI---\n')
            bounding_box = None
            emnist_net_preds = None
            tesseract_preds = None
            if(yolo.highest_object_confidence > 0 and yolo.roi_img is not None):
                bounding_box = {
                    'x': yolo.box_x,
                    'y': yolo.box_y,
                    'w': yolo.box_w,
                    'h': yolo.box_h
                }                                
                _, emnist_net_preds, tesseract_preds = predict(yolo.img, yolo.roi_img, [yolo.box_x, yolo.box_y, yolo.box_w, yolo.box_h], "", (255,255,0), ocr)                                
                if(DEBUG):                    
                    cv.imwrite("../debug/result.jpg", yolo.img.astype(np.uint8))
    
            data = {
                'bounding_box': bounding_box,
                'confidence': yolo.highest_object_confidence,
                'classId': str(yolo.classId_highest_object),
                'emnist_net_preds': emnist_net_preds,
                'tesseract_preds': tesseract_preds
            }
            response = jsonify(data)

    response.status_code = 200
    return response
Exemple #2
0
t0 = time.time()

while True:
  count = src_skip

  while count>=1:
    count -= 1
    grabbed, image = vid.read()
    if not grabbed: break
    if src_mirror: 
      image = cv2.flip(image, 1)
    if src_scale!=1:
      image = cv2.resize(image,(0,0),fx=src_scale,fy=src_scale)

  # Apply yolo
  yolo.detect(image,0.25,0.3)
  yolo.annotate(image)

  list = []
  if len(yolo.idxs) > 0:
    for i in yolo.idxs.flatten():
      list.append( yolo.LABELS[yolo.classIDs[i]] )
      print ( list )

  t1 = time.time()
  elap = t1-t0
  t0 = t1

  fps = round(1/elap)
  text = ("%d fps"%fps)
  cv2.putText(image,text,(10,20),cv2.FONT_HERSHEY_SIMPLEX, 0.5, [0,128,255], 2)
Exemple #3
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Testing YOLO...')
    parser.add_argument('--image', help='Path to image file.')
    args = parser.parse_args()

    yolo = Yolo(
        img_width=1056,
        img_height=576,
        debug=True,
        confidence_threshold=0.6,
        non_max_supress_theshold=0.4,
        classes_filename='../config/classes.names',
        model_architecture_filename="../config/yolov3_license_plates.cfg",
        model_weights_filename="../config/yolov3_license_plates_last.weights",
        output_directory='../debug/')

    # Open the image file
    if not os.path.isfile(args.image):
        print("Input image file ", args.image, " doesn't exist")
        sys.exit(1)
    cap = cv.VideoCapture(args.image)

    # get frame
    hasFrame, frame = cap.read()

    if hasFrame:
        yolo.detect(frame)
    else:
        print("Frame not found!")
Exemple #4
0
        classes_filename='../config/classes.names',
        model_architecture_filename="../config/yolov3_license_plates.cfg",
        model_weights_filename="../config/yolov3_license_plates_last.weights",
        output_directory='../debug/',
        output_image=False)

    ocr = OCR(model_filename="../config/attention_ocr_model.pth",
              use_cuda=False,
              threshold=0.7)

    cap = cv.VideoCapture(args.input)

    while (cap.isOpened()):
        hasFrame, frame = cap.read()
        if hasFrame:
            roi_imgs = yolo.detect(frame)
            index = 0
            for roi_img in roi_imgs:
                box = [
                    yolo.bounding_boxes[index][0],
                    yolo.bounding_boxes[index][1],
                    yolo.bounding_boxes[index][2],
                    yolo.bounding_boxes[index][3]
                ]
                pred = ocr.predict(roi_img)
                draw_bounding_box(input_image=frame,
                                  bounding_box=box,
                                  label=pred,
                                  background_color=(0, 255, 0),
                                  ocr=ocr)
                index += 1
Exemple #5
0
from yolo import Yolo
import cv2




imagepath = "images/dining_table.jpg"

yolofiles = {
  "config":  "yolo-coco/yolov3.cfg",
  "weights": "yolo-coco/yolov3.weights",
  "names":   "yolo-coco/coco.names"
}


yolo = Yolo(yolofiles)

# load our input image and grab its spatial dimensions
image = cv2.imread(imagepath)

yolo.detect(image) #,confidence=0.0,threshold=0.0)
yolo.annotate(image)

# show the output image
cv2.imshow("Image", image)
cv2.waitKey(0)