From d070152e98e373dbbbb50da66161d8ff72ad1507 Mon Sep 17 00:00:00 2001 From: johnng0805 Date: Fri, 17 Jun 2022 09:51:03 +0700 Subject: [PATCH] Demo #1 --- detect.py | 22 +++++++++++++--------- utils/image_crop.py | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/detect.py b/detect.py index 00ede86b6dce..847757b7c0e7 100644 --- a/detect.py +++ b/detect.py @@ -59,7 +59,7 @@ def run( imgsz=(640, 640), # inference size (height, width) conf_thres=0.25, # confidence threshold iou_thres=0.45, # NMS IOU threshold - max_det=1000, # maximum detections per image + max_det=10, # maximum detections per image device='', # cuda device, i.e. 0 or 0,1,2,3 or cpu view_img=False, # show results save_txt=False, # save results to *.txt @@ -99,8 +99,7 @@ def run( imgsz = check_img_size(imgsz, s=stride) # check image size # Load Alpr - alpr = Alpr("us", "/usr/share/openalpr/runtime_data/config/us.conf", - "/usr/share/openalpr/runtime_data") + alpr = Alpr(os.environ['COUNTRY_CODE'], os.environ['ALPR_CONFIG'], os.environ['ALPR_RUNTIME']) if not alpr.is_loaded(): print("Error loading OpenALPR") else: @@ -185,10 +184,10 @@ def run( # with open(f'{txt_path}.txt', 'a') as f: # f.write(('%g ' * len(line)).rstrip() % line + '\n') - # if save_img or save_crop or view_img: # Add bbox to image - # c = int(cls) # integer class - # label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}') - # annotator.box_label(xyxy, label, color=colors(c, True)) + if save_img or save_crop or view_img: # Add bbox to image + c = int(cls) # integer class + label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}') + annotator.box_label(xyxy, label, color=colors(c, True)) # if save_crop: # save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True) c = int(cls) @@ -197,10 +196,15 @@ def run( plate_num = alpr.recognize_ndarray(imCrop) if (plate_num['results'] != []): - plate = plate_num['results'][0]['plate'] + plate = plate_num['results'][0]['plate'].replace("\n", "") + data = None if plate and plate != prev_plate: - data = {'plate_num': plate} + if len(plate) >= 8: + data = {'plate_num': plate} + print(plate) + else: + pass try: r = requests.post(API_ENDPOINT, json=data, timeout=1.5) diff --git a/utils/image_crop.py b/utils/image_crop.py index 126a53154817..a28e730b3c57 100644 --- a/utils/image_crop.py +++ b/utils/image_crop.py @@ -25,6 +25,6 @@ def crop(xyxy, im, square=False, gain=1.02, pad=10, BGR=False): medBlur = cv2.medianBlur(gray, 3) - gaussBlur = cv2.GaussianBlur(medBlur, (5, 5), 0) + gaussBlur = cv2.GaussianBlur(gray, (3, 3), 0) return gaussBlur