Skip to content

Commit

Permalink
Initial commit or another suitable message
Browse files Browse the repository at this point in the history
  • Loading branch information
3bdul1ah committed Sep 6, 2023
0 parents commit a26a01f
Show file tree
Hide file tree
Showing 106 changed files with 1,382 additions and 0 deletions.
Empty file added !
Empty file.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/car plate.v26i.yolov8.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions TESTING.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('runs/detect/train18/weights/best.pt')

# Define remote image or video URL
source = 'https://source.roboflow.com/dRDeH1hYd0WQDBtCSKP39MHuZOY2/3eO0urIBcEjzYDWshuFg/original.jpg'

# Run inference on the source
results = model(source) # list of Results objects
13 changes: 13 additions & 0 deletions data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
path: C:\Users\Ahmed\PycharmProjects\car plate.v26i.yolov8\data
train: train/images
val: valid/images
test: test/images
nc: 51
names: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'exp', 'new_DUBAI', 'new_RAK', 'new_abudabi', 'new_ajman', 'new_am', 'new_fujairah', 'old_DUBAI', 'old_RAK', 'old_abudabi', 'old_ajman', 'old_am', 'old_fujira', 'old_sharka', 'plate']

roboflow:
workspace: zara-hara
project: car-plate-k6xij
version: 26
license: CC BY 4.0
url: https://universe.roboflow.com/zara-hara/car-plate-k6xij/dataset/26
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.yaml") # build a new model from scratch

# Use the model
model.train(data="data.yaml", epochs=3) # train the model
Binary file added original.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions plate_only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import os
from ultralytics import YOLO
import cv2
import requests
import numpy as np
from io import BytesIO
import matplotlib.pyplot as plt

model_path = os.path.join('.', 'runs', 'detect', 'train23', 'weights', 'last.pt')

specific_classes = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
state_classes = {
'exp': 'Export',
'new_DUBAI': 'Dubai',
'new_RAK': 'Ras Al-Kaimah',
'new_abudabi': 'Abu Dhabi',
'new_ajman': 'Ajman',
'new_am': 'Umm Al Quwain',
'new_fujairah': 'Fujairah',
'old_DUBAI': 'Dubai',
'old_RAK': 'Ras Al-Kaimah',
'old_abudabi': 'Abu Dhabi',
'old_ajman': 'Ajman',
'old_am': 'Umm Al-Quwain',
'old_fujira': 'Fujairah',
'old_sharka': 'Sharjah'
}

# Load a model
model = YOLO(model_path) # load a custom model

threshold = 0.4


def detect_text(image):
output_array = []
state_name = "couldn\'t be detected"

H, W, _ = image.shape

results = model(image)[0]

# Sort the results by the x-axis position
sorted_results = sorted(results.boxes.data.tolist(), key=lambda x: x[0])


for x1, y1, x2, y2, score, class_id in sorted_results:
class_name = model.names[class_id]

if (score > threshold) and (class_name in specific_classes):
output_array.append(class_name)



for x1, y1, x2, y2, score, class_id in sorted_results:
class_name = model.names[class_id]
if score > threshold and (class_name in state_classes):
state_name = state_classes[class_name]
break


if 'D' in output_array and 'Q' in output_array: #error correction
output_array.remove('Q')



return output_array , state_name


def main():
# URL list containing image URLs
image_urls = [
'https://c8.alamy.com/comp/A8G1XR/luxury-car-bmw-with-dubai-license-plate-photo-by-willy-matheisl-A8G1XR.jpg',
# Add more image URLs here
]

for image_url in image_urls:
response = requests.get(image_url)
if response.status_code == 200:
image_data = BytesIO(response.content)
image = cv2.imdecode(np.frombuffer(image_data.read(), np.uint8), cv2.IMREAD_COLOR)

H, W, _ = image.shape

results = model(image)[0]

sorted_results = sorted (results.boxes.data.tolist (), key=lambda x: x[0])

for result in sorted_results:
x1, y1, x2, y2, score, class_id = result

if score > threshold and results.names[int(class_id)] == 'plate':
cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 4)
plate_img = image[int(y1):int(y2), int(x1):int(x2)]
output , state = detect_text(plate_img)
print(output)
print(f"The state this car belongs to {state}")


plt.figure()
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))

plt.show()

else:
print(f"Failed to retrieve image from URL: {image_url}")


