delete unused files
This commit is contained in:
@@ -1,97 +0,0 @@
|
|||||||
# 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,148 +0,0 @@
|
|||||||
import cv2
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
GP_WIDGET_WINDOW = 0
|
|
||||||
GP_WIDGET_SECTION = 0
|
|
||||||
GP_WIDGET_TEXT = 0
|
|
||||||
GP_WIDGET_RANGE = 0
|
|
||||||
GP_WIDGET_TOGGLE = 0
|
|
||||||
GP_WIDGET_RADIO = 0
|
|
||||||
GP_WIDGET_MENU = 0
|
|
||||||
GP_WIDGET_BUTTON = 0
|
|
||||||
GP_WIDGET_DATE = 0
|
|
||||||
|
|
||||||
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 CameraListMock:
|
|
||||||
def count(self):
|
|
||||||
return 1
|
|
||||||
|
|
||||||
def get_name(self, idx):
|
|
||||||
return f"mock_name {idx}"
|
|
||||||
|
|
||||||
def get_value(self, idx):
|
|
||||||
return f"mock_value {idx}"
|
|
||||||
|
|
||||||
class MockPortInfo:
|
|
||||||
def __init__(self, address):
|
|
||||||
self.address = address
|
|
||||||
|
|
||||||
class PortInfoList:
|
|
||||||
def __init__(self):
|
|
||||||
self._ports = []
|
|
||||||
|
|
||||||
def load(self):
|
|
||||||
# Dodaj przykładowe porty
|
|
||||||
self._ports = [MockPortInfo("usb:001,002"), MockPortInfo("usb:001,003")]
|
|
||||||
|
|
||||||
def lookup_path(self, port_address):
|
|
||||||
for idx, port in enumerate(self._ports):
|
|
||||||
if port.address == port_address:
|
|
||||||
return idx
|
|
||||||
raise ValueError("Port not found")
|
|
||||||
|
|
||||||
def __getitem__(self, idx):
|
|
||||||
return self._ports[idx]
|
|
||||||
|
|
||||||
class ConfigMock:
|
|
||||||
def get_id(self):
|
|
||||||
return 0
|
|
||||||
def get_name(self):
|
|
||||||
return "name"
|
|
||||||
def get_label(self):
|
|
||||||
return "label"
|
|
||||||
def get_type(self):
|
|
||||||
return 0
|
|
||||||
def get_value(self):
|
|
||||||
return "value"
|
|
||||||
def get_choices(self):
|
|
||||||
return []
|
|
||||||
def count_children(self):
|
|
||||||
return 0
|
|
||||||
def get_child(self):
|
|
||||||
return ConfigMock()
|
|
||||||
|
|
||||||
|
|
||||||
class CameraAbilitiesList:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self.abilities = []
|
|
||||||
def load(self):
|
|
||||||
return
|
|
||||||
def lookup_model(self, name):
|
|
||||||
return 1
|
|
||||||
def get_abilities(self, abilities_index):
|
|
||||||
return 0
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
def set_port_info(self, obj):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_config(self):
|
|
||||||
return ConfigMock()
|
|
||||||
|
|
||||||
def set_single_config(self, name, widget):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def gp_camera_autodetect():
|
|
||||||
return CameraListMock()
|
|
||||||
|
|
||||||
def check_result(obj):
|
|
||||||
return obj
|
|
||||||
Reference in New Issue
Block a user