Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
johnng0805 committed Jun 17, 2022
1 parent d75d688 commit d070152
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion utils/image_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d070152

Please sign in to comment.