feat: add public interface
This commit is contained in:
parent
1a92a0b769
commit
3c09734f6a
@ -17,7 +17,13 @@ cd yiking
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
# Affiche l'interface pour le public
|
||||
python3 public.py
|
||||
|
||||
# Affiche l'interface opérateur
|
||||
python3 main.py
|
||||
|
||||
```
|
||||
|
||||
... devrait afficher une interface utilisateur.
|
||||
|
@ -151,12 +151,16 @@ def process_frame(params, cam_id):
|
||||
|
||||
# 7. Sortie des 6 couleurs en --- ou - -
|
||||
return_text = ""
|
||||
img_public = raw_image.copy()
|
||||
img_final = raw_image.copy()
|
||||
for i in boules_proches:
|
||||
boule = boules[i]
|
||||
return_text += f"{boules_couleurs[i]}\n"
|
||||
cv2.circle(img_final, (boule.x, boule.y), boule.rayon, (0, 255, 0), 2)
|
||||
cv2.circle(img_public, (boule.x, boule.y), boule.rayon, (0, 255, 0), 2)
|
||||
cv2.putText(img_final, boules_bgr[i], (boule.x, boule.y), cv2.FONT_HERSHEY_SIMPLEX,
|
||||
fontScale=0.75, color=(255, 255, 255), thickness=1, lineType=cv2.LINE_AA)
|
||||
|
||||
cv2.imwrite('/tmp/yiking.png', img_public)
|
||||
|
||||
return img_final, return_text
|
||||
|
52
public.py
Normal file
52
public.py
Normal file
@ -0,0 +1,52 @@
|
||||
import tkinter as tk
|
||||
from PIL import Image, ImageTk
|
||||
import os
|
||||
import time
|
||||
from threading import Thread
|
||||
import inotify.adapters
|
||||
|
||||
class YikingInterface:
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.root.title("Yiking")
|
||||
self.root.configure(bg="black")
|
||||
|
||||
# Canvas for displaying images
|
||||
self.canvas = tk.Canvas(self.root, bg="black", width=1024, height=768, highlightthickness=0, bd=0)
|
||||
self.canvas.pack(fill="both", expand=True)
|
||||
|
||||
self.image_path = "/tmp/yiking.png"
|
||||
|
||||
# Load initial image if it exists
|
||||
self.load_and_display_image()
|
||||
|
||||
# Start file watcher in a separate thread
|
||||
self.start_file_watcher()
|
||||
|
||||
def load_and_display_image(self):
|
||||
"""Load and display the image on the canvas, rescaling if necessary."""
|
||||
if os.path.exists(self.image_path):
|
||||
img = Image.open(self.image_path)
|
||||
img = img.resize((1024, 768), Image.Resampling.LANCZOS)
|
||||
self.tk_image = ImageTk.PhotoImage(img)
|
||||
self.canvas.create_image(0, 0, anchor="nw", image=self.tk_image)
|
||||
|
||||
def start_file_watcher(self):
|
||||
"""Start a file watcher to monitor changes on the image file."""
|
||||
def watch_file():
|
||||
notifier = inotify.adapters.Inotify()
|
||||
notifier.add_watch("/tmp")
|
||||
|
||||
for event in notifier.event_gen(yield_nones=False):
|
||||
(_, type_names, path, filename) = event
|
||||
if filename == "yiking.png" and "IN_CLOSE_WRITE" in type_names:
|
||||
print(f"File updated: {os.path.join(path, filename)}")
|
||||
self.load_and_display_image()
|
||||
|
||||
watcher_thread = Thread(target=watch_file, daemon=True)
|
||||
watcher_thread.start()
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
app = YikingInterface(root)
|
||||
root.mainloop()
|
@ -1,3 +1,4 @@
|
||||
numpy~=2.1.3
|
||||
opencv-python
|
||||
pillow
|
||||
inotify
|
Loading…
Reference in New Issue
Block a user