diff --git a/.gitignore b/.gitignore
index 347f534..bc8a4c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
runs
-venv
\ No newline at end of file
+venv
+.idea
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/cat-detector.iml b/.idea/cat-detector.iml
deleted file mode 100644
index e5d1770..0000000
--- a/.idea/cat-detector.iml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml
deleted file mode 100644
index 7dc1249..0000000
--- a/.idea/git_toolbox_blame.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml
deleted file mode 100644
index 02b915b..0000000
--- a/.idea/git_toolbox_prj.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
deleted file mode 100644
index 105ce2d..0000000
--- a/.idea/inspectionProfiles/profiles_settings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 2124c79..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index f19c4e6..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/main.py b/main.py
index d1de5e7..1f52db6 100644
--- a/main.py
+++ b/main.py
@@ -2,21 +2,94 @@
from cat import Cat
from counter import Counter
from deterrent import Deterrent
+import json
import cv2
from ultralytics import YOLO
min_confidence = 0.2
-counter = Counter("counter.json")
+# counter = Counter("counter.json")
deterrent = Deterrent(5, ["Get off the counter!", "What are you doing! Get off!", "No, no, no!", "Get down!", "Off! Now!"])
-model = YOLO("yolov8x.pt")
+model = YOLO("yolov8n.pt")
-cap = LatestVideoCapture("output_left.mp4")
+cap = LatestVideoCapture("rocky_ginger.mp4")
+#cap = cv2.VideoCapture(4)
+
+
+def set_counters(frame, win_name: str):
+ print("Left click to select n-gon corners")
+ print("Middle click to add current n-gon (needs at least 3 corners) and start a new one")
+ print("Hit 's' when done")
+ counters = {"counters": []}
+
+ current_ngon = []
+
+ def mouse_cb(event, x, y, flags, param):
+ for v in counters["counters"]:
+ coordinates = v["coordinates"]
+ for i, xy in enumerate(coordinates):
+ start = (xy[0], xy[1])
+
+ # Close the ngone
+ if i == len(coordinates) - 1:
+ end_idx = 0
+ else:
+ end_idx = i + 1
+
+ end = (coordinates[end_idx][0], coordinates[end_idx][1])
+
+ cv2.line(frame, start, end, (255, 0, 0))
+
+ for i, xy in enumerate(current_ngon):
+ if i == len(current_ngon) - 1:
+ break
+
+ start = (xy[0], xy[1])
+ end = (current_ngon[i + 1][0], current_ngon[i + 1][1])
+
+ cv2.line(frame, start, end, (255, 0, 0))
+
+ if event == cv2.EVENT_LBUTTONUP:
+ current_ngon.append([x, y])
+
+ if event == cv2.EVENT_MBUTTONUP:
+ if len(current_ngon) < 3:
+ print("Need to have at least 3 corners to save an ngon")
+ return
+
+ ngon = current_ngon.copy()
+ counter_id = len(counters["counters"]) + 1
+ counters["counters"].append({"id": counter_id, "name": f"Counter_{counter_id}", "coordinates": ngon})
+ current_ngon.clear()
+
+ cv2.setMouseCallback(win_name, mouse_cb)
+
+ while True:
+ cv2.imshow(win_name, frame)
+ if cv2.waitKey(1) & 0xFF == ord('s'):
+ break
+
+ cv2.setMouseCallback(win_name, lambda *args: None)
+
+ return counters
+
+
+cv2.namedWindow("Cat Detector", cv2.WINDOW_AUTOSIZE)
+
+if cap.isOpened():
+ s, f = cap.read()
+ if s:
+ counters = set_counters(f, "Cat Detector")
+ with open("set_counters.json", "w") as f:
+ json.dump(counters, f, indent=4)
+
+counter = Counter("set_counters.json")
while cap.isOpened():
success, frame = cap.read()
if success:
+
results = model(frame)
cats = []
for r in results:
diff --git a/rocky_ginger.mp4 b/rocky_ginger.mp4
new file mode 100644
index 0000000..77a04da
Binary files /dev/null and b/rocky_ginger.mp4 differ