From 2b36160a53f0bc120a43da3a556a4bdb972af776 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 23 Nov 2024 22:26:41 +0100 Subject: [PATCH] feat(Webcam): add option to overlay a nozzle crosshair for IDEX calibration Signed-off-by: Stefan Dej --- .../settings/Webcams/WebcamForm.vue | 100 ++++++++++++++++++ .../webcams/WebcamNozzleCrosshair.vue | 94 ++++++++++++++++ .../webcams/streamers/Mjpegstreamer.vue | 7 ++ .../streamers/MjpegstreamerAdaptive.vue | 7 ++ .../streamers/WebrtcCameraStreamer.vue | 14 ++- src/locales/en.json | 4 + src/store/gui/webcams/types.ts | 3 + 7 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 src/components/webcams/WebcamNozzleCrosshair.vue diff --git a/src/components/settings/Webcams/WebcamForm.vue b/src/components/settings/Webcams/WebcamForm.vue index 1de588da6..089339d46 100644 --- a/src/components/settings/Webcams/WebcamForm.vue +++ b/src/components/settings/Webcams/WebcamForm.vue @@ -143,6 +143,58 @@ :label="$t('Settings.WebcamsTab.Vertically')" /> + @@ -311,6 +363,54 @@ export default class WebcamForm extends Mixins(BaseMixin, WebcamMixin) { this.webcam.extra_data.enableAudio = newVal } + get nozzleCrosshairAvialable() { + return ['mjpegstreamer', 'mjpegstreamer-adaptive', 'webrtc-camerastreamer'].includes(this.webcam.service) + } + + get nozzleCrosshair() { + window.console.log(this.webcam.extra_data) + + return this.webcam.extra_data?.nozzleCrosshair ?? false + } + + set nozzleCrosshair(newVal) { + const extraData = { ...(this.webcam.extra_data ?? {}) } + extraData.nozzleCrosshair = newVal + + this.webcam.extra_data = extraData + } + + get nozzleCrosshairColor() { + return this.webcam.extra_data?.nozzleCrosshairColor ?? '#ff0000' + } + + set nozzleCrosshairColor(newVal: string) { + const extraData = { ...(this.webcam.extra_data ?? {}) } + extraData.nozzleCrosshairColor = newVal + + this.webcam.extra_data = extraData + } + + updateLogoColor(color: string | { hex: string }) { + if (typeof color === 'object') { + this.nozzleCrosshairColor = color.hex + return + } + + this.nozzleCrosshairColor = color + } + + get nozzleCrosshairSize() { + return this.webcam.extra_data?.nozzleCrosshairSize ?? 0.1 + } + + set nozzleCrosshairSize(newVal: number) { + const extraData = { ...(this.webcam.extra_data ?? {}) } + extraData.nozzleCrosshairSize = newVal + + this.webcam.extra_data = extraData + } + mounted() { this.oldWebcamName = this.webcam.name } diff --git a/src/components/webcams/WebcamNozzleCrosshair.vue b/src/components/webcams/WebcamNozzleCrosshair.vue new file mode 100644 index 000000000..413f46b6d --- /dev/null +++ b/src/components/webcams/WebcamNozzleCrosshair.vue @@ -0,0 +1,94 @@ + + + + + diff --git a/src/components/webcams/streamers/Mjpegstreamer.vue b/src/components/webcams/streamers/Mjpegstreamer.vue index 03706b94a..dcabf07fc 100644 --- a/src/components/webcams/streamers/Mjpegstreamer.vue +++ b/src/components/webcams/streamers/Mjpegstreamer.vue @@ -11,6 +11,7 @@ {{ $t('Panels.WebcamPanel.FPS') }}: {{ fpsOutput }} + @@ -99,6 +100,12 @@ export default class Mjpegstreamer extends Mixins(BaseMixin, WebcamMixin) { return this.$store.getters['gui/getPanelExpand']('webcam-panel', this.viewport) ?? false } + get showNozzleCrosshair() { + const nozzleCrosshair = this.camSettings.extra_data?.nozzleCrosshair ?? false + + return nozzleCrosshair && this.status === 'connected' + } + // start or stop the video when the expanded state changes @Watch('expanded', { immediate: true }) expandChanged(newExpanded: boolean): void { diff --git a/src/components/webcams/streamers/MjpegstreamerAdaptive.vue b/src/components/webcams/streamers/MjpegstreamerAdaptive.vue index cac1ee5f8..695831d31 100644 --- a/src/components/webcams/streamers/MjpegstreamerAdaptive.vue +++ b/src/components/webcams/streamers/MjpegstreamerAdaptive.vue @@ -12,6 +12,7 @@ {{ $t('Panels.WebcamPanel.FPS') }}: {{ fpsOutput }} + @@ -100,6 +101,12 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin, WebcamMixin return this.isVisibleDocument && this.isVisibleViewport } + get showNozzleCrosshair() { + const nozzleCrosshair = this.camSettings.extra_data?.nozzleCrosshair ?? false + + return nozzleCrosshair && this.status === 'connected' + } + mounted() { document.addEventListener('visibilitychange', this.documentVisibilityChanged) } diff --git a/src/components/webcams/streamers/WebrtcCameraStreamer.vue b/src/components/webcams/streamers/WebrtcCameraStreamer.vue index b3422bff8..3410f3cd3 100644 --- a/src/components/webcams/streamers/WebrtcCameraStreamer.vue +++ b/src/components/webcams/streamers/WebrtcCameraStreamer.vue @@ -1,5 +1,5 @@