Skip to content

Commit

Permalink
V1.8
Browse files Browse the repository at this point in the history
- BugFixes in the Operator UI
  • Loading branch information
8JP8 committed Jan 12, 2024
1 parent b999117 commit 7a6446e
Show file tree
Hide file tree
Showing 11 changed files with 1,220 additions and 42 deletions.
653 changes: 653 additions & 0 deletions apple_log.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ inputfilters_post-apply_dilate_and_erode = True

[DETECTION_CONFIG]
threshold1_value = 0
threshold2_value = 32
threshold2_value = 24
mode_value = 0
detectionmode_value = 2
categorizationmode_value = 0
Expand Down Expand Up @@ -104,5 +104,5 @@ high_apple_golden = (100, 100.0, 100.0)
low_apple_green = (100, 50.0, 50.0)
high_apple_green = (150, 100.0, 100.0)
threshold1_value = 0
threshold2_value = 40
threshold2_value = 1

72 changes: 32 additions & 40 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox, QFileDialog, QApplication, QPushButton, QVBoxLayout, QLabel, QDialog, QWidget, QTabWidget, QVBoxLayout, QGraphicsDropShadowEffect, QSizePolicy, QLCDNumber
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox, QFileDialog, QApplication, QPushButton, QVBoxLayout, QLabel, QDialog, QWidget, QVBoxLayout, QGraphicsDropShadowEffect, QSizePolicy
from PyQt6.uic import loadUi
from PyQt6.QtCore import pyqtSignal, Qt, QPropertyAnimation, QSize, QTimer, QThread, QMetaObject, Q_ARG
from PyQt6.QtCore import pyqtSignal, Qt, QPropertyAnimation, QSize, QTimer, QThread, QMetaObject, Q_ARG, Qt, QObject, pyqtSignal, QFile, QIODevice
from PyQt6.QtGui import QImage, QPixmap, QIcon, QCloseEvent, QAction, QKeySequence, QShortcut, QPalette, QColor, QMovie, QGuiApplication
import numpy as np
import threading
Expand Down Expand Up @@ -130,6 +130,18 @@ def __init__(self): # CONSTRUCTOR
self.video_writer2 = None
# ============ \\-// ============

self.logFileReader = LogFileReader()
self.logFileReader.logUpdated.connect(self.updateLogText)
self.readLogFile()

def readLogFile(self):
self.logFileReader.readLogFile()

def updateLogText(self, content):
current_content = self.Log_textBrowser.toPlainText()
if content != current_content:
self.Log_textBrowser.setPlainText(content)

def createShortcut(self, key_sequence, slot_function):
shortcut = key_sequence
action = QAction(self)
Expand Down Expand Up @@ -275,6 +287,7 @@ def cameracapture_to_gui_thread(self):
self.cameracapture_to_gui()
def recording_thread(self):
self.frame_record()

# ========================== \\--// ==========================

def set_video(self, video):
Expand Down Expand Up @@ -417,30 +430,16 @@ def update_operatordisplay(self):
self.BadApples_LCD.display(bad_apple_count)
total_apple_count = big_apple_count + small_apple_count + bad_apple_count
self.DetectedApples_LCD.display(big_apple_count+small_apple_count+bad_apple_count)
WorkerThread.set_initial_values(self, false_positives, diameter_sum / total_apple_count if total_apple_count != 0 else 0.0)

def start_operator_ui_thread(self):
self.worker_thread = WorkerThread()
self.worker_thread.update_signal.connect(self.update_operator_ui)
self.worker_thread.start()

def update_operator_ui(self, false_positives, average_diameter):
self.FalsePositives_TextEdit.setHtml(f"<div align='center'>{false_positives}</div>")
self.AverageDiameter_TextEdit.setHtml(f"<div align='center'>{average_diameter}</div>")

#print("updated")
QMetaObject.invokeMethod(self.FalsePositives_TextEdit, "setHtml",
Qt.ConnectionType.QueuedConnection,
Q_ARG(str, "<div align='center'>{}</div>".format(false_positives)))
QMetaObject.invokeMethod(self.AverageDiameter_TextEdit, "setHtml",
Qt.ConnectionType.QueuedConnection,
Q_ARG(str, "<div align='center'>{}</div>".format(diameter_sum / total_apple_count if total_apple_count != 0 else 0.0)))
#Updates with LogFile
try:
with open(LOG_FILE_PATH, 'r') as file:
content = file.read()
if content != log_file_content:
self.Log_textBrowser.setPlainText(str(content))
except Exception as e:
self.Log_textBrowser.setPlainText(f"Erro de Leitura do Ficheiro de Log: {str(e)}")
print(f"Erro de Leitura do Ficheiro de Log: {str(e)}")
self.logFileReader.readLogFile()

def start_cameracapture(self):
self.start_operator_ui_thread()
import modules.LEDControl as LEDControl

self.nextframe_BT.setText("CONGELAR (C)")
Expand Down Expand Up @@ -1079,24 +1078,17 @@ def update_config_value(tab, var, val):
with open('config.ini', 'w') as config_file:
config.write(config_file)

class WorkerThread(QThread):
update_signal = pyqtSignal(int, float)

def __init__(self):
super().__init__()
self.false_positives = 0
self.average_diameter = 0.0

def set_initial_values(self, false_positives, average_diameter):
self.false_positives = false_positives
self.average_diameter = average_diameter
class LogFileReader(QObject):
logUpdated = pyqtSignal(str)

def run(self):
# Simulate some work in the background
while True:
# Update UI with the current values
self.update_signal.emit(self.false_positives, self.average_diameter)
self.sleep(100) # Simulate some processing time
def readLogFile(self):
try:
with open(LOG_FILE_PATH, 'r') as file:
content = file.read()
self.logUpdated.emit(content)
except Exception as e:
self.logUpdated.emit(f"Erro de Leitura do Ficheiro de Log: {str(e)}")
print(f"Erro de Leitura do Ficheiro de Log: {str(e)}")

# =========================== \\---// ===========================
class Filter:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added modules/__pycache__/LEDControl.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file added modules/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added modules/__pycache__/code_v1.cpython-310.pyc
Binary file not shown.
Loading

0 comments on commit 7a6446e

Please sign in to comment.