Skip to content

Commit

Permalink
Update cal card to new data format
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Dec 20, 2023
1 parent fba44db commit 98e3381
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
19 changes: 12 additions & 7 deletions photon-client/src/components/cameras/CameraCalibrationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ const getUniqueVideoResolutions = (): VideoFormat[] => {
const calib = getCalibrationCoeffs(format.resolution);
if (calib !== undefined) {
format.mean = calib.perViewErrors.reduce((a, b) => a + b) / calib.perViewErrors.length;
format.horizontalFOV = 2 * Math.atan2(format.resolution.width / 2, calib.intrinsics[0]) * (180 / Math.PI);
format.verticalFOV = 2 * Math.atan2(format.resolution.height / 2, calib.intrinsics[4]) * (180 / Math.PI);
console.log(calib)
// Is this the right formula for RMS error? who knows! not me!
const perViewSumSquareReprojectionError = calib.observations.flatMap(it=>it.reprojectionErrors.flatMap(it2=>[it2.x, it2.y]))
format.mean = Math.sqrt(perViewSumSquareReprojectionError.reduce((a, b) => a + b, 0))
format.horizontalFOV = 2 * Math.atan2(format.resolution.width / 2, calib.cameraIntrinsics.data[0]) * (180 / Math.PI);
format.verticalFOV = 2 * Math.atan2(format.resolution.height / 2, calib.cameraIntrinsics.data[4]) * (180 / Math.PI);
format.diagonalFOV =
2 *
Math.atan2(
Math.sqrt(
format.resolution.width ** 2 +
(format.resolution.height / (calib.intrinsics[4] / calib.intrinsics[0])) ** 2
(format.resolution.height / (calib.cameraIntrinsics.data[4] / calib.cameraIntrinsics.data[0])) ** 2
) / 2,
calib.intrinsics[0]
calib.cameraIntrinsics.data[0]
) *
(180 / Math.PI);
}
Expand Down Expand Up @@ -492,12 +497,12 @@ const reprojectionErrorSeries = () => {
</v-col>
</v-row>

<LineChart
<!-- <LineChart
:chartData="reprojectionErrorSeries"
min="0"
max="3500"
ref="loadCell"
/>
/> -->

</div>
</v-card>
Expand Down
1 change: 0 additions & 1 deletion photon-client/src/stores/settings/CameraSettingsStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineStore } from "pinia";
import type {
CalibrationBoardTypes,
CameraCalibrationResult,
CameraSettings,
ConfigurableCameraSettings,
RobotOffsetType,
Expand Down
36 changes: 33 additions & 3 deletions photon-client/src/types/SettingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,44 @@ export interface VideoFormat {
diagonalFOV?: number;
horizontalFOV?: number;
verticalFOV?: number;
standardDeviation?: number;
mean?: number;
}

export interface JsonMat {
rows: number
cols: number
type: number
data: number[]
}

export interface Point3 {
x: number
y: number
z: number
}
export interface Point2 {
x: number
y: number
}

export interface Pose3d {
translation: { x: number, y: number, z: number }
rotation: { quaternion: { W: number, X: number, Y: number, Z: number } }
}

export interface BoardObservation {
locationInObjectSpace: Point3[]
locationInImageSpace: Point2[]
reprojectionErrors: Point2[]
optimisedCameraToObject: Pose3d[]
}

export interface CameraCalibrationResult {
resolution: Resolution;
distCoeffs: number[];
intrinsics: number[];
cameraIntrinsics: JsonMat;
// TODO rename to be Right
cameraExtrinsics: JsonMat;
observations: BoardObservation[]
}

export interface ConfigurableCameraSettings {
Expand Down
4 changes: 2 additions & 2 deletions photon-client/src/types/WebsocketDataTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GeneralSettings, LightingSettings, LogLevel, MetricData, NetworkSettings } from "@/types/SettingTypes";
import type { CameraCalibrationResult, GeneralSettings, LightingSettings, LogLevel, MetricData, NetworkSettings } from "@/types/SettingTypes";
import type { ActivePipelineSettings } from "@/types/PipelineTypes";
import type { AprilTagFieldLayout, PipelineResult } from "@/types/PhotonTrackingTypes";

Expand Down Expand Up @@ -46,7 +46,7 @@ export type WebsocketVideoFormat = Record<
>;

export interface WebsocketCameraSettingsUpdate {
calibrations: WebsocketCompleteCalib[];
calibrations: CameraCalibrationResult[];
currentPipelineIndex: number;
currentPipelineSettings: ActivePipelineSettings;
fov: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;

Expand All @@ -35,6 +36,7 @@
import org.opencv.core.Size;
import org.photonvision.vision.opencv.Releasable;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CameraCalibrationCoefficients implements Releasable {
public static final class BoardObservation {
@JsonProperty("locationInObjectSpace")
Expand Down Expand Up @@ -88,6 +90,10 @@ public CameraCalibrationCoefficients(
this.cameraIntrinsics = cameraIntrinsics;
this.distCoeffs = distCoeffs;

// Legacy migration just to make sure that observations is at worst empty and never null
if (observations == null) {
observations = List.of();
}
this.observations = observations;

// do this once so gets are quick
Expand Down

0 comments on commit 98e3381

Please sign in to comment.