Abhinav Deshpande commited on
Configure LFS
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +3 -0
- .gitignore +54 -0
- Backend/BrandRecognition/Dynamic/Brand_Count_Vid.py +135 -0
- Backend/BrandRecognition/Static/Brand_Count_Img.py +132 -0
- Backend/Fruit_Freshness/Apples/Photos/Fresh_1.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Fresh_2.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Fresh_3.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Fresh_4.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Fresh_5.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Rotten_1.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Rotten_2.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Rotten_3.png +0 -0
- Backend/Fruit_Freshness/Apples/Photos/Rotten_4.png +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8.zip +3 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/README.dataset.txt +6 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/README.roboflow.txt +32 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/data.yaml +13 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-2-54-49-PM_png.rf.2557a1048acae352cd5420528e467e18.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-2-57-13-PM_png.rf.e9da17a0710d447581911d0a686a64bb.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-3-02-24-PM_png.rf.fce9e910b977026e4356db03caaf7835.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-3-02-51-PM_png.rf.193331860c01427edcafb663e15d5f8c.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-2-54-49-PM_png.rf.2557a1048acae352cd5420528e467e18.txt +1 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-2-57-13-PM_png.rf.e9da17a0710d447581911d0a686a64bb.txt +1 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-3-02-24-PM_png.rf.fce9e910b977026e4356db03caaf7835.txt +1 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-3-02-51-PM_png.rf.193331860c01427edcafb663e15d5f8c.txt +1 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-20-PM_png.rf.17a1184c9996ed00a4e7f232de6060ea.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-20-PM_png.rf.82f8c8cd7117007c6c219b76568b83a4.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-20-PM_png.rf.e324b699b3d1948c6212a7ec533fe981.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-33-PM_png.rf.163b037e01da46c3ec715755c291aa95.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-33-PM_png.rf.89f62e24f24e80e8031ce669fb74718e.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-33-PM_png.rf.bb9cacf69bb23894866f1982caea0ccf.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-08-PM_png.rf.5ed4084cc0d8b7812c8cc819480ba10f.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-08-PM_png.rf.ac4d108659b63c81acf73865dc81ee9c.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-58-PM_png.rf.0bab53e4576f3dcdc3eecbad1f2e2a25.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-58-PM_png.rf.10803b835c52cbd24433f1a0515668e4.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-58-PM_png.rf.bd3f4db76c39859bc11bcf30418b654e.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-55-27-PM_png.rf.40e834e8eb8867403264b94970229392.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-55-27-PM_png.rf.449428299a5d3574754e53017cb74a08.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-55-27-PM_png.rf.dcf06ba791b8c9e2ed6a5deaecff39b9.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-56-57-PM_png.rf.227c73b163d364d8da4dc460d373e21a.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-56-57-PM_png.rf.83e9e5ac4fcaee7b11b3a535c0c1d2ef.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-56-57-PM_png.rf.970a7fa1fa583318b57baa9255ef021d.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-05-PM_png.rf.51d0712871be1b778ac39dbe8d10392b.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-05-PM_png.rf.ddd660cf6503243277404540b277a30f.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-05-PM_png.rf.f891d92a399c50347fff17b9721486e1.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-26-PM_png.rf.5ae2dbffe4997cd0502a4604f79b5a4a.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-26-PM_png.rf.8cf78686362e2f91096c65afa93974cf.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-26-PM_png.rf.dbb43335e14c7a61d9719fc63e744a46.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-42-PM_png.rf.7f27375200a5f1f25f11cfc2dadaa1cc.jpg +0 -0
- Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-42-PM_png.rf.a4416d86ea25aad74339a40630da321e.jpg +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.ipynb filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
|
| 5 |
+
# C extensions
|
| 6 |
+
*.so
|
| 7 |
+
|
| 8 |
+
# Distribution / packaging
|
| 9 |
+
bin/
|
| 10 |
+
build/
|
| 11 |
+
develop-eggs/
|
| 12 |
+
dist/
|
| 13 |
+
eggs/
|
| 14 |
+
lib/
|
| 15 |
+
lib64/
|
| 16 |
+
parts/
|
| 17 |
+
sdist/
|
| 18 |
+
var/
|
| 19 |
+
*.egg-info/
|
| 20 |
+
.installed.cfg
|
| 21 |
+
*.egg
|
| 22 |
+
|
| 23 |
+
# Installer logs
|
| 24 |
+
pip-log.txt
|
| 25 |
+
pip-delete-this-directory.txt
|
| 26 |
+
|
| 27 |
+
# Unit test / coverage reports
|
| 28 |
+
.tox/
|
| 29 |
+
.coverage
|
| 30 |
+
.cache
|
| 31 |
+
nosetests.xml
|
| 32 |
+
coverage.xml
|
| 33 |
+
|
| 34 |
+
# Translations
|
| 35 |
+
*.mo
|
| 36 |
+
|
| 37 |
+
# Mr Developer
|
| 38 |
+
.mr.developer.cfg
|
| 39 |
+
.project
|
| 40 |
+
.pydevproject
|
| 41 |
+
|
| 42 |
+
# Rope
|
| 43 |
+
.ropeproject
|
| 44 |
+
|
| 45 |
+
# Django stuff:
|
| 46 |
+
*.log
|
| 47 |
+
*.pot
|
| 48 |
+
|
| 49 |
+
# Sphinx documentation
|
| 50 |
+
docs/_build/
|
| 51 |
+
Share
|
| 52 |
+
|
| 53 |
+
# mac
|
| 54 |
+
.DS_Store
|
Backend/BrandRecognition/Dynamic/Brand_Count_Vid.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
from collections import deque, defaultdict
|
| 4 |
+
from ultralytics import YOLO
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def iou(box1, box2):
|
| 9 |
+
x1 = max(box1[0], box2[0])
|
| 10 |
+
y1 = max(box1[1], box2[1])
|
| 11 |
+
x2 = min(box1[2], box2[2])
|
| 12 |
+
y2 = min(box1[3], box2[3])
|
| 13 |
+
|
| 14 |
+
intersection = max(0, x2 - x1) * max(0, y2 - y1)
|
| 15 |
+
area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
|
| 16 |
+
area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
|
| 17 |
+
|
| 18 |
+
iou = intersection / float(area1 + area2 - intersection)
|
| 19 |
+
return iou
|
| 20 |
+
|
| 21 |
+
def smooth_box(box_history):
|
| 22 |
+
if not box_history:
|
| 23 |
+
return None
|
| 24 |
+
return np.mean(box_history, axis=0)
|
| 25 |
+
|
| 26 |
+
def process_video(input_path, output_path):
|
| 27 |
+
model = YOLO('kitkat_s.pt')
|
| 28 |
+
cap = cv2.VideoCapture(input_path)
|
| 29 |
+
|
| 30 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 31 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 32 |
+
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
| 33 |
+
|
| 34 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 35 |
+
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 36 |
+
|
| 37 |
+
detected_items = {}
|
| 38 |
+
frame_count = 0
|
| 39 |
+
|
| 40 |
+
detections_history = defaultdict(lambda: defaultdict(int))
|
| 41 |
+
|
| 42 |
+
while cap.isOpened():
|
| 43 |
+
ret, frame = cap.read()
|
| 44 |
+
if not ret:
|
| 45 |
+
break
|
| 46 |
+
|
| 47 |
+
frame_count += 1
|
| 48 |
+
|
| 49 |
+
if frame_count % 5 == 0:
|
| 50 |
+
results = model(frame)
|
| 51 |
+
|
| 52 |
+
current_frame_detections = []
|
| 53 |
+
|
| 54 |
+
for r in results:
|
| 55 |
+
boxes = r.boxes
|
| 56 |
+
for box in boxes:
|
| 57 |
+
x1, y1, x2, y2 = box.xyxy[0].tolist()
|
| 58 |
+
conf = box.conf.item()
|
| 59 |
+
cls = int(box.cls.item())
|
| 60 |
+
brand = model.names[cls]
|
| 61 |
+
|
| 62 |
+
current_frame_detections.append((brand, [x1, y1, x2, y2], conf))
|
| 63 |
+
|
| 64 |
+
for brand, box, conf in current_frame_detections:
|
| 65 |
+
matched = False
|
| 66 |
+
for item_id, item_info in detected_items.items():
|
| 67 |
+
if iou(box, item_info['smoothed_box']) > 0.5:
|
| 68 |
+
item_info['frames_detected'] += 1
|
| 69 |
+
item_info['total_conf'] += conf
|
| 70 |
+
item_info['box_history'].append(box)
|
| 71 |
+
if len(item_info['box_history']) > 10:
|
| 72 |
+
item_info['box_history'].popleft()
|
| 73 |
+
item_info['smoothed_box'] = smooth_box(item_info['box_history'])
|
| 74 |
+
item_info['last_seen'] = frame_count
|
| 75 |
+
matched = True
|
| 76 |
+
break
|
| 77 |
+
|
| 78 |
+
if not matched:
|
| 79 |
+
item_id = len(detected_items)
|
| 80 |
+
detected_items[item_id] = {
|
| 81 |
+
'brand': brand,
|
| 82 |
+
'box_history': deque([box], maxlen=10),
|
| 83 |
+
'smoothed_box': box,
|
| 84 |
+
'frames_detected': 1,
|
| 85 |
+
'total_conf': conf,
|
| 86 |
+
'last_seen': frame_count
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
detections_history[brand][frame_count] += 1
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
for item_id, item_info in list(detected_items.items()):
|
| 93 |
+
if frame_count - item_info['last_seen'] > fps * 2: # 2 seconds
|
| 94 |
+
del detected_items[item_id]
|
| 95 |
+
continue
|
| 96 |
+
|
| 97 |
+
if item_info['smoothed_box'] is not None:
|
| 98 |
+
alpha = 0.3
|
| 99 |
+
current_box = item_info['smoothed_box']
|
| 100 |
+
target_box = item_info['box_history'][-1] if item_info['box_history'] else current_box
|
| 101 |
+
interpolated_box = [
|
| 102 |
+
current_box[i] * (1 - alpha) + target_box[i] * alpha
|
| 103 |
+
for i in range(4)
|
| 104 |
+
]
|
| 105 |
+
item_info['smoothed_box'] = interpolated_box
|
| 106 |
+
|
| 107 |
+
x1, y1, x2, y2 = map(int, interpolated_box)
|
| 108 |
+
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 109 |
+
cv2.putText(frame, f"{item_info['brand']}",
|
| 110 |
+
(x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
| 111 |
+
|
| 112 |
+
out.write(frame)
|
| 113 |
+
|
| 114 |
+
cap.release()
|
| 115 |
+
out.release()
|
| 116 |
+
|
| 117 |
+
total_frames = frame_count
|
| 118 |
+
confirmed_items = {}
|
| 119 |
+
for brand, frame_counts in detections_history.items():
|
| 120 |
+
detection_frames = len(frame_counts)
|
| 121 |
+
if detection_frames > total_frames * 0.1:
|
| 122 |
+
avg_count = sum(frame_counts.values()) / detection_frames
|
| 123 |
+
confirmed_items[brand] = round(avg_count)
|
| 124 |
+
|
| 125 |
+
return confirmed_items
|
| 126 |
+
|
| 127 |
+
def annotate_video(input_video):
|
| 128 |
+
output_path = 'annotated_output.mp4'
|
| 129 |
+
confirmed_items = process_video(input_video, output_path)
|
| 130 |
+
|
| 131 |
+
item_list = [(brand, quantity) for brand, quantity in confirmed_items.items()]
|
| 132 |
+
|
| 133 |
+
status_message = "Video processed successfully!"
|
| 134 |
+
|
| 135 |
+
return output_path, item_list, status_message
|
Backend/BrandRecognition/Static/Brand_Count_Img.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
from Database.mongodb import DatabaseManager
|
| 5 |
+
|
| 6 |
+
def preprocess_image(image, input_size=(640, 640), augment=False):
|
| 7 |
+
"""
|
| 8 |
+
Advanced image preprocessing for multi-brand object detection.
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
image (numpy.ndarray): Input image in BGR format.
|
| 12 |
+
input_size (tuple): Target image dimensions (width, height).
|
| 13 |
+
augment (bool): Apply data augmentation for training.
|
| 14 |
+
|
| 15 |
+
Returns:
|
| 16 |
+
numpy.ndarray: Preprocessed image in RGB format.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
# Convert image to RGB
|
| 20 |
+
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 21 |
+
|
| 22 |
+
# Resize and enhance
|
| 23 |
+
resized_image = cv2.resize(image_rgb, input_size, interpolation=cv2.INTER_NEAREST)
|
| 24 |
+
enhanced_image = cv2.convertScaleAbs(resized_image, alpha=1.65, beta=1.75)
|
| 25 |
+
|
| 26 |
+
return enhanced_image
|
| 27 |
+
|
| 28 |
+
def detect_grocery_items(image, model_path=None, threshold=0.5):
|
| 29 |
+
|
| 30 |
+
"""
|
| 31 |
+
Detect grocery items in an image.
|
| 32 |
+
|
| 33 |
+
Args:
|
| 34 |
+
image (numpy.ndarray): Input image in BGR format.
|
| 35 |
+
model_path (str, optional): Path to YOLO model weights.
|
| 36 |
+
threshold (float, optional): Confidence threshold for detection.
|
| 37 |
+
|
| 38 |
+
Returns:
|
| 39 |
+
tuple: Annotated image, summary table, and status message
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
db_manager = DatabaseManager()
|
| 43 |
+
|
| 44 |
+
# Validate image input
|
| 45 |
+
if image is None or image.size == 0:
|
| 46 |
+
return None, [], "Invalid image input"
|
| 47 |
+
|
| 48 |
+
# Use default model path if not provided
|
| 49 |
+
if model_path is None:
|
| 50 |
+
model_path = 'Weights/kitkat_s.pt'
|
| 51 |
+
|
| 52 |
+
# Load YOLO model
|
| 53 |
+
try:
|
| 54 |
+
model = YOLO(model_path)
|
| 55 |
+
except Exception as e:
|
| 56 |
+
return None, [], f"Model loading error: {str(e)}"
|
| 57 |
+
|
| 58 |
+
# Preprocess image
|
| 59 |
+
processed_image = preprocess_image(image)
|
| 60 |
+
|
| 61 |
+
# Detect objects
|
| 62 |
+
try:
|
| 63 |
+
results = model(processed_image)
|
| 64 |
+
|
| 65 |
+
# If no results, return early
|
| 66 |
+
if len(results[0].boxes) == 0:
|
| 67 |
+
return processed_image, [], "No items detected"
|
| 68 |
+
|
| 69 |
+
# Annotate image
|
| 70 |
+
annotated_image = results[0].plot()
|
| 71 |
+
|
| 72 |
+
# Process detection results
|
| 73 |
+
class_ids = results[0].boxes.cls.cpu().numpy()
|
| 74 |
+
confidences = results[0].boxes.conf.cpu().numpy()
|
| 75 |
+
|
| 76 |
+
# Aggregate results
|
| 77 |
+
class_counts = {}
|
| 78 |
+
class_confidences = {}
|
| 79 |
+
|
| 80 |
+
# Iterate over detected objects
|
| 81 |
+
for i, class_id in enumerate(class_ids):
|
| 82 |
+
|
| 83 |
+
# Get class name and confidence
|
| 84 |
+
confidence = confidences[i]
|
| 85 |
+
|
| 86 |
+
# Filter by confidence threshold
|
| 87 |
+
if confidence >= threshold:
|
| 88 |
+
|
| 89 |
+
# Get class name
|
| 90 |
+
class_name = model.names[int(class_id)]
|
| 91 |
+
class_counts[class_name] = class_counts.get(class_name, 0) + 1
|
| 92 |
+
|
| 93 |
+
# Store confidence values
|
| 94 |
+
if class_name not in class_confidences:
|
| 95 |
+
class_confidences[class_name] = []
|
| 96 |
+
|
| 97 |
+
# Add confidence value
|
| 98 |
+
class_confidences[class_name].append(confidence)
|
| 99 |
+
|
| 100 |
+
# Create summary table
|
| 101 |
+
summary_table = [
|
| 102 |
+
[class_name, count, f"{np.mean(class_confidences[class_name]):.2f}"]
|
| 103 |
+
for class_name, count in class_counts.items()
|
| 104 |
+
]
|
| 105 |
+
|
| 106 |
+
# Add brand records to the database
|
| 107 |
+
for brand, count in class_counts.items():
|
| 108 |
+
db_manager.add_brand_record(brand, count)
|
| 109 |
+
|
| 110 |
+
# Convert back to RGB for display
|
| 111 |
+
annotated_image_rgb = annotated_image[:, :, ::-1]
|
| 112 |
+
|
| 113 |
+
return annotated_image_rgb, summary_table, "Objects Recognised Successfully 🥳"
|
| 114 |
+
|
| 115 |
+
except Exception as e:
|
| 116 |
+
return None, [], f"Detection error: {str(e)}"
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
# Optional: Batch processing function
|
| 120 |
+
def batch_detect_grocery_items(images, model_path=None, threshold=0.4):
|
| 121 |
+
"""
|
| 122 |
+
Detect grocery items in multiple images.
|
| 123 |
+
|
| 124 |
+
Args:
|
| 125 |
+
images (list): List of input images in BGR format.
|
| 126 |
+
model_path (str, optional): Path to YOLO model weights.
|
| 127 |
+
threshold (float, optional): Confidence threshold for detection.
|
| 128 |
+
|
| 129 |
+
Returns:
|
| 130 |
+
list: List of detection results for each image
|
| 131 |
+
"""
|
| 132 |
+
return [detect_grocery_items(img, model_path, threshold) for img in images]
|
Backend/Fruit_Freshness/Apples/Photos/Fresh_1.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Fresh_2.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Fresh_3.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Fresh_4.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Fresh_5.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Rotten_1.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Rotten_2.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Rotten_3.png
ADDED
|
Backend/Fruit_Freshness/Apples/Photos/Rotten_4.png
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5ad993b6a4cda53115519046abf74f9b61cca502ce32a795f97c00e00afaaa50
|
| 3 |
+
size 984758
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/README.dataset.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Rotten Apple Labeller > Rotten Apples
|
| 2 |
+
https://universe.roboflow.com/shyam-krishna/rotten-apple-labeller
|
| 3 |
+
|
| 4 |
+
Provided by a Roboflow user
|
| 5 |
+
License: CC BY 4.0
|
| 6 |
+
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/README.roboflow.txt
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Rotten Apple Labeller - v1 Rotten Apples
|
| 3 |
+
==============================
|
| 4 |
+
|
| 5 |
+
This dataset was exported via roboflow.com on March 15, 2023 at 6:50 AM GMT
|
| 6 |
+
|
| 7 |
+
Roboflow is an end-to-end computer vision platform that helps you
|
| 8 |
+
* collaborate with your team on computer vision projects
|
| 9 |
+
* collect & organize images
|
| 10 |
+
* understand and search unstructured image data
|
| 11 |
+
* annotate, and create datasets
|
| 12 |
+
* export, train, and deploy computer vision models
|
| 13 |
+
* use active learning to improve your dataset over time
|
| 14 |
+
|
| 15 |
+
For state of the art Computer Vision training notebooks you can use with this dataset,
|
| 16 |
+
visit https://github.com/roboflow/notebooks
|
| 17 |
+
|
| 18 |
+
To find over 100k other datasets and pre-trained models, visit https://universe.roboflow.com
|
| 19 |
+
|
| 20 |
+
The dataset includes 62 images.
|
| 21 |
+
Rotten-Apples are annotated in YOLOv8 format.
|
| 22 |
+
|
| 23 |
+
The following pre-processing was applied to each image:
|
| 24 |
+
* Auto-orientation of pixel data (with EXIF-orientation stripping)
|
| 25 |
+
* Resize to 416x416 (Stretch)
|
| 26 |
+
|
| 27 |
+
The following augmentation was applied to create 3 versions of each source image:
|
| 28 |
+
* 50% probability of horizontal flip
|
| 29 |
+
* 50% probability of vertical flip
|
| 30 |
+
* Equal probability of one of the following 90-degree rotations: none, clockwise, counter-clockwise, upside-down
|
| 31 |
+
|
| 32 |
+
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/data.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
train: ../train/images
|
| 2 |
+
val: ../valid/images
|
| 3 |
+
test: ../test/images
|
| 4 |
+
|
| 5 |
+
nc: 1
|
| 6 |
+
names: ['Rotten Apple']
|
| 7 |
+
|
| 8 |
+
roboflow:
|
| 9 |
+
workspace: shyam-krishna
|
| 10 |
+
project: rotten-apple-labeller
|
| 11 |
+
version: 1
|
| 12 |
+
license: CC BY 4.0
|
| 13 |
+
url: https://universe.roboflow.com/shyam-krishna/rotten-apple-labeller/dataset/1
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-2-54-49-PM_png.rf.2557a1048acae352cd5420528e467e18.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-2-57-13-PM_png.rf.e9da17a0710d447581911d0a686a64bb.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-3-02-24-PM_png.rf.fce9e910b977026e4356db03caaf7835.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/images/Screen-Shot-2018-06-07-at-3-02-51-PM_png.rf.193331860c01427edcafb663e15d5f8c.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-2-54-49-PM_png.rf.2557a1048acae352cd5420528e467e18.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
0 0.4795673076923077 0.5108173076923077 0.7235576923076923 0.7836538461538461
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-2-57-13-PM_png.rf.e9da17a0710d447581911d0a686a64bb.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
0 0.5853365384615384 0.5180288461538461 0.7175480769230769 0.7043269230769231
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-3-02-24-PM_png.rf.fce9e910b977026e4356db03caaf7835.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
0 0.49759615384615385 0.4723557692307692 0.8028846153846154 0.8509615384615384
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/test/labels/Screen-Shot-2018-06-07-at-3-02-51-PM_png.rf.193331860c01427edcafb663e15d5f8c.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
0 0.49038461538461536 0.4963942307692308 0.7223557692307693 0.7415865384615384
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-20-PM_png.rf.17a1184c9996ed00a4e7f232de6060ea.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-20-PM_png.rf.82f8c8cd7117007c6c219b76568b83a4.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-20-PM_png.rf.e324b699b3d1948c6212a7ec533fe981.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-33-PM_png.rf.163b037e01da46c3ec715755c291aa95.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-33-PM_png.rf.89f62e24f24e80e8031ce669fb74718e.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-53-33-PM_png.rf.bb9cacf69bb23894866f1982caea0ccf.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-08-PM_png.rf.5ed4084cc0d8b7812c8cc819480ba10f.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-08-PM_png.rf.ac4d108659b63c81acf73865dc81ee9c.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-58-PM_png.rf.0bab53e4576f3dcdc3eecbad1f2e2a25.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-58-PM_png.rf.10803b835c52cbd24433f1a0515668e4.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-54-58-PM_png.rf.bd3f4db76c39859bc11bcf30418b654e.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-55-27-PM_png.rf.40e834e8eb8867403264b94970229392.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-55-27-PM_png.rf.449428299a5d3574754e53017cb74a08.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-55-27-PM_png.rf.dcf06ba791b8c9e2ed6a5deaecff39b9.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-56-57-PM_png.rf.227c73b163d364d8da4dc460d373e21a.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-56-57-PM_png.rf.83e9e5ac4fcaee7b11b3a535c0c1d2ef.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-56-57-PM_png.rf.970a7fa1fa583318b57baa9255ef021d.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-05-PM_png.rf.51d0712871be1b778ac39dbe8d10392b.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-05-PM_png.rf.ddd660cf6503243277404540b277a30f.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-05-PM_png.rf.f891d92a399c50347fff17b9721486e1.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-26-PM_png.rf.5ae2dbffe4997cd0502a4604f79b5a4a.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-26-PM_png.rf.8cf78686362e2f91096c65afa93974cf.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-26-PM_png.rf.dbb43335e14c7a61d9719fc63e744a46.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-42-PM_png.rf.7f27375200a5f1f25f11cfc2dadaa1cc.jpg
ADDED
|
Backend/Fruit_Freshness/Apples/Rotten Apple Labeller.v1-rotten-apples.yolov8/train/images/Screen-Shot-2018-06-07-at-2-57-42-PM_png.rf.a4416d86ea25aad74339a40630da321e.jpg
ADDED
|