Skip to content

Commit

Permalink
Merge branch 'PhotonVision:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
levyishai committed Apr 15, 2024
2 parents 214facc + 0106880 commit e462114
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
10 changes: 8 additions & 2 deletions photon-client/src/components/app/photon-camera-stream.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, inject } from "vue";
import { computed, inject, ref, onBeforeUnmount } from "vue";
import { useCameraSettingsStore } from "@/stores/settings/CameraSettingsStore";
import { useStateStore } from "@/stores/StateStore";
import loadingImage from "@/assets/images/loading.svg";
Expand Down Expand Up @@ -53,11 +53,17 @@ const handleFullscreenRequest = () => {
if (!stream) return;
stream.requestFullscreen();
};
const mjpgStream: any = ref(null);
onBeforeUnmount(() => {
if (!mjpgStream.value) return;
mjpgStream.value["src"] = null;
});
</script>

<template>
<div class="stream-container">
<img :id="id" crossorigin="anonymous" :src="streamSrc" :alt="streamDesc" :style="streamStyle" />
<img :id="id" crossorigin="anonymous" :src="streamSrc" :alt="streamDesc" :style="streamStyle" ref="mjpgStream" />
<div class="stream-overlay" :style="overlayStyle">
<pv-icon
icon-name="mdi-camera-image"
Expand Down
6 changes: 6 additions & 0 deletions photon-client/src/components/cameras/CamerasView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ th {
justify-content: center;
}

@media only screen and (min-width: 960px) {
#camera-settings-camera-view-card {
position: sticky;
top: 12px;
}
}
@media only screen and (min-width: 512px) and (max-width: 960px) {
.stream-container {
flex-wrap: nowrap;
Expand Down
2 changes: 1 addition & 1 deletion photon-client/src/components/dashboard/tabs/TargetsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const calculateStdDev = (values: number[]): number => {
};
const resetCurrentBuffer = () => {
// Need to clear the array in place
while (useStateStore().currentMultitagBuffer?.length != 0) useStateStore().currentMultitagBuffer?.pop();
if (useStateStore().currentMultitagBuffer) useStateStore().currentMultitagBuffer!.length = 0;
};
</script>

Expand Down
3 changes: 2 additions & 1 deletion photon-client/src/stores/StateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const useStateStore = defineStore("state", {
return this.backendResults[this.currentCameraIndex.toString()];
},
currentMultitagBuffer(): MultitagResult[] | undefined {
return this.multitagResultBuffer[this.currentCameraIndex.toString()];
if (!this.multitagResultBuffer[this.currentCameraIndex]) this.multitagResultBuffer[this.currentCameraIndex] = [];
return this.multitagResultBuffer[this.currentCameraIndex];
}
},
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
package org.photonvision.vision.frame.provider;

import edu.wpi.first.cscore.CvSink;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.vision.opencv.CVMat;
import org.photonvision.vision.processes.VisionSourceSettables;

public class USBFrameProvider extends CpuImageProcessor {
private static final Logger logger = new Logger(USBFrameProvider.class, LogGroup.Camera);

private final CvSink cvSink;

@SuppressWarnings("SpellCheckingInspection")
Expand All @@ -43,9 +46,9 @@ public CapturedFrame getInputMat() {
cvSink.grabFrame(mat.getMat())
* 1000; // Units are microseconds, epoch is the same as the Unix epoch

// Sometimes CSCore gives us a zero frametime.
if (time <= 1e-6) {
time = MathUtils.wpiNanoTime();
if (time == 0) {
var error = cvSink.getError();
logger.error("Error grabbing image: " + error);
}

return new CapturedFrame(mat, settables.getFrameStaticProperties(), time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ private void update() {
// Grab the new camera frame
var frame = frameSupplier.get();

// Frame empty -- no point in trying to do anything more?
if (frame.processedImage.getMat().empty() && frame.colorImage.getMat().empty()) {
// give up without increasing loop count
continue;
}

// There's no guarantee the processing type change will occur this tick, so pipelines should
// check themselves
try {
Expand Down

0 comments on commit e462114

Please sign in to comment.