Pineapple (CH3)

+ Better µScan
    + BmpV!
This commit is contained in:
rattatwinko
2025-04-18 21:20:30 +02:00
parent c1e5a1498a
commit 3aac454ac6
2 changed files with 54 additions and 50 deletions

View File

@@ -373,7 +373,7 @@ class PfandCalculator:
label = tk.Label( label = tk.Label(
about_window, about_window,
text=( text=(
"PfandApp V.8.05.501 - 'Pineapple'\n" "PfandApp V.8.15.000 - 'Pineapple'\n"
"PaketVersion 1.1 ( PKG1.1 )\n\n" "PaketVersion 1.1 ( PKG1.1 )\n\n"
"Erstellt mit TKinter, CV2, Numpy, PyZbar, TGTG-API, TKCalendar, Datetime\n" "Erstellt mit TKinter, CV2, Numpy, PyZbar, TGTG-API, TKCalendar, Datetime\n"
), ),
@@ -550,7 +550,7 @@ class PfandCalculator:
about_uscan, about_uscan,
text=( text=(
"µScan - Der bessere Barcode Scanner\n" "µScan - Der bessere Barcode Scanner\n"
"Version 1.1.0\n" "Version 2.1.0\n"
"µScan erfordert einen UI Reload (Strg+R) in der Root Anwendung\n" "µScan erfordert einen UI Reload (Strg+R) in der Root Anwendung\n"
"µScan ist für mehrere Barcodes gemacht, die in einer kurzen Zeit gescannt werden sollten\n" "µScan ist für mehrere Barcodes gemacht, die in einer kurzen Zeit gescannt werden sollten\n"
), ),

View File

@@ -1,5 +1,4 @@
# µScan # µScan V2.1.0
import tkinter as tk import tkinter as tk
from tkinter import ttk, simpledialog, messagebox from tkinter import ttk, simpledialog, messagebox
import cv2 import cv2
@@ -126,33 +125,36 @@ class PfandScanner:
return binary return binary
def process_video(self): def process_video(self):
ret, frame = self.cap.read() try:
if ret: ret, frame = self.cap.read()
if not self.autofocus_var.get(): if ret:
self.cap.set(cv2.CAP_PROP_FOCUS, self.focus_slider.get()) if not self.autofocus_var.get():
self.cap.set(cv2.CAP_PROP_FOCUS, self.focus_slider.get())
processed_frame = self.adjust_image(frame) processed_frame = self.adjust_image(frame)
barcodes = decode(processed_frame) or decode(frame) barcodes = decode(processed_frame) or decode(frame)
for barcode in barcodes: for barcode in barcodes:
points = barcode.polygon points = barcode.polygon
if len(points) == 4: if len(points) == 4:
pts = [(p.x, p.y) for p in points] pts = [(p.x, p.y) for p in points]
cv2.polylines(frame, [cv2.convexHull(cv2.UMat(cv2.Mat(pts))).get()], True, (0, 255, 0), 2) cv2.polylines(frame, [cv2.convexHull(cv2.UMat(cv2.Mat(pts))).get()], True, (0, 0, 255), 2)
barcode_data = barcode.data.decode('utf-8') barcode_data = barcode.data.decode('utf-8')
self.queue.put(barcode_data) self.queue.put(barcode_data)
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA) cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image) img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img) imgtk = ImageTk.PhotoImage(image=img)
self.camera_label.imgtk = imgtk self.camera_label.imgtk = imgtk
self.camera_label.configure(image=imgtk) self.camera_label.configure(image=imgtk)
except Exception as e:
print(f"Error in processing video: {e}")
self.window.after(10, self.process_video) self.window.after(100, self.process_video)
def show_product_selection(self, barcode_data): def show_product_selection(self, barcode_data):
if hasattr(self, 'product_win') and self.product_win.winfo_exists(): if hasattr(self, 'product_win') and self.product_win.winfo_exists():
return # prevent multiple dialogs return
self.product_win = tk.Toplevel(self.window) self.product_win = tk.Toplevel(self.window)
self.product_win.title("Produktwahl") self.product_win.title("Produktwahl")
@@ -176,38 +178,40 @@ class PfandScanner:
def process_queue(self): def process_queue(self):
try: try:
while True: barcode_data = self.queue.get(timeout=0.1)
barcode_data = self.queue.get_nowait()
now = datetime.now()
if barcode_data in self.barcode_times: now = datetime.now()
timestamps = self.barcode_times[barcode_data]
timestamps = [t for t in timestamps if now - t <= timedelta(seconds=20)]
if len(timestamps) >= 10:
continue
timestamps.append(now)
self.barcode_times[barcode_data] = timestamps
else:
self.barcode_times[barcode_data] = [now]
current_time = now.strftime("%Y-%m-%d %H:%M:%S") if barcode_data in self.barcode_times:
if len(barcode_data) == 13: timestamps = self.barcode_times[barcode_data]
pfand_type = "EINWEG" timestamps = [t for t in timestamps if now - t <= timedelta(seconds=5)]
elif len(barcode_data) == 8: if len(timestamps) >= 3:
pfand_type = "MEHRWEG" return
else: timestamps.append(now)
pfand_type = "DOSE" self.barcode_times[barcode_data] = timestamps
deposit = self.pfand_values.get(pfand_type, 0.00) else:
self.tree.insert("", 0, values=(current_time, barcode_data, pfand_type, f"{deposit:.2f}")) self.barcode_times[barcode_data] = [now]
if barcode_data not in self.prompted_barcodes: current_time = now.strftime("%Y-%m-%d %H:%M:%S")
self.prompted_barcodes.add(barcode_data) if len(barcode_data) == 13:
self.window.after(0, self.show_product_selection, barcode_data) pfand_type = "EINWEG"
elif len(barcode_data) == 8:
pfand_type = "MEHRWEG"
else:
pfand_type = "DOSE"
deposit = self.pfand_values.get(pfand_type, 0.00)
self.tree.insert("", 0, values=(current_time, barcode_data, pfand_type, f"{deposit:.2f}"))
if barcode_data not in self.prompted_barcodes:
self.prompted_barcodes.add(barcode_data)
self.window.after(0, self.show_product_selection, barcode_data)
except queue.Empty: except queue.Empty:
pass pass
except Exception as e:
print(f"Error in queue processing: {e}")
finally: finally:
self.window.after(100, self.process_queue) self.window.after(100, self.process_queue) # freez delay
def on_closing(self): def on_closing(self):
if self.cap.isOpened(): if self.cap.isOpened():
@@ -217,4 +221,4 @@ class PfandScanner:
if __name__ != "__main__": if __name__ != "__main__":
def launch_pfand_scanner(): def launch_pfand_scanner():
scanner_window = tk.Toplevel() scanner_window = tk.Toplevel()
PfandScanner(scanner_window, "µScan V1.1.0") PfandScanner(scanner_window, "µScan V2.1.0")