Spaces:
Sleeping
Sleeping
more to run the app
Browse files
__pycache__/xyxy_converter.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/xyxy_converter.cpython-310.pyc and b/__pycache__/xyxy_converter.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -60,26 +60,27 @@ def main():
|
|
| 60 |
--weights {MODEL_PATH} \
|
| 61 |
--source {image_path} \
|
| 62 |
--img 640 \
|
| 63 |
-
--conf 0.
|
| 64 |
--name temp_exp \
|
| 65 |
--hide-labels \
|
| 66 |
--hide-conf \
|
| 67 |
--save-txt \
|
| 68 |
-
--exist-ok
|
|
|
|
| 69 |
'''
|
| 70 |
|
| 71 |
# Run the command
|
| 72 |
os.system(command)
|
| 73 |
|
| 74 |
-
st.write('The detection is completed!!!')
|
| 75 |
|
| 76 |
os.chdir(CUR_DIR)
|
| 77 |
|
| 78 |
-
st.write(os.path.exists('yolov5/runs/detect/temp_exp'))
|
| 79 |
|
| 80 |
if os.path.exists('yolov5/runs/detect/temp_exp'):
|
| 81 |
processed_image = cv2.imread('yolov5/runs/detect/temp_exp/odometer_image.jpg')
|
| 82 |
-
st.write('Image boxed and loaded')
|
| 83 |
text_files = os.listdir('yolov5/runs/detect/temp_exp/labels')
|
| 84 |
original_img = cv2.imread('odometer_image.jpg')
|
| 85 |
gray = cv2.cvtColor(original_img, cv2.COLOR_BGR2GRAY)
|
|
@@ -89,7 +90,7 @@ def main():
|
|
| 89 |
else:
|
| 90 |
text_file_path = f'yolov5/runs/detect/temp_exp/labels/{text_files[0]}'
|
| 91 |
x1, y1, x2, y2 = yolov5_to_image_coordinates(text_file_path)
|
| 92 |
-
st.write(x1, y1, x2, y2)
|
| 93 |
cropped_image = gray[x1:x2, y1:y2]
|
| 94 |
|
| 95 |
reader = easyocr.Reader(['en'])
|
|
@@ -101,14 +102,16 @@ def main():
|
|
| 101 |
else:
|
| 102 |
odometer_value = 'not detected'
|
| 103 |
display_text = f"The odometer value is {odometer_value}!!!"
|
| 104 |
-
try:
|
| 105 |
-
shutil.rmtree('odometer_image.jpg')
|
| 106 |
-
except:
|
| 107 |
-
pass
|
| 108 |
else:
|
| 109 |
display_text = "An odometer is not detected in the image!!!"
|
| 110 |
processed_image = cv2.imread('odometer_image.jpg')
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
# Resize or preprocess the image as needed for your model
|
| 113 |
# For example, resizing to a specific input size
|
| 114 |
# processed_image = cv2.resize(image_np, (224, 224))
|
|
|
|
| 60 |
--weights {MODEL_PATH} \
|
| 61 |
--source {image_path} \
|
| 62 |
--img 640 \
|
| 63 |
+
--conf 0.4 \
|
| 64 |
--name temp_exp \
|
| 65 |
--hide-labels \
|
| 66 |
--hide-conf \
|
| 67 |
--save-txt \
|
| 68 |
+
--exist-ok \
|
| 69 |
+
--save-conf
|
| 70 |
'''
|
| 71 |
|
| 72 |
# Run the command
|
| 73 |
os.system(command)
|
| 74 |
|
| 75 |
+
# st.write('The detection is completed!!!')
|
| 76 |
|
| 77 |
os.chdir(CUR_DIR)
|
| 78 |
|
| 79 |
+
# st.write(os.path.exists('yolov5/runs/detect/temp_exp'))
|
| 80 |
|
| 81 |
if os.path.exists('yolov5/runs/detect/temp_exp'):
|
| 82 |
processed_image = cv2.imread('yolov5/runs/detect/temp_exp/odometer_image.jpg')
|
| 83 |
+
# st.write('Image boxed and loaded')
|
| 84 |
text_files = os.listdir('yolov5/runs/detect/temp_exp/labels')
|
| 85 |
original_img = cv2.imread('odometer_image.jpg')
|
| 86 |
gray = cv2.cvtColor(original_img, cv2.COLOR_BGR2GRAY)
|
|
|
|
| 90 |
else:
|
| 91 |
text_file_path = f'yolov5/runs/detect/temp_exp/labels/{text_files[0]}'
|
| 92 |
x1, y1, x2, y2 = yolov5_to_image_coordinates(text_file_path)
|
| 93 |
+
# st.write(x1, y1, x2, y2)
|
| 94 |
cropped_image = gray[x1:x2, y1:y2]
|
| 95 |
|
| 96 |
reader = easyocr.Reader(['en'])
|
|
|
|
| 102 |
else:
|
| 103 |
odometer_value = 'not detected'
|
| 104 |
display_text = f"The odometer value is {odometer_value}!!!"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
else:
|
| 106 |
display_text = "An odometer is not detected in the image!!!"
|
| 107 |
processed_image = cv2.imread('odometer_image.jpg')
|
| 108 |
|
| 109 |
+
try:
|
| 110 |
+
shutil.rmtree('odometer_image.jpg')
|
| 111 |
+
shutil.rmtree('runs/detect/temp_exp')
|
| 112 |
+
except:
|
| 113 |
+
pass
|
| 114 |
+
|
| 115 |
# Resize or preprocess the image as needed for your model
|
| 116 |
# For example, resizing to a specific input size
|
| 117 |
# processed_image = cv2.resize(image_np, (224, 224))
|
odometer_image.jpg
CHANGED
|
|
xyxy_converter.py
CHANGED
|
@@ -14,8 +14,14 @@ def yolov5_to_image_coordinates(text_file, image_width=640, image_height=640):
|
|
| 14 |
with open(text_file, 'r') as f:
|
| 15 |
xywh_text = f.read()
|
| 16 |
|
| 17 |
-
xywh_splitted = xywh_text.split('\n')
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# yolo_box = [float(i) for i in xywh_text.replace('\n', '').split(' ')[1:]]
|
| 20 |
|
| 21 |
x_center, y_center, width, height = yolo_box
|
|
|
|
| 14 |
with open(text_file, 'r') as f:
|
| 15 |
xywh_text = f.read()
|
| 16 |
|
| 17 |
+
xywh_splitted = xywh_text.split('\n')
|
| 18 |
+
if xywh_splitted[-1] == '':
|
| 19 |
+
xywh_splitted = xywh_text.split('\n')[0]
|
| 20 |
+
else:
|
| 21 |
+
conf_list = [float(i.split(' ')[-1]) for i in xywh_splitted]
|
| 22 |
+
max_conf_idx = conf_list.index(max(conf_list))
|
| 23 |
+
xywh_splitted = xywh_text.split('\n')[max_conf_idx]
|
| 24 |
+
yolo_box = [float(i) for i in xywh_splitted.split(' ')[1:-1]]
|
| 25 |
# yolo_box = [float(i) for i in xywh_text.replace('\n', '').split(' ')[1:]]
|
| 26 |
|
| 27 |
x_center, y_center, width, height = yolo_box
|
yolov5/runs/detect/temp_exp/labels/odometer_image.txt
CHANGED
|
@@ -1,10 +1,2 @@
|
|
| 1 |
-
0 0.
|
| 2 |
-
0 0.
|
| 3 |
-
0 0.452344 0.715625 0.429688 0.18125
|
| 4 |
-
0 0.409375 0.657031 0.375 0.148438
|
| 5 |
-
0 0.409375 0.657031 0.375 0.148438
|
| 6 |
-
0 0.409375 0.657031 0.375 0.148438
|
| 7 |
-
0 0.564844 0.671094 0.207813 0.0859375
|
| 8 |
-
0 0.442187 0.621094 0.38125 0.139062
|
| 9 |
-
0 0.510156 0.665625 0.254687 0.11875
|
| 10 |
-
0 0.539062 0.586719 0.375 0.201562
|
|
|
|
| 1 |
+
0 0.617188 0.760156 0.128125 0.0515625 0.718977
|
| 2 |
+
0 0.579687 0.696875 0.265625 0.121875 0.872913
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yolov5/runs/detect/temp_exp/odometer_image.jpg
CHANGED
|
|