Compare commits
5 Commits
ab266c2767
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d616fd15e | |||
| 2187536c7d | |||
| 6133c9fb18 | |||
| e006fea037 | |||
| 6acb690f16 |
97
controllers/camera_controller.py
Normal file
97
controllers/camera_controller.py
Normal file
@@ -0,0 +1,97 @@
|
||||
# import gphoto2 as gp
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
from PySide6.QtCore import QObject, QThread, Signal
|
||||
from PySide6.QtGui import QImage, QPixmap
|
||||
|
||||
# try:
|
||||
# import gphoto2 as gp
|
||||
# except:
|
||||
from . import mock_gphoto as gp
|
||||
|
||||
class CameraWorker(QObject):
|
||||
frameReady = Signal(QPixmap)
|
||||
errorOccurred = Signal(str)
|
||||
|
||||
def __init__(self, fps: int = 15, parent=None):
|
||||
super().__init__(parent)
|
||||
self.fps = fps
|
||||
self.running = False
|
||||
self.camera = None
|
||||
|
||||
def start_camera(self):
|
||||
"""Uruchom kamerę i zacznij pobierać klatki"""
|
||||
try:
|
||||
self.camera = gp.Camera() # type: ignore
|
||||
self.camera.init()
|
||||
self.running = True
|
||||
self._capture_loop()
|
||||
except gp.GPhoto2Error as e:
|
||||
self.errorOccurred.emit(f"Błąd inicjalizacji kamery: {e}")
|
||||
|
||||
def stop_camera(self):
|
||||
"""Zatrzymaj pobieranie"""
|
||||
self.running = False
|
||||
if self.camera:
|
||||
try:
|
||||
self.camera.exit()
|
||||
except gp.GPhoto2Error:
|
||||
pass
|
||||
self.camera = None
|
||||
|
||||
def _capture_loop(self):
|
||||
"""Pętla odczytu klatek w osobnym wątku"""
|
||||
import time
|
||||
delay = 1.0 / self.fps
|
||||
|
||||
while self.running:
|
||||
try:
|
||||
file = self.camera.capture_preview() # type: ignore
|
||||
data = file.get_data_and_size()
|
||||
frame = np.frombuffer(data, dtype=np.uint8)
|
||||
frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
|
||||
|
||||
if frame is not None:
|
||||
rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
h, w, ch = rgb_image.shape
|
||||
qimg = QImage(rgb_image.data, w, h, ch * w, QImage.Format.Format_RGB888)
|
||||
pixmap = QPixmap.fromImage(qimg)
|
||||
self.frameReady.emit(pixmap)
|
||||
|
||||
except gp.GPhoto2Error as e:
|
||||
self.errorOccurred.emit(f"Błąd odczytu LiveView: {e}")
|
||||
break
|
||||
except Exception as e:
|
||||
self.errorOccurred.emit(f"Nieoczekiwany błąd: {e}")
|
||||
break
|
||||
|
||||
time.sleep(delay)
|
||||
|
||||
|
||||
class CameraController(QObject):
|
||||
frameReady = Signal(QPixmap)
|
||||
errorOccurred = Signal(str)
|
||||
|
||||
def __init__(self, fps: int = 15, parent=None):
|
||||
super().__init__(parent)
|
||||
self.camera_thread = QThread()
|
||||
self.worker = CameraWorker(fps)
|
||||
self.worker.moveToThread(self.camera_thread )
|
||||
|
||||
# sygnały z workera
|
||||
self.worker.frameReady.connect(self.frameReady)
|
||||
self.worker.errorOccurred.connect(self.errorOccurred)
|
||||
|
||||
# sygnały start/stop
|
||||
self.camera_thread.started.connect(self.worker.start_camera)
|
||||
|
||||
def start(self):
|
||||
"""Start kamery w osobnym wątku"""
|
||||
self.camera_thread.start()
|
||||
|
||||
def stop(self):
|
||||
"""Stop kamery i zakończenie wątku"""
|
||||
self.worker.stop_camera()
|
||||
self.camera_thread.quit()
|
||||
self.camera_thread.wait()
|
||||
@@ -1,8 +1,11 @@
|
||||
from PySide6.QtWidgets import QPushButton
|
||||
from pathlib import Path
|
||||
from core.database import DatabaseManager
|
||||
from core.media import MediaRepository
|
||||
from ui.widgets.color_list_widget import ColorListWidget
|
||||
from ui.widgets.thumbnail_list_widget import ThumbnailListWidget
|
||||
from ui.widgets.split_view_widget import SplitView
|
||||
from .camera_controller import CameraController
|
||||
|
||||
|
||||
class MainController:
|
||||
@@ -12,15 +15,27 @@ class MainController:
|
||||
self.media_repo = MediaRepository(self.db)
|
||||
self.media_repo.sync_media()
|
||||
|
||||
self.camera_controller = CameraController()
|
||||
|
||||
self.view = view
|
||||
self.color_list: ColorListWidget = view.color_list_widget
|
||||
self.thumbnail_list: ThumbnailListWidget = view.thumbnail_widget
|
||||
self.split_view: SplitView = view.preview_widget
|
||||
|
||||
self.photo_button: QPushButton = view.photo_button
|
||||
self.photo_button.clicked.connect(self.take_photo)
|
||||
|
||||
self.color_list.colorSelected.connect(self.on_color_selected)
|
||||
self.color_list.editColor.connect(self.on_edit_color)
|
||||
self.thumbnail_list.selectedThumbnail.connect(self.on_thumbnail_selected)
|
||||
|
||||
self.camera_controller.errorOccurred.connect(self.split_view.widget_start.set_info_text)
|
||||
self.camera_controller.frameReady.connect(self.split_view.set_live_image)
|
||||
self.split_view.widget_start.camera_start_btn.clicked.connect(self.camera_controller.start)
|
||||
|
||||
def start_camera(self):
|
||||
pass
|
||||
|
||||
def load_colors(self) -> None:
|
||||
colors = self.db.get_all_colors()
|
||||
print("Loaded colors:", colors)
|
||||
@@ -49,5 +64,10 @@ class MainController:
|
||||
media = self.db.get_media(media_id)
|
||||
if media:
|
||||
print(f"Wybrano miniaturę o ID: {media_id}, ścieżka: {media['media_path']}")
|
||||
self.split_view.set_reference_image(media['media_path'])
|
||||
else:
|
||||
print(f"Nie znaleziono mediów o ID: {media_id}")
|
||||
|
||||
def take_photo(self):
|
||||
print("Robienie zdjęcia...")
|
||||
self.split_view.toglle_live_view()
|
||||
|
||||
64
controllers/mock_gphoto.py
Normal file
64
controllers/mock_gphoto.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
class GPhoto2Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class CameraFileMock:
|
||||
"""Mock obiektu zwracanego przez gphoto2.Camera.capture_preview()"""
|
||||
|
||||
def __init__(self, frame: np.ndarray):
|
||||
# Kodowanie do JPEG, żeby symulować prawdziwe dane z kamery
|
||||
success, buf = cv2.imencode(".jpg", frame)
|
||||
if not success:
|
||||
raise GPhoto2Error("Nie udało się zakodować ramki testowej.")
|
||||
self._data = buf.tobytes()
|
||||
|
||||
def get_data_and_size(self):
|
||||
return self._data
|
||||
return self._data, len(self._data)
|
||||
|
||||
|
||||
class Camera:
|
||||
def __init__(self):
|
||||
self._frame_counter = 0
|
||||
self._running = False
|
||||
|
||||
def init(self):
|
||||
self._running = True
|
||||
print("[my_gphoto] Kamera MOCK zainicjalizowana")
|
||||
|
||||
def exit(self):
|
||||
self._running = False
|
||||
print("[my_gphoto] Kamera MOCK wyłączona")
|
||||
|
||||
def capture_preview(self):
|
||||
if not self._running:
|
||||
raise GPhoto2Error("Kamera MOCK nie jest uruchomiona")
|
||||
|
||||
# przykład 1: wczytaj stały obrazek z pliku
|
||||
# frame = cv2.imread("test_frame.jpg")
|
||||
# if frame is None:
|
||||
# raise GPhoto2Error("Nie znaleziono test_frame.jpg")
|
||||
|
||||
# przykład 2: wygeneruj kolorową planszę
|
||||
h, w = 480, 640
|
||||
color = (self._frame_counter % 255, 100, 200)
|
||||
frame = np.full((h, w, 3), color, dtype=np.uint8)
|
||||
|
||||
# dodanie napisu
|
||||
text = "OBRAZ TESTOWY"
|
||||
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||
scale = 1.5
|
||||
thickness = 3
|
||||
color_text = (255, 255, 255)
|
||||
|
||||
(text_w, text_h), _ = cv2.getTextSize(text, font, scale, thickness)
|
||||
x = (w - text_w) // 2
|
||||
y = (h + text_h) // 2
|
||||
cv2.putText(frame, text, (x, y), font, scale, color_text, thickness, cv2.LINE_AA)
|
||||
|
||||
|
||||
self._frame_counter += 1
|
||||
return CameraFileMock(frame)
|
||||
18
core/base.py
Normal file
18
core/base.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from
|
||||
|
||||
|
||||
class BaseImageSource(QObject):
|
||||
frameReady = Signal(QPixmap)
|
||||
errorOccurred = Signal(str)
|
||||
|
||||
def start(self): ...
|
||||
def stop(self): ...
|
||||
|
||||
|
||||
class BaseControlSource(QObject):
|
||||
errorOccurred = Signal(str)
|
||||
parameterChanged = Signal(str, object)
|
||||
|
||||
def set_parameter(self, name: str, value): ...
|
||||
def get_parameter(self, name: str): ...
|
||||
def list_parameters(self) -> dict: ...
|
||||
49
core/camera/base_camera.py
Normal file
49
core/camera/base_camera.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
class BaseCamera(ABC):
|
||||
"""Interfejs wspólny dla wszystkich backendów kamer."""
|
||||
|
||||
@abstractmethod
|
||||
def connect(self) -> bool:
|
||||
"""Nawiązuje połączenie z urządzeniem."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def disconnect(self):
|
||||
"""Zamyka połączenie z urządzeniem."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def start_stream(self):
|
||||
"""Rozpocznij strumień wideo."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def stop_stream(self):
|
||||
"""Zatrzymaj strumień wideo."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def get_frame(self):
|
||||
"""Pobierz jedną klatkę liveview."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def capture_photo(self):
|
||||
"""Zrób zdjęcie."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def record_video(self):
|
||||
"""Nagraj film."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def get_available_settings(self) -> dict:
|
||||
"""Zwraca słownik dostępnych ustawień i ich możliwych wartości."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def set_setting(self, name: str, value) -> bool:
|
||||
"""Ustawia wybraną wartość dla danego ustawienia."""
|
||||
raise NotImplementedError
|
||||
35
core/camera/gphoto_camera.py
Normal file
35
core/camera/gphoto_camera.py
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
from .base_camera import BaseCamera
|
||||
|
||||
class GPhotoBackend(BaseCamera):
|
||||
def __init__(self) -> None:
|
||||
self.camera = None
|
||||
self.context = None
|
||||
self._is_streaming = False
|
||||
|
||||
def connect(self) -> bool:
|
||||
pass
|
||||
|
||||
def disconnect(self):
|
||||
pass
|
||||
|
||||
def start_stream(self):
|
||||
pass
|
||||
|
||||
def stop_stream(self):
|
||||
pass
|
||||
|
||||
def get_frame(self):
|
||||
pass
|
||||
|
||||
def capture_photo(self):
|
||||
pass
|
||||
|
||||
def record_video(self):
|
||||
pass
|
||||
|
||||
def get_available_settings(self) -> dict:
|
||||
pass
|
||||
|
||||
def set_setting(self, name: str, value) -> bool:
|
||||
pass
|
||||
104
core/camera/opencv_camera.py
Normal file
104
core/camera/opencv_camera.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# camera/opencv_camera.py
|
||||
|
||||
import cv2
|
||||
import time
|
||||
from PySide6.QtGui import QImage, QPixmap
|
||||
from .base_camera import BaseCamera
|
||||
|
||||
class OpenCVCamera(BaseCamera):
|
||||
"""Implementacja kamery przy użyciu OpenCV."""
|
||||
|
||||
def __init__(self, camera_index=0):
|
||||
self.camera_index = camera_index
|
||||
self.video_capture = None
|
||||
self._is_streaming = False
|
||||
# self._live_view_thread = None # Wewnętrzny wątek do pętli live view
|
||||
|
||||
def connect(self) -> bool:
|
||||
self.video_capture = cv2.VideoCapture(self.camera_index)
|
||||
if not self.video_capture.isOpened():
|
||||
# self.error_occurred.emit(f"Nie można otworzyć kamery OpenCV o indeksie {self.camera_index}")
|
||||
self.video_capture = None
|
||||
return False
|
||||
# print("Kamera OpenCV połączona.")
|
||||
return True
|
||||
|
||||
def disconnect(self):
|
||||
self.stop_stream()
|
||||
if self.video_capture:
|
||||
self.video_capture.release()
|
||||
self.video_capture = None
|
||||
# print("Kamera OpenCV rozłączona.")
|
||||
# self.camera_disconnected.emit()
|
||||
|
||||
def start_stream(self):
|
||||
if not self.video_capture or not self.video_capture.isOpened():
|
||||
# self.error_occurred.emit("Próba uruchomienia podglądu na niepodłączonej kamerze.")
|
||||
return
|
||||
|
||||
if self._is_streaming:
|
||||
return # Już działa
|
||||
|
||||
self._is_streaming = True
|
||||
# Uruchamiamy pętlę w metodzie, ponieważ cała klasa działa już w dedykowanym wątku
|
||||
# self._live_view_loop()
|
||||
|
||||
def stop_stream(self):
|
||||
self._is_streaming = False
|
||||
|
||||
|
||||
def get_frame(self):
|
||||
if not self.video_capture:
|
||||
return None
|
||||
|
||||
ret, frame = self.video_capture.read()
|
||||
if not ret:
|
||||
self.stop_stream()
|
||||
return None
|
||||
|
||||
rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
h, w, ch = rgb_image.shape
|
||||
bytes_per_line = ch * w
|
||||
qt_image = QImage(rgb_image.data, w, h, bytes_per_line, QImage.Format.Format_RGB888)
|
||||
|
||||
return qt_image
|
||||
|
||||
def capture_photo(self, save_path: str):
|
||||
if not self.video_capture or not self.video_capture.isOpened():
|
||||
# self.error_occurred.emit("Nie można zrobić zdjęcia, kamera nie jest podłączona.")
|
||||
return
|
||||
|
||||
ret, frame = self.video_capture.read()
|
||||
if ret:
|
||||
try:
|
||||
cv2.imwrite(save_path, frame)
|
||||
print(f"Zdjęcie zapisane w: {save_path}")
|
||||
# self.photo_captured.emit(save_path)
|
||||
except Exception as e:
|
||||
# self.error_occurred.emit(f"Błąd zapisu zdjęcia: {e}")
|
||||
else:
|
||||
# self.error_occurred.emit("Nie udało się przechwycić klatki do zdjęcia.")
|
||||
|
||||
def get_available_settings(self) -> dict:
|
||||
# To jest uproszczona implementacja
|
||||
if not self.video_capture:
|
||||
return {}
|
||||
return {
|
||||
"brightness": self.video_capture.get(cv2.CAP_PROP_BRIGHTNESS),
|
||||
"contrast": self.video_capture.get(cv2.CAP_PROP_CONTRAST),
|
||||
"saturation": self.video_capture.get(cv2.CAP_PROP_SATURATION),
|
||||
}
|
||||
|
||||
def set_setting(self, name: str, value) -> bool:
|
||||
if not self.video_capture:
|
||||
return False
|
||||
|
||||
prop_map = {
|
||||
"brightness": cv2.CAP_PROP_BRIGHTNESS,
|
||||
"contrast": cv2.CAP_PROP_CONTRAST,
|
||||
"saturation": cv2.CAP_PROP_SATURATION,
|
||||
}
|
||||
|
||||
if name in prop_map:
|
||||
return self.video_capture.set(prop_map[name], value)
|
||||
return False
|
||||
80
core/gphoto_adapter.py
Normal file
80
core/gphoto_adapter.py
Normal file
@@ -0,0 +1,80 @@
|
||||
from PySide6.QtCore import QObject, QThread, Signal, QTimer
|
||||
from PySide6.QtGui import QImage, QPixmap
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from .base import BaseControlSource, BaseImageSource
|
||||
|
||||
# try:
|
||||
# import gphoto2 as gp
|
||||
# except:
|
||||
from . import mock_gphoto as gp
|
||||
|
||||
class GPhotoImageSource(BaseImageSource):
|
||||
def __init__(self, camera: gp.Camera, fps=10, parent=None):
|
||||
super().__init__(parent)
|
||||
self.camera = camera
|
||||
self.fps = fps
|
||||
self.timer = None
|
||||
|
||||
def start(self):
|
||||
self.timer = QTimer()
|
||||
self.timer.timeout.connect(self._grab_frame)
|
||||
self.timer.start(int(1000 / self.fps))
|
||||
|
||||
def _grab_frame(self):
|
||||
try:
|
||||
file = self.camera.capture_preview()
|
||||
data = file.get_data_and_size()
|
||||
frame = np.frombuffer(data, dtype=np.uint8)
|
||||
frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
|
||||
if frame is None:
|
||||
return
|
||||
|
||||
rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
h, w, ch = rgb_image.shape
|
||||
qimg = QImage(rgb_image.data, w, h, ch * w, QImage.Format.Format_RGB888)
|
||||
pixmap = QPixmap.fromImage(qimg)
|
||||
self.frameReady.emit(pixmap)
|
||||
except gp.GPhoto2Error as e:
|
||||
self.errorOccurred.emit(f"GPhoto2 error: {e}")
|
||||
|
||||
def stop(self):
|
||||
if self.timer:
|
||||
self.timer.stop()
|
||||
|
||||
|
||||
|
||||
class GPhotoControlSource(BaseControlSource):
|
||||
def __init__(self, camera: gp.Camera, parent=None):
|
||||
super().__init__(parent)
|
||||
self.camera = camera
|
||||
|
||||
def set_parameter(self, name, value):
|
||||
try:
|
||||
config = self.camera.get_config()
|
||||
child = config.get_child_by_name(name)
|
||||
child.set_value(value)
|
||||
self.camera.set_config(config)
|
||||
self.parameterChanged.emit(name, value)
|
||||
except gp.GPhoto2Error as e:
|
||||
self.errorOccurred.emit(str(e))
|
||||
|
||||
def get_parameter(self, name):
|
||||
try:
|
||||
config = self.camera.get_config()
|
||||
child = config.get_child_by_name(name)
|
||||
return child.get_value()
|
||||
except gp.GPhoto2Error as e:
|
||||
self.errorOccurred.emit(str(e))
|
||||
return None
|
||||
|
||||
def list_parameters(self):
|
||||
params = {}
|
||||
try:
|
||||
config = self.camera.get_config()
|
||||
for child in config.get_children():
|
||||
params[child.get_name()] = child.get_value()
|
||||
except gp.GPhoto2Error as e:
|
||||
self.errorOccurred.emit(str(e))
|
||||
return params
|
||||
64
core/mock_gphoto.py
Normal file
64
core/mock_gphoto.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
class GPhoto2Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class CameraFileMock:
|
||||
"""Mock obiektu zwracanego przez gphoto2.Camera.capture_preview()"""
|
||||
|
||||
def __init__(self, frame: np.ndarray):
|
||||
# Kodowanie do JPEG, żeby symulować prawdziwe dane z kamery
|
||||
success, buf = cv2.imencode(".jpg", frame)
|
||||
if not success:
|
||||
raise GPhoto2Error("Nie udało się zakodować ramki testowej.")
|
||||
self._data = buf.tobytes()
|
||||
|
||||
def get_data_and_size(self):
|
||||
return self._data
|
||||
return self._data, len(self._data)
|
||||
|
||||
|
||||
class Camera:
|
||||
def __init__(self):
|
||||
self._frame_counter = 0
|
||||
self._running = False
|
||||
|
||||
def init(self):
|
||||
self._running = True
|
||||
print("[my_gphoto] Kamera MOCK zainicjalizowana")
|
||||
|
||||
def exit(self):
|
||||
self._running = False
|
||||
print("[my_gphoto] Kamera MOCK wyłączona")
|
||||
|
||||
def capture_preview(self):
|
||||
if not self._running:
|
||||
raise GPhoto2Error("Kamera MOCK nie jest uruchomiona")
|
||||
|
||||
# przykład 1: wczytaj stały obrazek z pliku
|
||||
# frame = cv2.imread("test_frame.jpg")
|
||||
# if frame is None:
|
||||
# raise GPhoto2Error("Nie znaleziono test_frame.jpg")
|
||||
|
||||
# przykład 2: wygeneruj kolorową planszę
|
||||
h, w = 480, 640
|
||||
color = (self._frame_counter % 255, 100, 200)
|
||||
frame = np.full((h, w, 3), color, dtype=np.uint8)
|
||||
|
||||
# dodanie napisu
|
||||
text = "OBRAZ TESTOWY"
|
||||
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||
scale = 1.5
|
||||
thickness = 3
|
||||
color_text = (255, 255, 255)
|
||||
|
||||
(text_w, text_h), _ = cv2.getTextSize(text, font, scale, thickness)
|
||||
x = (w - text_w) // 2
|
||||
y = (h + text_h) // 2
|
||||
cv2.putText(frame, text, (x, y), font, scale, color_text, thickness, cv2.LINE_AA)
|
||||
|
||||
|
||||
self._frame_counter += 1
|
||||
return CameraFileMock(frame)
|
||||
34
core/opencv_adapter.py
Normal file
34
core/opencv_adapter.py
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class OpenCVControlSource(BaseControlSource):
|
||||
def __init__(self, cap: cv2.VideoCapture, parent=None):
|
||||
super().__init__(parent)
|
||||
self.cap = cap
|
||||
|
||||
def set_parameter(self, name, value):
|
||||
prop_id = getattr(cv2, name, None)
|
||||
if prop_id is None:
|
||||
self.errorOccurred.emit(f"Nieznany parametr {name}")
|
||||
return
|
||||
self.cap.set(prop_id, value)
|
||||
self.parameterChanged.emit(name, value)
|
||||
|
||||
def get_parameter(self, name):
|
||||
prop_id = getattr(cv2, name, None)
|
||||
if prop_id is None:
|
||||
self.errorOccurred.emit(f"Nieznany parametr {name}")
|
||||
return None
|
||||
return self.cap.get(prop_id)
|
||||
|
||||
def list_parameters(self):
|
||||
return {
|
||||
"CAP_PROP_BRIGHTNESS": self.cap.get(cv2.CAP_PROP_BRIGHTNESS),
|
||||
"CAP_PROP_CONTRAST": self.cap.get(cv2.CAP_PROP_CONTRAST),
|
||||
"CAP_PROP_SATURATION": self.cap.get(cv2.CAP_PROP_SATURATION),
|
||||
"CAP_PROP_GAIN": self.cap.get(cv2.CAP_PROP_GAIN),
|
||||
"CAP_PROP_EXPOSURE": self.cap.get(cv2.CAP_PROP_EXPOSURE),
|
||||
}
|
||||
1
main.py
1
main.py
@@ -8,6 +8,7 @@ from controllers.main_controller import MainController
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
app.setStyle("Fusion")
|
||||
window = MainWindow()
|
||||
controller = MainController(window)
|
||||
controller.load_colors()
|
||||
|
||||
6
requirements.txt
Normal file
6
requirements.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
numpy==2.2.6
|
||||
opencv-python==4.12.0.88
|
||||
PySide6==6.9.2
|
||||
PySide6_Addons==6.9.2
|
||||
PySide6_Essentials==6.9.2
|
||||
shiboken6==6.9.2
|
||||
@@ -9,6 +9,7 @@ from PySide6.QtGui import QPalette, QColor
|
||||
from ui.widgets.placeholder_widget import PlaceholderWidget
|
||||
from ui.widgets.color_list_widget import ColorListWidget
|
||||
from ui.widgets.thumbnail_list_widget import ThumbnailListWidget
|
||||
from ui.widgets.split_view_widget import SplitView
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
@@ -23,9 +24,7 @@ class MainWindow(QMainWindow):
|
||||
main_layout = QHBoxLayout(central_widget)
|
||||
self.setCentralWidget(central_widget)
|
||||
|
||||
self.preview_widget = QSplitter(Qt.Orientation.Vertical)
|
||||
self.preview_widget.addWidget(PlaceholderWidget("Camera View", "#750466"))
|
||||
self.preview_widget.addWidget(PlaceholderWidget("Image View", "#007981"))
|
||||
self.preview_widget = SplitView()
|
||||
|
||||
self.thumbnail_widget = ThumbnailListWidget()
|
||||
self.thumbnail_widget.setFixedWidth(200)
|
||||
@@ -39,23 +38,24 @@ class MainWindow(QMainWindow):
|
||||
|
||||
control_layout = QVBoxLayout(self.control_widget)
|
||||
control_layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
histogram_view = PlaceholderWidget("Histogram View", "#FF5733")
|
||||
histogram_view.setFixedHeight(200)
|
||||
control_layout.addWidget(histogram_view)
|
||||
|
||||
self.color_list_widget = ColorListWidget(self.control_widget)
|
||||
|
||||
self.record_button = QPushButton("Nagraj Wideo")
|
||||
self.record_button.setMinimumHeight(40)
|
||||
self.record_button.setStyleSheet("font-size: 12pt;")
|
||||
|
||||
self.photo_button = QPushButton("Zrób zdjęcie")
|
||||
self.photo_button.setMinimumHeight(40)
|
||||
self.photo_button.setStyleSheet("font-size: 12pt;")
|
||||
|
||||
control_layout.addWidget(histogram_view)
|
||||
control_layout.addWidget(self.color_list_widget)
|
||||
|
||||
record_button = QPushButton("Nagraj Wideo")
|
||||
record_button.setMinimumHeight(40)
|
||||
record_button.setStyleSheet("font-size: 12pt;")
|
||||
control_layout.addWidget(record_button)
|
||||
|
||||
photo_button = QPushButton("Zrób zdjęcie")
|
||||
photo_button.setMinimumHeight(40)
|
||||
photo_button.setStyleSheet("font-size: 12pt;")
|
||||
control_layout.addWidget(photo_button)
|
||||
|
||||
control_layout.addWidget(self.record_button)
|
||||
control_layout.addWidget(self.photo_button)
|
||||
|
||||
|
||||
|
||||
|
||||
164
ui/widgets/split_view_widget.py
Normal file
164
ui/widgets/split_view_widget.py
Normal file
@@ -0,0 +1,164 @@
|
||||
from PySide6.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsPixmapItem, QApplication, QMainWindow, QWidget, QVBoxLayout, QSplitter, QStackedWidget, QPushButton, QLabel
|
||||
from PySide6.QtGui import QPixmap, QWheelEvent, QPainter, QBrush, QColor
|
||||
from PySide6.QtCore import Qt
|
||||
import sys
|
||||
from ui.widgets.placeholder_widget import PlaceholderWidget
|
||||
|
||||
class ZoomableImageView(QGraphicsView):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
# Scena i element obrazu
|
||||
self._scene = QGraphicsScene(self)
|
||||
self.setScene(self._scene)
|
||||
self._scene.setBackgroundBrush(QBrush(QColor(20, 20, 20))) # ciemne tło
|
||||
|
||||
self._pixmap_item = QGraphicsPixmapItem()
|
||||
self._scene.addItem(self._pixmap_item)
|
||||
|
||||
# Ustawienia widoku
|
||||
self.setDragMode(QGraphicsView.DragMode.ScrollHandDrag) # przesuwanie myszą
|
||||
self.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
self.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
|
||||
|
||||
# Wyłączenie suwaków
|
||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||
# Parametry zoomu
|
||||
self._zoom_factor = 1.25
|
||||
self._current_scale = 1.0
|
||||
|
||||
def set_image(self, pixmap: QPixmap):
|
||||
# pixmap = QPixmap(image_path)
|
||||
self._pixmap_item.setPixmap(pixmap)
|
||||
self._scene.setSceneRect(pixmap.rect())
|
||||
# self.reset_transform()
|
||||
|
||||
def reset_transform(self):
|
||||
"""Resetuje skalowanie i ustawia 1:1"""
|
||||
self._current_scale = 1.0
|
||||
self.setTransform(self.transform().fromScale(1, 1))
|
||||
|
||||
def wheelEvent(self, event: QWheelEvent):
|
||||
"""Zoom kółkiem myszy"""
|
||||
if event.modifiers() & Qt.KeyboardModifier.ControlModifier: # zoom tylko z CTRL
|
||||
if event.angleDelta().y() > 0:
|
||||
zoom = self._zoom_factor
|
||||
else:
|
||||
zoom = 1 / self._zoom_factor
|
||||
|
||||
self._current_scale *= zoom
|
||||
self.scale(zoom, zoom)
|
||||
else:
|
||||
return
|
||||
super().wheelEvent(event) # normalne przewijanie
|
||||
|
||||
class CameraPlaceholder(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.setAutoFillBackground(True)
|
||||
self.setStyleSheet("background-color: #141414;")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(20)
|
||||
|
||||
self.camera_start_btn = QPushButton("Start Camera")
|
||||
self.camera_start_btn.setFixedSize(200, 50)
|
||||
style_sheet = """
|
||||
QPushButton {
|
||||
/* --- Styl podstawowy --- */
|
||||
background-color: transparent;
|
||||
border: 2px solid #CECECE; /* Grubość, styl i kolor obramowania */
|
||||
border-radius: 25px; /* Kluczowa właściwość do zaokrąglenia rogów! */
|
||||
color: #CECECE;
|
||||
padding: 10px 20px; /* Wewnętrzny margines */
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
QPushButton:hover {
|
||||
/* --- Styl po najechaniu myszką --- */
|
||||
color: #F0F0F0;
|
||||
border: 2px solid #F0F0F0;
|
||||
}
|
||||
|
||||
QPushButton:pressed {
|
||||
/* --- Styl po naciśnięciu --- */
|
||||
background-color: #e0e0e0; /* Ciemniejsze tło w momencie kliknięcia */
|
||||
border: 2px solid #e0e0e0; /* Zmiana koloru ramki dla sygnalizacji akcji */
|
||||
}
|
||||
"""
|
||||
self.camera_start_btn.setStyleSheet(style_sheet)
|
||||
|
||||
self.info_label = QLabel("Kliknij, aby uruchomić kamerę")
|
||||
self.info_label.setStyleSheet("background-color: transparent; color: #CECECE; font-size: 18px;")
|
||||
self.info_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
layout.addStretch()
|
||||
layout.addWidget(self.camera_start_btn, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||
layout.addWidget(self.info_label)
|
||||
layout.addStretch()
|
||||
self.setLayout(layout)
|
||||
|
||||
def set_info_text(self, text: str):
|
||||
self.info_label.setText(text)
|
||||
|
||||
class SplitView(QSplitter):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
print("Inicjalizacja SplitView2")
|
||||
self.setOrientation(Qt.Orientation.Vertical)
|
||||
|
||||
self.widget_start = CameraPlaceholder()
|
||||
self.widget_live = ZoomableImageView()
|
||||
# self.widget_live = PlaceholderWidget("Camera View", "#750466")
|
||||
self.widget_ref = ZoomableImageView()
|
||||
# self.widget_ref = PlaceholderWidget("Image View", "#007981")
|
||||
|
||||
self.stack = QStackedWidget()
|
||||
self.stack.addWidget(self.widget_start)
|
||||
self.stack.addWidget(self.widget_live)
|
||||
self.stack.setCurrentWidget(self.widget_start)
|
||||
|
||||
self.addWidget(self.stack)
|
||||
self.addWidget(self.widget_ref)
|
||||
|
||||
self.setSizes([self.height(), 0])
|
||||
|
||||
pixmap = QPixmap("media/empty_guitar_h.jpg")
|
||||
# pixmap.fill(Qt.GlobalColor.lightGray)
|
||||
self.widget_live.set_image(pixmap)
|
||||
|
||||
def toggle_orientation(self):
|
||||
if self.orientation() == Qt.Orientation.Vertical:
|
||||
self.setOrientation(Qt.Orientation.Horizontal)
|
||||
self.setSizes([self.width()//2, self.width()//2])
|
||||
else:
|
||||
self.setOrientation(Qt.Orientation.Vertical)
|
||||
self.setSizes([self.height()//2, self.height()//2])
|
||||
|
||||
# def set_live_image(self, path_image: str):
|
||||
# """Ustawienie obrazu na żywo"""
|
||||
# pixmap = QPixmap(path_image)
|
||||
# self.widget_live.set_image(pixmap)
|
||||
|
||||
def set_live_image(self, pixmap: QPixmap):
|
||||
"""Ustawienie obrazu na żywo"""
|
||||
self.widget_live.set_image(pixmap)
|
||||
if self.stack.currentWidget() != self.widget_live:
|
||||
self.stack.setCurrentWidget(self.widget_live)
|
||||
|
||||
def set_reference_image(self, path_image: str):
|
||||
"""Ustawienie obrazu referencyjnego"""
|
||||
pixmap = QPixmap(path_image)
|
||||
self.widget_ref.set_image(pixmap)
|
||||
|
||||
def toglle_live_view(self):
|
||||
"""Przełączanie widoku na żywo"""
|
||||
if self.stack.currentWidget() == self.widget_start:
|
||||
self.stack.setCurrentWidget(self.widget_live)
|
||||
else:
|
||||
self.stack.setCurrentWidget(self.widget_start)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user