MTerryJack commited on
Commit
9d048a4
·
verified ·
1 Parent(s): d5c27f8

Upload 9 files

Browse files
Files changed (9) hide show
  1. class_names.txt +3 -0
  2. element.yaml +8 -0
  3. environment.json +1 -0
  4. example.jpeg +0 -0
  5. main.py +86 -0
  6. model_type.json +4 -0
  7. pyproject.toml +10 -0
  8. uv.lock +0 -0
  9. weights.onnx +3 -0
class_names.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ QR_CODE
2
+ qr_code
3
+ qrcode
element.yaml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ version: 0.1.0
2
+ element_type: Detect
3
+ main: main.py
4
+ source: https://universe.roboflow.com/krkkale-niversitesi-pnmrg/qr-code-ee1km
5
+ objects:
6
+ - QR_CODE
7
+ - qr_code
8
+ - qrcode
environment.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"BATCH_SIZE": -1, "CACHE_PATH": "/tmp/cache", "DATASET_ID": "prsg2ggNaUDK4kKNjZ8y", "DATASET_LINK": "https://app.roboflow.com/ds/9f5oc5pEBM?key=LsBUYgkzRT", "DATASET_OWNER": "2w1FkkGDTNVbv5xYuZ8XbYezIBu1", "DATASET_VERSION_ID": "3", "ENDPOINT": "prsg2ggNaUDK4kKNjZ8y/3", "MODEL_NAME": "yolov8n", "PREPROCESSING": "{\"auto-orient\":{\"enabled\":true},\"resize\":{\"format\":\"Stretch to\",\"width\":640,\"enabled\":true,\"height\":640}}", "PROJECT": "roboflow-platform", "RESOLUTION": 640, "TRAINING_TIME": "2678400", "UID": "2w1FkkGDTNVbv5xYuZ8XbYezIBu1", "COLORS": {"QR_CODE": "#C7FC00", "qr_code": "#8622FF", "qrcode": "#FE0056"}}
example.jpeg ADDED
main.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import json
3
+ import sys
4
+ from io import BytesIO
5
+ from pathlib import Path
6
+ from typing import Any, Dict, List
7
+
8
+ import numpy as np
9
+ from PIL import Image
10
+ from ultralytics import YOLO
11
+
12
+
13
+ def load_image(frame: Any, base_dir: Path) -> Image.Image:
14
+ if isinstance(frame, (bytes, bytearray, memoryview)):
15
+ return Image.open(BytesIO(frame)).convert("RGB")
16
+
17
+ path = Path(str(frame))
18
+ if not path.is_absolute():
19
+ path = (Path.cwd() / path).resolve()
20
+ if not path.exists():
21
+ candidate = (base_dir / str(frame)).resolve()
22
+ if candidate.exists():
23
+ path = candidate
24
+ return Image.open(path).convert("RGB")
25
+
26
+
27
+ def load_model(*_args: Any, **_kwargs: Any):
28
+ base_dir = Path(__file__).resolve().parent
29
+ model_path = base_dir / "weights.onnx"
30
+ if not model_path.exists():
31
+ return None
32
+ return YOLO(str(model_path))
33
+
34
+
35
+ def run_model(model, frame: "np.ndarray") -> List[Dict[str, Any]]:
36
+ image = Image.fromarray(frame)
37
+ results = model(image)
38
+ detections: List[Dict[str, Any]] = []
39
+ result = results[0]
40
+ names = result.names or model.names
41
+
42
+ for det_idx, box in enumerate(result.boxes):
43
+ xyxy = box.xyxy[0].tolist()
44
+ class_id = int(box.cls[0].item())
45
+ detections.append(
46
+ {
47
+ "frame_idx": 0,
48
+ "class": names.get(class_id, str(class_id)),
49
+ "bbox": [float(x) for x in xyxy],
50
+ "score": float(box.conf[0].item()),
51
+ "track_id": f"f0-d{det_idx}",
52
+ }
53
+ )
54
+
55
+ return detections
56
+
57
+
58
+ def build_parser() -> argparse.ArgumentParser:
59
+ parser = argparse.ArgumentParser(description="Run QR code detection (YOLOv8 ONNX).")
60
+ parser.add_argument(
61
+ "--stdin-raw",
62
+ action="store_true",
63
+ default=True,
64
+ help="Read raw image bytes from stdin.",
65
+ )
66
+ return parser
67
+
68
+
69
+ if __name__ == "__main__":
70
+ build_parser().parse_args()
71
+
72
+ base_dir = Path(__file__).resolve().parent
73
+ model = load_model()
74
+ if model is None:
75
+ print("[]")
76
+ sys.exit(0)
77
+
78
+ try:
79
+ image = load_image(sys.stdin.buffer.read(), base_dir)
80
+ except Exception:
81
+ print("[]")
82
+ sys.exit(0)
83
+
84
+ frame = np.array(image)
85
+ output = run_model(model, frame)
86
+ print(json.dumps(output))
model_type.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "project_task_type": "object-detection",
3
+ "model_type": "yolov8n"
4
+ }
pyproject.toml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "qr-code-ee1km-3"
3
+ version = "0.1.0"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "numpy>=1.26",
7
+ "pillow>=10.0",
8
+ "ultralytics>=8.0.0",
9
+ "onnxruntime>=1.17",
10
+ ]
uv.lock ADDED
The diff for this file is too large to render. See raw diff
 
weights.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd54085a60f46d449378f6208e2f12c449e8c642d4eac98ca6626a9cca1e5484
3
+ size 12239568