GUI: added face_detection hadnling to daq_worker.py

This commit is contained in:
leonarski_f committed 2025-10-24 17:31:21 +02:00
1 parent d658fe4336
commit 28f7369a86
2 files changed
+27 -2

No files matched your search

-2
View File
@@ -953,8 +953,6 @@ class AareDAQ:
B_max = 10.0 * y_std
bounds = ([-np.inf, 0.0, -math.pi], [np.inf, B_max, math.pi])
def area_fn(theta_deg: float) -> float:
return A + B * math.cos(math.radians(theta_deg) - phi)
try:
popt, _ = curve_fit(self._cos_model, degs, ys, p0=[A0, B0, phi0], bounds=bounds, maxfev=10000)
A, B, phi = map(float, popt)
+27
View File
@@ -25,6 +25,7 @@ class DAQWorker(QObject):
raster_scan_completed = Signal(CompletedRasterGrid)
standard_scan_completed = Signal(CompletedRotationScan)
raster_generated_by_ml = Signal(RasterGridRequest)
face_detection_result = Signal(dict)
def __init__(self, base_url: str | None, token: str, parent=None):
super().__init__(parent)
@@ -423,3 +424,29 @@ class DAQWorker(QObject):
reply = self.__net_manager.post(request, QByteArray(b""))
reply.finished.connect(lambda: self.handle_ml_box_response(reply))
def _handle_face_detection_response(self, reply: QNetworkReply):
try:
if reply.error() != QNetworkReply.NetworkError.NoError:
raise RuntimeError(reply.errorString())
payload = reply.readAll().data().decode("utf-8") or "{}"
import json
data = json.loads(payload)
self.face_detection_result.emit(data)
except Exception as e:
self.http_error.emit(str(e))
finally:
reply.deleteLater()
@Slot()
def face_detection(self):
if self.__base_url is None:
print(f"POST /face_detection/run")
return
request = QNetworkRequest(QUrl(f"{self.__base_url}/face_detection/run"))
request.setRawHeader(b"Authorization", f"Bearer {self.__token}".encode("utf-8"))
request.setRawHeader(b"Content-Type", b"application/json")
# fire-and-forget; handle reply asynchronously and emit result
reply = self.__net_manager.post(request, QByteArray(b""))
reply.finished.connect(lambda: self._handle_face_detection_response(reply))