update: bjoerntest8 inference working
149
CameraStream.py
Normal file
@ -0,0 +1,149 @@
|
||||
import cv2
|
||||
import os
|
||||
from datetime import datetime
|
||||
from ultralytics import YOLO
|
||||
|
||||
class YOLOv8CameraStream:
|
||||
def __init__(self, model_path: str, camera_source=0, confidence_threshold=0.5, save_threshold=0.9,
|
||||
log_file="detections.log", logging_level="high"):
|
||||
self.model = YOLO(model_path)
|
||||
self.camera_source = camera_source
|
||||
self.confidence_threshold = confidence_threshold
|
||||
self.default_confidence_threshold = confidence_threshold
|
||||
self.save_threshold = save_threshold
|
||||
self.default_save_threshold = save_threshold
|
||||
self.log_file = log_file
|
||||
self.logging_level = logging_level
|
||||
self.cap = cv2.VideoCapture(camera_source)
|
||||
|
||||
# Create directories for saved frames and archived logs if they don't exist
|
||||
os.makedirs("saved_frames", exist_ok=True)
|
||||
os.makedirs("archive", exist_ok=True)
|
||||
|
||||
# Initialize display settings
|
||||
self.show_thresholds = True
|
||||
|
||||
def log_detection(self, label, confidence):
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self.check_log_size() # Check log size before logging
|
||||
with open(self.log_file, "a") as log:
|
||||
log.write(f"{timestamp} - Detected: {label} with confidence {confidence:.2f}\n")
|
||||
|
||||
def check_log_size(self):
|
||||
"""Checks the size of the log file and archives it if it exceeds 5 MB."""
|
||||
if os.path.exists(self.log_file) and os.path.getsize(self.log_file) > 5 * 1024 * 1024: # 5 MB
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
archived_log_file = f"archive/{self.log_file}_{timestamp}.log"
|
||||
os.rename(self.log_file, archived_log_file) # Rename the old log file
|
||||
print(f"Archived old log file to {archived_log_file}")
|
||||
# Create a new log file
|
||||
open(self.log_file, 'w').close() # Create an empty log file
|
||||
|
||||
def save_frame(self, frame, label):
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
filename = f"saved_frames/{label}_{timestamp}.jpg"
|
||||
cv2.imwrite(filename, frame)
|
||||
print(f"Frame saved: {filename}")
|
||||
|
||||
def get_color_for_confidence(self, confidence):
|
||||
if confidence > 0.75:
|
||||
return (0, 255, 0)
|
||||
elif confidence > 0.5:
|
||||
return (0, 255, 255)
|
||||
else:
|
||||
return (0, 0, 255)
|
||||
|
||||
def process_frame(self, frame):
|
||||
results = self.model.predict(frame)
|
||||
for result in results:
|
||||
for box in result.boxes:
|
||||
confidence = float(box.conf.item())
|
||||
if self.logging_level == "high" and confidence < self.save_threshold:
|
||||
continue
|
||||
|
||||
if confidence > self.confidence_threshold:
|
||||
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
||||
class_id = int(box.cls.item())
|
||||
label = f"{result.names[class_id]} {confidence:.2f}"
|
||||
color = self.get_color_for_confidence(confidence)
|
||||
cv2.rectangle(frame, (x1, y1), (x2, y2), color, 2)
|
||||
cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
||||
|
||||
self.log_detection(result.names[class_id], confidence)
|
||||
|
||||
if confidence > self.save_threshold:
|
||||
self.save_frame(frame, result.names[class_id])
|
||||
|
||||
if self.show_thresholds:
|
||||
self.display_thresholds(frame)
|
||||
self.display_keyboard_options(frame)
|
||||
|
||||
return frame
|
||||
|
||||
def display_thresholds(self, frame):
|
||||
text = f"Confidence Threshold: {self.confidence_threshold:.2f} | Save Threshold: {self.save_threshold:.2f}"
|
||||
cv2.putText(frame, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
|
||||
|
||||
def display_keyboard_options(self, frame):
|
||||
options = [
|
||||
"Keyboard Controls:",
|
||||
"'c' - Increase Confidence Threshold | 'v' - Decrease Confidence Threshold",
|
||||
"'s' - Increase Save Threshold | 'x' - Decrease Save Threshold",
|
||||
"'t' - Toggle Threshold Display | 'r' - Reset Thresholds to Default",
|
||||
"'q' - Quit"
|
||||
]
|
||||
for i, option in enumerate(options):
|
||||
cv2.putText(frame, option, (10, 50 + i * 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
|
||||
|
||||
def adjust_thresholds(self):
|
||||
print("\nPress 'c' to increase confidence threshold, 'v' to decrease it.")
|
||||
print("Press 's' to increase save threshold, 'x' to decrease it.")
|
||||
print("Press 't' to toggle threshold display, 'r' to reset thresholds to default.")
|
||||
print("Press 'q' to quit the program.\n")
|
||||
|
||||
def start(self):
|
||||
if not self.cap.isOpened():
|
||||
print("Error: Could not open video source.")
|
||||
return
|
||||
|
||||
self.adjust_thresholds()
|
||||
|
||||
while True:
|
||||
ret, frame = self.cap.read()
|
||||
if not ret:
|
||||
print("Error: Failed to capture frame.")
|
||||
break
|
||||
|
||||
processed_frame = self.process_frame(frame)
|
||||
cv2.imshow("YOLOv8 Camera Stream", processed_frame)
|
||||
|
||||
key = cv2.waitKey(1) & 0xFF
|
||||
if key == ord('q'):
|
||||
break
|
||||
elif key == ord('c'):
|
||||
self.confidence_threshold = min(self.confidence_threshold + 0.05, 1.0)
|
||||
print(f"Confidence threshold increased to {self.confidence_threshold:.2f}")
|
||||
elif key == ord('v'):
|
||||
self.confidence_threshold = max(self.confidence_threshold - 0.05, 0.0)
|
||||
print(f"Confidence threshold decreased to {self.confidence_threshold:.2f}")
|
||||
elif key == ord('s'):
|
||||
self.save_threshold = min(self.save_threshold + 0.05, 1.0)
|
||||
print(f"Save threshold increased to {self.save_threshold:.2f}")
|
||||
elif key == ord('x'):
|
||||
self.save_threshold = max(self.save_threshold - 0.05, 0.0)
|
||||
print(f"Save threshold decreased to {self.save_threshold:.2f}")
|
||||
elif key == ord('t'):
|
||||
self.show_thresholds = not self.show_thresholds
|
||||
print(f"Threshold display toggled to {'on' if self.show_thresholds else 'off'}")
|
||||
elif key == ord('r'):
|
||||
self.confidence_threshold = self.default_confidence_threshold
|
||||
self.save_threshold = self.default_save_threshold
|
||||
print("Thresholds reset to default values.")
|
||||
|
||||
self.cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
# Run the object detection stream
|
||||
if __name__ == "__main__":
|
||||
yolo_stream = YOLOv8CameraStream(model_path="models/yolov8m_seg_e300.pt", logging_level="high")
|
||||
yolo_stream.start()
|
BIN
__pycache__/CameraStream.cpython-311.pyc
Normal file
154
bjoerntest4.py
Normal file
@ -0,0 +1,154 @@
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import cv2
|
||||
import sys
|
||||
from CameraStream import YOLOv8CameraStream # Import the YOLOv8CameraStream class
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName("MainWindow")
|
||||
MainWindow.resize(1090, 675)
|
||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
self.btn1 = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.btn1.setGeometry(QtCore.QRect(900, 80, 111, 25))
|
||||
self.btn1.setObjectName("btn1")
|
||||
self.AuftragsdetailsTable = QtWidgets.QTableWidget(self.centralwidget)
|
||||
self.AuftragsdetailsTable.setGeometry(QtCore.QRect(10, 10, 661, 192))
|
||||
self.AuftragsdetailsTable.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
||||
self.AuftragsdetailsTable.setObjectName("AuftragsdetailsTable")
|
||||
self.AuftragsdetailsTable.setColumnCount(5)
|
||||
self.AuftragsdetailsTable.setRowCount(1)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.AuftragsdetailsTable.setVerticalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(1, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(2, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(3, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(4, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.AuftragsdetailsTable.setItem(0, 0, item)
|
||||
self.label = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label.setGeometry(QtCore.QRect(900, 20, 121, 17))
|
||||
self.label.setObjectName("label")
|
||||
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.textEdit.setGeometry(QtCore.QRect(860, 40, 221, 31))
|
||||
self.textEdit.setObjectName("textEdit")
|
||||
self.bauteilTypBtn = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.bauteilTypBtn.setGeometry(QtCore.QRect(60, 340, 161, 25))
|
||||
self.bauteilTypBtn.setObjectName("bauteilTypBtn")
|
||||
self.bauteiltypTextbox = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.bauteiltypTextbox.setGeometry(QtCore.QRect(230, 340, 221, 31))
|
||||
self.bauteiltypTextbox.setObjectName("bauteiltypTextbox")
|
||||
self.label_3 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label_3.setGeometry(QtCore.QRect(250, 320, 181, 20))
|
||||
self.label_3.setObjectName("label_3")
|
||||
self.label_4 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label_4.setGeometry(QtCore.QRect(520, 320, 67, 17))
|
||||
self.label_4.setObjectName("label_4")
|
||||
self.textEdit_3 = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.textEdit_3.setGeometry(QtCore.QRect(460, 340, 191, 31))
|
||||
self.textEdit_3.setObjectName("textEdit_3")
|
||||
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
|
||||
self.checkBox.setGeometry(QtCore.QRect(70, 410, 151, 23))
|
||||
self.checkBox.setChecked(False)
|
||||
self.checkBox.setObjectName("checkBox")
|
||||
self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)
|
||||
self.graphicsView.setGeometry(QtCore.QRect(800, 280, 256, 192))
|
||||
self.graphicsView.setObjectName("graphicsView")
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 1090, 22))
|
||||
self.menubar.setObjectName("menubar")
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QtWidgets.QStatusBar(MainWindow)
|
||||
self.statusbar.setObjectName("statusbar")
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
||||
self.btn1.setText(_translate("MainWindow", "load Auftrag"))
|
||||
self.label.setText(_translate("MainWindow", "Auftragsnummer:"))
|
||||
self.bauteilTypBtn.setText(_translate("MainWindow", "Bauteiltype erkennen"))
|
||||
self.label_3.setText(_translate("MainWindow", "Bezeichnung"))
|
||||
self.label_4.setText(_translate("MainWindow", "Pos.-Nr:"))
|
||||
self.checkBox.setText(_translate("MainWindow", "Bauteiltype locked"))
|
||||
|
||||
class CameraStreamApp(QtWidgets.QMainWindow):
|
||||
def __init__(self, ui):
|
||||
super().__init__()
|
||||
self.ui = ui
|
||||
self.yolo_stream = None # Initialize YOLOv8CameraStream as None
|
||||
self.timer = QtCore.QTimer(self)
|
||||
self.timer.timeout.connect(self.update_frame)
|
||||
self.ui.btn1.clicked.connect(self.start_camera) # start camera if button LoadAuftrag is clicked
|
||||
self.scene = QtWidgets.QGraphicsScene(self)
|
||||
self.ui.graphicsView.setScene(self.scene)
|
||||
|
||||
def start_camera(self):
|
||||
# Start the YOLOv8 camera stream (only if not already started)
|
||||
if self.yolo_stream is None:
|
||||
self.yolo_stream = YOLOv8CameraStream(model_path="models/yolov8m_seg_e300.pt", logging_level="high")
|
||||
# self.yolo_stream.start() # Start the YOLOv8 stream
|
||||
self.timer.start(30) # Start the timer to update the frame every 30ms (about 33 FPS)
|
||||
|
||||
def update_frame(self):
|
||||
# Update the frame from YOLOv8 stream
|
||||
if self.yolo_stream:
|
||||
ret, frame = self.yolo_stream.cap.read() # Capture frame from YOLOv8 stream
|
||||
if ret:
|
||||
# Convert the frame from BGR (OpenCV format) to RGB
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
|
||||
# Convert the frame to QImage
|
||||
h, w, ch = frame.shape
|
||||
bytes_per_line = ch * w
|
||||
qt_image = QtGui.QImage(frame.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888)
|
||||
|
||||
# Add the QImage to a QPixmap
|
||||
pixmap = QtGui.QPixmap.fromImage(qt_image)
|
||||
|
||||
# Get the size of the graphicsView and scale the pixmap to fit
|
||||
view_size = self.ui.graphicsView.size()
|
||||
scaled_pixmap = pixmap.scaled(view_size, QtCore.Qt.KeepAspectRatio)
|
||||
|
||||
# Update the scene with the scaled pixmap
|
||||
self.scene.clear()
|
||||
self.scene.addPixmap(scaled_pixmap)
|
||||
|
||||
def closeEvent(self, event):
|
||||
# Release the camera when the application is closed
|
||||
if self.yolo_stream is not None:
|
||||
self.yolo_stream.cap.release()
|
||||
event.accept()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
MainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
|
||||
# Initialize the CameraStreamApp with the UI
|
||||
camera_app = CameraStreamApp(ui)
|
||||
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
159
bjoerntest5.py
Normal file
@ -0,0 +1,159 @@
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import cv2
|
||||
import sys
|
||||
from CameraStream import YOLOv8CameraStream # Import the YOLOv8CameraStream class
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName("MainWindow")
|
||||
MainWindow.resize(1090, 675)
|
||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
self.btn1 = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.btn1.setGeometry(QtCore.QRect(900, 80, 111, 25))
|
||||
self.btn1.setObjectName("btn1")
|
||||
self.AuftragsdetailsTable = QtWidgets.QTableWidget(self.centralwidget)
|
||||
self.AuftragsdetailsTable.setGeometry(QtCore.QRect(10, 10, 661, 192))
|
||||
self.AuftragsdetailsTable.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
||||
self.AuftragsdetailsTable.setObjectName("AuftragsdetailsTable")
|
||||
self.AuftragsdetailsTable.setColumnCount(5)
|
||||
self.AuftragsdetailsTable.setRowCount(1)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.AuftragsdetailsTable.setVerticalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(1, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(2, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(3, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(4, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.AuftragsdetailsTable.setItem(0, 0, item)
|
||||
self.label = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label.setGeometry(QtCore.QRect(900, 20, 121, 17))
|
||||
self.label.setObjectName("label")
|
||||
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.textEdit.setGeometry(QtCore.QRect(860, 40, 221, 31))
|
||||
self.textEdit.setObjectName("textEdit")
|
||||
self.bauteilTypBtn = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.bauteilTypBtn.setGeometry(QtCore.QRect(60, 340, 161, 25))
|
||||
self.bauteilTypBtn.setObjectName("bauteilTypBtn")
|
||||
self.bauteiltypTextbox = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.bauteiltypTextbox.setGeometry(QtCore.QRect(230, 340, 221, 31))
|
||||
self.bauteiltypTextbox.setObjectName("bauteiltypTextbox")
|
||||
self.label_3 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label_3.setGeometry(QtCore.QRect(250, 320, 181, 20))
|
||||
self.label_3.setObjectName("label_3")
|
||||
self.label_4 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label_4.setGeometry(QtCore.QRect(520, 320, 67, 17))
|
||||
self.label_4.setObjectName("label_4")
|
||||
self.textEdit_3 = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.textEdit_3.setGeometry(QtCore.QRect(460, 340, 191, 31))
|
||||
self.textEdit_3.setObjectName("textEdit_3")
|
||||
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
|
||||
self.checkBox.setGeometry(QtCore.QRect(70, 410, 151, 23))
|
||||
self.checkBox.setChecked(False)
|
||||
self.checkBox.setObjectName("checkBox")
|
||||
self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)
|
||||
self.graphicsView.setGeometry(QtCore.QRect(800, 280, 256, 192))
|
||||
self.graphicsView.setObjectName("graphicsView")
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 1090, 22))
|
||||
self.menubar.setObjectName("menubar")
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QtWidgets.QStatusBar(MainWindow)
|
||||
self.statusbar.setObjectName("statusbar")
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
||||
self.btn1.setText(_translate("MainWindow", "load Auftrag"))
|
||||
self.label.setText(_translate("MainWindow", "Auftragsnummer:"))
|
||||
self.bauteilTypBtn.setText(_translate("MainWindow", "Bauteiltype erkennen"))
|
||||
self.label_3.setText(_translate("MainWindow", "Bezeichnung"))
|
||||
self.label_4.setText(_translate("MainWindow", "Pos.-Nr:"))
|
||||
self.checkBox.setText(_translate("MainWindow", "Bauteiltype locked"))
|
||||
|
||||
class CameraStreamApp(QtWidgets.QMainWindow):
|
||||
def __init__(self, ui):
|
||||
super().__init__()
|
||||
self.ui = ui
|
||||
self.yolo_stream = None # Initialize YOLOv8CameraStream as None
|
||||
self.timer = QtCore.QTimer(self)
|
||||
self.timer.timeout.connect(self.update_frame)
|
||||
self.ui.btn1.clicked.connect(self.start_camera) # start camera if button LoadAuftrag is clicked
|
||||
self.scene = QtWidgets.QGraphicsScene(self)
|
||||
self.ui.graphicsView.setScene(self.scene)
|
||||
|
||||
def start_camera(self):
|
||||
# Start the YOLOv8 camera stream (only if not already started)
|
||||
if self.yolo_stream is None:
|
||||
self.yolo_stream = YOLOv8CameraStream(model_path="models/yolov8m_seg_e300.pt", logging_level="high")
|
||||
# self.yolo_stream.start() # Start the YOLOv8 stream
|
||||
self.timer.start(30) # Start the timer to update the frame every 30ms (about 33 FPS)
|
||||
|
||||
def update_frame(self):
|
||||
# Update the frame from YOLOv8 stream
|
||||
if self.yolo_stream:
|
||||
ret, frame = self.yolo_stream.cap.read() # Capture frame from YOLOv8 stream
|
||||
|
||||
if ret:
|
||||
# new part including processing via yolo model
|
||||
processed_frame = self.yolo_stream.process_frame(frame)
|
||||
|
||||
# Convert the frame from BGR (OpenCV format) to RGB
|
||||
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB) # might change nomenclature later?
|
||||
|
||||
# Convert the frame to QImage
|
||||
h, w, ch = frame.shape
|
||||
bytes_per_line = ch * w
|
||||
qt_image = QtGui.QImage(frame.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888)
|
||||
|
||||
# Add the QImage to a QPixmap
|
||||
pixmap = QtGui.QPixmap.fromImage(qt_image)
|
||||
|
||||
# Get the size of the graphicsView and scale the pixmap to fit
|
||||
view_size = self.ui.graphicsView.size()
|
||||
scaled_pixmap = pixmap.scaled(view_size, QtCore.Qt.KeepAspectRatio)
|
||||
|
||||
# Update the scene with the scaled pixmap
|
||||
self.scene.clear()
|
||||
self.scene.addPixmap(scaled_pixmap)
|
||||
|
||||
def closeEvent(self, event):
|
||||
# Release the camera when the application is closed
|
||||
if self.yolo_stream is not None:
|
||||
self.yolo_stream.cap.release()
|
||||
event.accept()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
MainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
|
||||
# Initialize the CameraStreamApp with the UI
|
||||
camera_app = CameraStreamApp(ui)
|
||||
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
138
bjoerntest6.py
Normal file
@ -0,0 +1,138 @@
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import cv2
|
||||
import sys
|
||||
from CameraStream import YOLOv8CameraStream # Import the YOLOv8CameraStream class
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName("MainWindow")
|
||||
MainWindow.resize(1090, 675)
|
||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
|
||||
# Create a vertical layout
|
||||
self.layout = QtWidgets.QVBoxLayout(self.centralwidget)
|
||||
|
||||
# Add your widgets to the layout
|
||||
self.AuftragsdetailsTable = QtWidgets.QTableWidget(self.centralwidget)
|
||||
self.AuftragsdetailsTable.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
||||
self.AuftragsdetailsTable.setColumnCount(5)
|
||||
self.AuftragsdetailsTable.setRowCount(1)
|
||||
self.layout.addWidget(self.AuftragsdetailsTable)
|
||||
|
||||
self.label = QtWidgets.QLabel(self.centralwidget)
|
||||
self.layout.addWidget(self.label)
|
||||
|
||||
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.layout.addWidget(self.textEdit)
|
||||
|
||||
self.bauteilTypBtn = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.layout.addWidget(self.bauteilTypBtn)
|
||||
|
||||
self.bauteiltypTextbox = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.layout.addWidget(self.bauteiltypTextbox)
|
||||
|
||||
self.label_3 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.layout.addWidget(self.label_3)
|
||||
|
||||
self.label_4 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.layout.addWidget(self.label_4)
|
||||
|
||||
self.textEdit_3 = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.layout.addWidget(self.textEdit_3)
|
||||
|
||||
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
|
||||
self.layout.addWidget(self.checkBox)
|
||||
|
||||
# Create the QGraphicsView
|
||||
self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)
|
||||
self.layout.addWidget(self.graphicsView)
|
||||
|
||||
# Add a button to the layout
|
||||
self.btn1 = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.layout.addWidget(self.btn1)
|
||||
|
||||
# Set the layout for the central widget
|
||||
self.centralwidget.setLayout(self.layout)
|
||||
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QtWidgets.QStatusBar(MainWindow)
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
||||
self.btn1.setText(_translate("MainWindow", "load Auftrag"))
|
||||
self.label.setText(_translate("MainWindow", "Auftragsnummer:"))
|
||||
self.bauteilTypBtn.setText(_translate("MainWindow", "Bauteiltype erkennen"))
|
||||
self.label_3.setText(_translate("MainWindow", "Bezeichnung"))
|
||||
self.label_4.setText(_translate("MainWindow", "Pos.-Nr:"))
|
||||
self.checkBox.setText(_translate("MainWindow", "Bauteiltype locked"))
|
||||
|
||||
class CameraStreamApp(QtWidgets.QMainWindow):
|
||||
def __init__(self, ui):
|
||||
super().__init__()
|
||||
self.ui = ui
|
||||
self.yolo_stream = None # Initialize YOLOv8CameraStream as None
|
||||
self.timer = QtCore.QTimer(self)
|
||||
self.timer.timeout.connect(self.update_frame)
|
||||
self.ui.btn1.clicked.connect(self.start_camera) # start camera if button LoadAuftrag is clicked
|
||||
self.scene = QtWidgets.QGraphicsScene(self)
|
||||
self.ui.graphicsView.setScene(self.scene)
|
||||
|
||||
def start_camera(self):
|
||||
# Start the YOLOv8 camera stream (only if not already started)
|
||||
if self.yolo_stream is None:
|
||||
self.yolo_stream = YOLOv8CameraStream(model_path="models/yolov8m_seg_e300.pt", logging_level="high")
|
||||
self.timer.start(30) # Start the timer to update the frame every 30ms (about 33 FPS)
|
||||
|
||||
def update_frame(self):
|
||||
# Update the frame from YOLOv8 stream
|
||||
if self.yolo_stream:
|
||||
ret, frame = self.yolo_stream.cap.read() # Capture frame from YOLOv8 stream
|
||||
|
||||
if ret:
|
||||
# Process frame via YOLO model
|
||||
processed_frame = self.yolo_stream.process_frame(frame)
|
||||
|
||||
# Convert the frame from BGR (OpenCV format) to RGB
|
||||
frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)
|
||||
|
||||
# Convert the frame to QImage
|
||||
h, w, ch = frame.shape
|
||||
bytes_per_line = ch * w
|
||||
qt_image = QtGui.QImage(frame.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888)
|
||||
|
||||
# Add the QImage to a QPixmap
|
||||
pixmap = QtGui.QPixmap.fromImage(qt_image)
|
||||
|
||||
# Get the size of the graphicsView and scale the pixmap to fit
|
||||
view_size = self.ui.graphicsView.size()
|
||||
scaled_pixmap = pixmap.scaled(view_size, QtCore.Qt.KeepAspectRatio)
|
||||
|
||||
# Update the scene with the scaled pixmap
|
||||
self.scene.clear()
|
||||
self.scene.addPixmap(scaled_pixmap)
|
||||
|
||||
def closeEvent(self, event):
|
||||
# Release the camera when the application is closed
|
||||
if self.yolo_stream is not None:
|
||||
self.yolo_stream.cap.release()
|
||||
event.accept()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
MainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
|
||||
# Initialize the CameraStreamApp with the UI
|
||||
camera_app = CameraStreamApp(ui)
|
||||
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
142
bjoerntest7.py
Normal file
@ -0,0 +1,142 @@
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import cv2
|
||||
import sys
|
||||
from CameraStream import YOLOv8CameraStream # Import the YOLOv8CameraStream class
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName("MainWindow")
|
||||
MainWindow.resize(1090, 675)
|
||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
|
||||
# Create a horizontal layout for the main window
|
||||
self.layout = QtWidgets.QHBoxLayout(self.centralwidget)
|
||||
|
||||
# Left Column (Can be empty or have some widgets)
|
||||
self.left_column = QtWidgets.QWidget(self.centralwidget)
|
||||
self.left_layout = QtWidgets.QVBoxLayout(self.left_column)
|
||||
|
||||
# You can add more widgets to the left column here if needed
|
||||
self.label = QtWidgets.QLabel("Left Column (Empty)", self.left_column)
|
||||
self.left_layout.addWidget(self.label)
|
||||
|
||||
# Add left column widget to the main layout
|
||||
self.layout.addWidget(self.left_column)
|
||||
|
||||
# Right Column
|
||||
self.right_column = QtWidgets.QWidget(self.centralwidget)
|
||||
self.right_layout = QtWidgets.QVBoxLayout(self.right_column)
|
||||
|
||||
# Add your widgets to the right layout
|
||||
self.AuftragsdetailsTable = QtWidgets.QTableWidget(self.right_column)
|
||||
self.AuftragsdetailsTable.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
||||
self.AuftragsdetailsTable.setColumnCount(5)
|
||||
self.AuftragsdetailsTable.setRowCount(1)
|
||||
self.right_layout.addWidget(self.AuftragsdetailsTable)
|
||||
|
||||
self.textEdit = QtWidgets.QTextEdit(self.right_column)
|
||||
self.right_layout.addWidget(self.textEdit)
|
||||
|
||||
self.bauteilTypBtn = QtWidgets.QPushButton("Bauteiltype erkennen", self.right_column)
|
||||
self.right_layout.addWidget(self.bauteilTypBtn)
|
||||
|
||||
self.bauteiltypTextbox = QtWidgets.QTextEdit(self.right_column)
|
||||
self.right_layout.addWidget(self.bauteiltypTextbox)
|
||||
|
||||
self.label_3 = QtWidgets.QLabel("Bezeichnung", self.right_column)
|
||||
self.right_layout.addWidget(self.label_3)
|
||||
|
||||
self.label_4 = QtWidgets.QLabel("Pos.-Nr:", self.right_column)
|
||||
self.right_layout.addWidget(self.label_4)
|
||||
|
||||
self.textEdit_3 = QtWidgets.QTextEdit(self.right_column)
|
||||
self.right_layout.addWidget(self.textEdit_3)
|
||||
|
||||
self.checkBox = QtWidgets.QCheckBox("Bauteiltype locked", self.right_column)
|
||||
self.right_layout.addWidget(self.checkBox)
|
||||
|
||||
# Create the QGraphicsView
|
||||
self.graphicsView = QtWidgets.QGraphicsView(self.right_column)
|
||||
self.right_layout.addWidget(self.graphicsView)
|
||||
|
||||
# Add right column widget to the main layout
|
||||
self.layout.addWidget(self.right_column)
|
||||
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QtWidgets.QStatusBar(MainWindow)
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
||||
self.bauteilTypBtn.setText(_translate("MainWindow", "Bauteiltype erkennen"))
|
||||
# Add more translations as needed
|
||||
|
||||
class CameraStreamApp(QtWidgets.QMainWindow):
|
||||
def __init__(self, ui):
|
||||
super().__init__()
|
||||
self.ui = ui
|
||||
self.yolo_stream = None # Initialize YOLOv8CameraStream as None
|
||||
self.timer = QtCore.QTimer(self)
|
||||
self.timer.timeout.connect(self.update_frame)
|
||||
self.ui.bauteilTypBtn.clicked.connect(self.start_camera) # Connect the button to start the camera
|
||||
self.scene = QtWidgets.QGraphicsScene(self)
|
||||
self.ui.graphicsView.setScene(self.scene)
|
||||
|
||||
def start_camera(self):
|
||||
# Start the YOLOv8 camera stream (only if not already started)
|
||||
if self.yolo_stream is None:
|
||||
self.yolo_stream = YOLOv8CameraStream(model_path="models/yolov8m_seg_e300.pt", logging_level="high")
|
||||
self.timer.start(30) # Start the timer to update the frame every 30ms (about 33 FPS)
|
||||
|
||||
def update_frame(self):
|
||||
# Update the frame from YOLOv8 stream
|
||||
if self.yolo_stream:
|
||||
ret, frame = self.yolo_stream.cap.read() # Capture frame from YOLOv8 stream
|
||||
|
||||
if ret:
|
||||
# Process frame via YOLO model
|
||||
processed_frame = self.yolo_stream.process_frame(frame)
|
||||
|
||||
# Convert the frame from BGR (OpenCV format) to RGB
|
||||
frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)
|
||||
|
||||
# Convert the frame to QImage
|
||||
h, w, ch = frame.shape
|
||||
bytes_per_line = ch * w
|
||||
qt_image = QtGui.QImage(frame.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888)
|
||||
|
||||
# Add the QImage to a QPixmap
|
||||
pixmap = QtGui.QPixmap.fromImage(qt_image)
|
||||
|
||||
# Get the size of the graphicsView and scale the pixmap to fit
|
||||
view_size = self.ui.graphicsView.size()
|
||||
scaled_pixmap = pixmap.scaled(view_size, QtCore.Qt.KeepAspectRatio)
|
||||
|
||||
# Update the scene with the scaled pixmap
|
||||
self.scene.clear()
|
||||
self.scene.addPixmap(scaled_pixmap)
|
||||
|
||||
def closeEvent(self, event):
|
||||
# Release the camera when the application is closed
|
||||
if self.yolo_stream is not None:
|
||||
self.yolo_stream.cap.release()
|
||||
event.accept()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
MainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
|
||||
# Initialize the CameraStreamApp with the UI
|
||||
camera_app = CameraStreamApp(ui)
|
||||
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
159
bjoerntest8.py
Normal file
@ -0,0 +1,159 @@
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import cv2
|
||||
import sys
|
||||
from CameraStream import YOLOv8CameraStream # Import the YOLOv8CameraStream class
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName("MainWindow")
|
||||
MainWindow.resize(1090, 675)
|
||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
self.btn1 = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.btn1.setGeometry(QtCore.QRect(900, 80, 111, 25))
|
||||
self.btn1.setObjectName("btn1")
|
||||
self.AuftragsdetailsTable = QtWidgets.QTableWidget(self.centralwidget)
|
||||
self.AuftragsdetailsTable.setGeometry(QtCore.QRect(10, 10, 661, 192))
|
||||
self.AuftragsdetailsTable.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
||||
self.AuftragsdetailsTable.setObjectName("AuftragsdetailsTable")
|
||||
self.AuftragsdetailsTable.setColumnCount(5)
|
||||
self.AuftragsdetailsTable.setRowCount(1)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.AuftragsdetailsTable.setVerticalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(1, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(2, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(3, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
font.setPointSize(8)
|
||||
item.setFont(font)
|
||||
self.AuftragsdetailsTable.setHorizontalHeaderItem(4, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.AuftragsdetailsTable.setItem(0, 0, item)
|
||||
self.label = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label.setGeometry(QtCore.QRect(900, 20, 121, 17))
|
||||
self.label.setObjectName("label")
|
||||
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.textEdit.setGeometry(QtCore.QRect(860, 40, 221, 31))
|
||||
self.textEdit.setObjectName("textEdit")
|
||||
self.bauteilTypBtn = QtWidgets.QPushButton(self.centralwidget)
|
||||
self.bauteilTypBtn.setGeometry(QtCore.QRect(60, 340, 161, 25))
|
||||
self.bauteilTypBtn.setObjectName("bauteilTypBtn")
|
||||
self.bauteiltypTextbox = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.bauteiltypTextbox.setGeometry(QtCore.QRect(230, 340, 221, 31))
|
||||
self.bauteiltypTextbox.setObjectName("bauteiltypTextbox")
|
||||
self.label_3 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label_3.setGeometry(QtCore.QRect(250, 320, 181, 20))
|
||||
self.label_3.setObjectName("label_3")
|
||||
self.label_4 = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label_4.setGeometry(QtCore.QRect(520, 320, 67, 17))
|
||||
self.label_4.setObjectName("label_4")
|
||||
self.textEdit_3 = QtWidgets.QTextEdit(self.centralwidget)
|
||||
self.textEdit_3.setGeometry(QtCore.QRect(460, 340, 191, 31))
|
||||
self.textEdit_3.setObjectName("textEdit_3")
|
||||
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
|
||||
self.checkBox.setGeometry(QtCore.QRect(70, 410, 151, 23))
|
||||
self.checkBox.setChecked(False)
|
||||
self.checkBox.setObjectName("checkBox")
|
||||
self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)
|
||||
self.graphicsView.setGeometry(QtCore.QRect(1100, 20, int(640*1.2), int(480*1.2))) # position and size of camera frame
|
||||
self.graphicsView.setObjectName("graphicsView")
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 1090, 22))
|
||||
self.menubar.setObjectName("menubar")
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QtWidgets.QStatusBar(MainWindow)
|
||||
self.statusbar.setObjectName("statusbar")
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
||||
self.btn1.setText(_translate("MainWindow", "load Auftrag"))
|
||||
self.label.setText(_translate("MainWindow", "Auftragsnummer:"))
|
||||
self.bauteilTypBtn.setText(_translate("MainWindow", "Bauteiltype erkennen"))
|
||||
self.label_3.setText(_translate("MainWindow", "Bezeichnung"))
|
||||
self.label_4.setText(_translate("MainWindow", "Pos.-Nr:"))
|
||||
self.checkBox.setText(_translate("MainWindow", "Bauteiltype locked"))
|
||||
|
||||
class CameraStreamApp(QtWidgets.QMainWindow):
|
||||
def __init__(self, ui):
|
||||
super().__init__()
|
||||
self.ui = ui
|
||||
self.yolo_stream = None # Initialize YOLOv8CameraStream as None
|
||||
self.timer = QtCore.QTimer(self)
|
||||
self.timer.timeout.connect(self.update_frame)
|
||||
self.ui.btn1.clicked.connect(self.start_camera) # start camera if button LoadAuftrag is clicked
|
||||
self.scene = QtWidgets.QGraphicsScene(self)
|
||||
self.ui.graphicsView.setScene(self.scene)
|
||||
|
||||
def start_camera(self):
|
||||
# Start the YOLOv8 camera stream (only if not already started)
|
||||
if self.yolo_stream is None:
|
||||
self.yolo_stream = YOLOv8CameraStream(model_path="models/yolov8m_seg_e300.pt", logging_level="high")
|
||||
# self.yolo_stream.start() # Start the YOLOv8 stream
|
||||
self.timer.start(30) # Start the timer to update the frame every 30ms (about 33 FPS)
|
||||
|
||||
def update_frame(self):
|
||||
# Update the frame from YOLOv8 stream
|
||||
if self.yolo_stream:
|
||||
ret, frame = self.yolo_stream.cap.read() # Capture frame from YOLOv8 stream
|
||||
|
||||
if ret:
|
||||
# new part including processing via yolo model
|
||||
processed_frame = self.yolo_stream.process_frame(frame)
|
||||
|
||||
# Convert the frame from BGR (OpenCV format) to RGB
|
||||
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB) # might change nomenclature later?
|
||||
|
||||
# Convert the frame to QImage
|
||||
h, w, ch = frame.shape
|
||||
bytes_per_line = ch * w
|
||||
qt_image = QtGui.QImage(frame.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888)
|
||||
|
||||
# Add the QImage to a QPixmap
|
||||
pixmap = QtGui.QPixmap.fromImage(qt_image)
|
||||
|
||||
# Get the size of the graphicsView and scale the pixmap to fit
|
||||
view_size = self.ui.graphicsView.size()
|
||||
scaled_pixmap = pixmap.scaled(view_size, QtCore.Qt.KeepAspectRatio)
|
||||
|
||||
# Update the scene with the scaled pixmap
|
||||
self.scene.clear()
|
||||
self.scene.addPixmap(scaled_pixmap)
|
||||
|
||||
def closeEvent(self, event):
|
||||
# Release the camera when the application is closed
|
||||
if self.yolo_stream is not None:
|
||||
self.yolo_stream.cap.release()
|
||||
event.accept()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
MainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
|
||||
# Initialize the CameraStreamApp with the UI
|
||||
camera_app = CameraStreamApp(ui)
|
||||
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
124
detections.log
Normal file
@ -0,0 +1,124 @@
|
||||
2024-10-25 10:50:36 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:16 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:17 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:18 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:19 - Detected: hand with confidence 0.90
|
||||
2024-10-25 10:59:19 - Detected: hand with confidence 0.93
|
||||
2024-10-25 10:59:19 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:19 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:19 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:19 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:19 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:20 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:20 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:20 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:20 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:20 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:20 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:20 - Detected: hand with confidence 0.93
|
||||
2024-10-25 10:59:21 - Detected: hand with confidence 0.91
|
||||
2024-10-25 10:59:21 - Detected: hand with confidence 0.92
|
||||
2024-10-25 10:59:21 - Detected: hand with confidence 0.92
|
||||
2024-10-25 11:00:16 - Detected: hand with confidence 0.92
|
||||
2024-10-25 11:00:16 - Detected: hand with confidence 0.92
|
||||
2024-10-25 11:00:16 - Detected: hand with confidence 0.95
|
||||
2024-10-25 11:00:16 - Detected: hand with confidence 0.95
|
||||
2024-10-25 11:00:16 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:00:16 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:00:16 - Detected: hand with confidence 0.90
|
||||
2024-10-25 11:00:17 - Detected: hand with confidence 0.90
|
||||
2024-10-25 11:00:17 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:00:17 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:00:18 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:00:21 - Detected: hand with confidence 0.90
|
||||
2024-10-25 11:00:21 - Detected: hand with confidence 0.94
|
||||
2024-10-25 11:00:28 - Detected: hand with confidence 0.90
|
||||
2024-10-25 11:00:31 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:00:32 - Detected: hand with confidence 0.93
|
||||
2024-10-25 11:00:32 - Detected: hand with confidence 0.93
|
||||
2024-10-25 11:00:32 - Detected: hand with confidence 0.94
|
||||
2024-10-25 11:00:32 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:03:17 - Detected: schraube_sk_m10x45 with confidence 0.91
|
||||
2024-10-25 11:48:21 - Detected: hand with confidence 0.90
|
||||
2024-10-25 11:48:21 - Detected: hand with confidence 0.92
|
||||
2024-10-25 11:48:21 - Detected: hand with confidence 0.92
|
||||
2024-10-25 11:48:21 - Detected: hand with confidence 0.93
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.93
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.97
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.97
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.97
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.97
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.93
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:22 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.92
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.92
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.93
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.91
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.93
|
||||
2024-10-25 11:48:23 - Detected: ring_58mm with confidence 0.92
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.92
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.93
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.91
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.94
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:24 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:25 - Detected: ring_58mm with confidence 0.95
|
||||
2024-10-25 11:48:25 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:25 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:25 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:25 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:25 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:25 - Detected: ring_58mm with confidence 0.96
|
||||
2024-10-25 11:48:26 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:48:27 - Detected: hand with confidence 0.90
|
||||
2024-10-25 11:48:27 - Detected: hand with confidence 0.91
|
||||
2024-10-25 11:48:27 - Detected: hand with confidence 0.93
|
||||
2024-10-25 12:08:10 - Detected: hand with confidence 0.90
|
||||
2024-10-25 12:08:11 - Detected: hand with confidence 0.90
|
||||
2024-10-25 12:08:11 - Detected: hand with confidence 0.91
|
||||
2024-10-25 12:08:11 - Detected: hand with confidence 0.90
|
||||
2024-10-25 12:08:13 - Detected: hand with confidence 0.91
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.91
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.90
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.92
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.92
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.91
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.92
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.90
|
||||
2024-10-25 12:10:52 - Detected: hand with confidence 0.91
|
BIN
models/yolov8m_seg_e300.pt
Normal file
BIN
saved_frames/hand_20241025_105036.jpg
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
saved_frames/hand_20241025_105916.jpg
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
saved_frames/hand_20241025_105917.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_105918.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_105919.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_105920.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_105921.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_110016.jpg
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
saved_frames/hand_20241025_110017.jpg
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
saved_frames/hand_20241025_110018.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_110021.jpg
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
saved_frames/hand_20241025_110028.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_110031.jpg
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
saved_frames/hand_20241025_110032.jpg
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
saved_frames/hand_20241025_114821.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_114826.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_114827.jpg
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
saved_frames/hand_20241025_120810.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_120811.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_120813.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/hand_20241025_121052.jpg
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
saved_frames/ring_58mm_20241025_114822.jpg
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
saved_frames/ring_58mm_20241025_114823.jpg
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
saved_frames/ring_58mm_20241025_114824.jpg
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
saved_frames/ring_58mm_20241025_114825.jpg
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
saved_frames/schraube_sk_m10x45_20241025_110317.jpg
Normal file
After Width: | Height: | Size: 80 KiB |