if __name__ == "__main__":
main()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions runs/detect/train/args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
task: detect
mode: train
model: yolov8n.yaml
data: data.yaml
epochs: 3
patience: 50
batch: 16
imgsz: 640
save: true
save_period: -1
cache: false
device: null
workers: 8
project: null
name: null
exist_ok: false
pretrained: true
optimizer: auto
verbose: true
seed: 0
deterministic: true
single_cls: false
rect: false
cos_lr: false
close_mosaic: 10
resume: false
amp: true
fraction: 1.0
profile: false
freeze: null
overlap_mask: true
mask_ratio: 4
dropout: 0.0
val: true
split: val
save_json: false
save_hybrid: false
conf: null
iou: 0.7
max_det: 300
half: false
dnn: false
plots: true
source: null
show: false
save_txt: false
save_conf: false
save_crop: false
show_labels: true
show_conf: true
vid_stride: 1
stream_buffer: false
line_width: null
visualize: false
augment: false
agnostic_nms: false
classes: null
retina_masks: false
boxes: true
format: torchscript
keras: false
optimize: false
int8: false
dynamic: false
simplify: false
opset: null
workspace: 4
nms: false
lr0: 0.01
lrf: 0.01
momentum: 0.937
weight_decay: 0.0005
warmup_epochs: 3.0
warmup_momentum: 0.8
warmup_bias_lr: 0.1
box: 7.5
cls: 0.5
dfl: 1.5
pose: 12.0
kobj: 1.0
label_smoothing: 0.0
nbs: 64
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
degrees: 0.0
translate: 0.1
scale: 0.5
shear: 0.0
perspective: 0.0
flipud: 0.0
fliplr: 0.5
mosaic: 1.0
mixup: 0.0
copy_paste: 0.0
cfg: null
tracker: botsort.yaml
save_dir: runs\detect\train
Binary file added runs/detect/train/labels.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/detect/train/labels_correlogram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions runs/detect/train/results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
epoch, train/box_loss, train/cls_loss, train/dfl_loss, metrics/precision(B), metrics/recall(B), metrics/mAP50(B), metrics/mAP50-95(B), val/box_loss, val/cls_loss, val/dfl_loss, lr/pg0, lr/pg1, lr/pg2
1, 4.4059, 7.2949, 3.9288, 0.35655, 0.0046, 0.00174, 0.00047, 3.2456, 5.315, 3.2751, 6.057e-05, 6.057e-05, 6.057e-05
2, 3.1671, 4.2795, 2.623, 0.09093, 0.02468, 0.01277, 0.00496, 2.8609, 3.8934, 2.029, 8.1229e-05, 8.1229e-05, 8.1229e-05
3, 2.7716, 3.3153, 1.8106, 0.11494, 0.02624, 0.01891, 0.00866, 2.4415, 3.1568, 1.6992, 6.1847e-05, 6.1847e-05, 6.1847e-05
Binary file added runs/detect/train/results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/detect/train/train_batch0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/detect/train/train_batch1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/detect/train/train_batch2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/detect/train/weights/best.pt
Binary file not shown.
Binary file added runs/detect/train/weights/last.pt
Binary file not shown.
98 changes: 98 additions & 0 deletions runs/detect/train17/args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
task: detect
mode: train
model: yolov8n.yaml
data: data.yaml
epochs: 600
patience: 50
batch: 16
imgsz: 640
save: true
save_period: -1
cache: false
device: null
workers: 8
project: null
name: null
exist_ok: false
pretrained: true
optimizer: auto
verbose: true
seed: 0
deterministic: true
single_cls: false
rect: false
cos_lr: false
close_mosaic: 10
resume: false
amp: true
fraction: 1.0
profile: false
freeze: null
overlap_mask: true
mask_ratio: 4
dropout: 0.0
val: true
split: val
save_json: false
save_hybrid: false
conf: null
iou: 0.7
max_det: 300
half: false
dnn: false
plots: true
source: null
show: false
save_txt: false
save_conf: false
save_crop: false
show_labels: true
show_conf: true
vid_stride: 1
stream_buffer: false
line_width: null
visualize: false
augment: false
agnostic_nms: false
classes: null
retina_masks: false
boxes: true
format: torchscript
keras: false
optimize: false
int8: false
dynamic: false
simplify: false
opset: null
workspace: 4
nms: false
lr0: 0.01
lrf: 0.01
momentum: 0.937
weight_decay: 0.0005
warmup_epochs: 3.0
warmup_momentum: 0.8
warmup_bias_lr: 0.1
box: 7.5
cls: 0.5
dfl: 1.5
pose: 12.0
kobj: 1.0
label_smoothing: 0.0
nbs: 64
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
degrees: 0.0
translate: 0.1
scale: 0.5
shear: 0.0
perspective: 0.0
flipud: 0.0
fliplr: 0.5
mosaic: 1.0
mixup: 0.0
copy_paste: 0.0
cfg: null
tracker: botsort.yaml
save_dir: runs\detect\train17
Binary file added runs/detect/train17/labels.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/detect/train17/labels_correlogram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a26a01f

Please sign in to comment.