Skip to content

Commit

Permalink
Remove cal images if needed and bump http request size
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Mar 22, 2024
1 parent 15da06b commit 6e18c45
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
36 changes: 33 additions & 3 deletions photon-client/src/components/cameras/CameraCalibrationInfoCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useCameraSettingsStore } from "@/stores/settings/CameraSettingsStore";
import { useStateStore } from "@/stores/StateStore";
import { computed, inject, ref } from "vue";
import { getResolutionString, parseJsonFile } from "@/lib/PhotonUtils";
import axios from "axios";

Check warning on line 7 in photon-client/src/components/cameras/CameraCalibrationInfoCard.vue

View workflow job for this annotation

GitHub Actions / PhotonClient Lint and Formatting

'axios' is defined but never used
import loadingImage from "@/assets/images/loading.svg";
const props = defineProps<{
videoFormat: VideoFormat;
Expand Down Expand Up @@ -36,13 +38,36 @@ const importCalibration = async () => {
return;
}
let message: any = undefined;
// check size and trim if we have to
let approxSizeMb = uploadedJson.size / 1e6;
if (approxSizeMb > 50) {
data.observations.map((it) => (it.snapshotData = undefined));
// so at this point the calibration is likely pretty small -- it's cheap enough to check though
approxSizeMb = JSON.stringify(data).length / 1e6;
if (approxSizeMb > 50) {
// Absolutely monster dataset, try trimming again
data.observations = [];
}
message = {
color: "warning",
message: `The calibration file was very large (~${approxSizeMb.toFixed(0)}MB) -- images were removed to save space!`,
timeout: 10000
};
}
useCameraSettingsStore()
.importCalibrationFromData({ calibration: data })
.then((response) => {
useStateStore().showSnackbarMessage({
message = message || {
color: "success",
message: response.data.text || response.data
});
};
useStateStore().showSnackbarMessage(message);
})
.catch((error) => {
if (error.response) {
Expand Down Expand Up @@ -256,7 +281,12 @@ const calibrationImageURL = (index: number) =>
<template #expanded-item="{ headers, item }">
<td :colspan="headers.length">
<div style="display: flex; justify-content: center; width: 100%">
<img :src="calibrationImageURL(item.index)" alt="observation image" class="snapshot-preview pt-2 pb-2" />
<v-img
:src="calibrationImageURL(item.index)"
:lazy-src="loadingImage"
alt="observation image"
class="snapshot-preview pt-2 pb-2"
/>
</div>
</td>
</template>
Expand Down
2 changes: 1 addition & 1 deletion photon-client/src/types/SettingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export interface BoardObservation {
optimisedCameraToObject: Pose3d;
includeObservationInCalibration: boolean;
snapshotName: string;
snapshotData: JsonImageMat;
snapshotData?: JsonImageMat;
}

export interface CameraCalibrationResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ public static void onCalibrationSnapshotRequest(Context ctx) {
.findFirst()
.orElse(null);

if (calList == null || calList.observations.size() < observationIdx) {
if (calList == null
|| calList.observations.size() < observationIdx
|| calList.observations.get(observationIdx).snapshotData == null) {
ctx.status(404);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void start(int port) {

// Increase the upload size limit (arbitrary, but need to be able to deal with large
// calibration JSONs)
javalinConfig.http.maxRequestSize = (long) (50 * 1e6);
javalinConfig.http.maxRequestSize = (long) (100 * 1e6);

javalinConfig.requestLogger.http(
(ctx, ms) -> {
Expand Down

0 comments on commit 6e18c45

Please sign in to comment.