Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions photon-client/src/components/cameras/CameraCalibrationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,32 @@ watchEffect(() => {
uniqueVideoResolutionIndex.value = currentIndex;
});
const dimensionUnit = ref<"in" | "mm">("in");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which unit do we want to be the default?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only kept it as inches since that's the existing behaviour.

I reckon whatever the default is should match whatever's in the board PDF.

const squareSizeIn = ref(1);
const markerSizeIn = ref(0.75);
const squareSizeMm = ref(30);
const markerSizeMm = ref(22);
const patternWidth = ref(8);
const patternHeight = ref(8);
const boardType = ref<CalibrationBoardTypes>(CalibrationBoardTypes.Charuco);
const useOldPattern = ref(false);
const tagFamily = ref<CalibrationTagFamilies>(CalibrationTagFamilies.Dict_4X4_1000);
const requestedVideoFormatIndex = ref(0);

const convertInchesToDisplay = (valueInInches: number) =>
dimensionUnit.value === "mm" ? valueInInches * MM_PER_INCH : valueInInches;
const convertMetricToDisplay = (valueInMm: number) =>
dimensionUnit.value === "in" ? valueInMm / MM_PER_INCH : valueInMm;

const convertDisplayToInches = (displayValue: number) =>
dimensionUnit.value === "mm" ? displayValue / MM_PER_INCH : displayValue;
const convertDisplayToMetric = (displayValue: number) =>
dimensionUnit.value === "in" ? displayValue * MM_PER_INCH : displayValue;

const squareSize = computed({
get: () => convertInchesToDisplay(squareSizeIn.value),
get: () => convertMetricToDisplay(squareSizeMm.value),
set(value) {
squareSizeIn.value = convertDisplayToInches(value);
squareSizeMm.value = convertDisplayToMetric(value);
}
});

const markerSize = computed({
get: () => convertInchesToDisplay(markerSizeIn.value),
get: () => convertMetricToDisplay(markerSizeMm.value),
set(value) {
markerSizeIn.value = convertDisplayToInches(value);
markerSizeMm.value = convertDisplayToMetric(value);
}
});

Expand All @@ -149,7 +149,7 @@ const tooManyPoints = computed(
const downloadCalibBoard = async () => {
const { jsPDF } = await jspdf;
const { font } = await PromptRegular;
const doc = new jsPDF({ unit: "in", format: "letter" });
const doc = new jsPDF({ unit: "mm", format: "letter" });

doc.addFileToVFS("Prompt-Regular.tff", font);
doc.addFont("Prompt-Regular.tff", "Prompt-Regular", "normal");
Expand All @@ -161,28 +161,34 @@ const downloadCalibBoard = async () => {

switch (boardType.value) {
case CalibrationBoardTypes.Chessboard:
const chessboardStartX = (paperWidth - patternWidth.value * squareSizeIn.value) / 2;
const chessboardStartX = (paperWidth - patternWidth.value * squareSizeMm.value) / 2;

const chessboardStartY = (paperHeight - patternWidth.value * squareSizeIn.value) / 2;
const chessboardStartY = (paperHeight - patternWidth.value * squareSizeMm.value) / 2;

for (let squareY = 0; squareY < patternHeight.value; squareY++) {
for (let squareX = 0; squareX < patternWidth.value; squareX++) {
const xPos = chessboardStartX + squareX * squareSizeIn.value;
const yPos = chessboardStartY + squareY * squareSizeIn.value;
const xPos = chessboardStartX + squareX * squareSizeMm.value;
const yPos = chessboardStartY + squareY * squareSizeMm.value;

// Only draw the odd squares to create the chessboard pattern
if (squareY % 2 !== squareX % 2) {
doc.rect(xPos, yPos, squareSizeIn.value, squareSizeIn.value, "F");
doc.rect(xPos, yPos, squareSizeMm.value, squareSizeMm.value, "F");
}
}
}
doc.text(`${patternWidth.value} x ${patternHeight.value} | ${squareSizeIn.value}in`, paperWidth - 1, 1.0, {
maxWidth: (paperWidth - 2.0) / 2,
align: "right"
});
doc.text(
`${patternWidth.value} x ${patternHeight.value} | ${squareSize.value}${dimensionUnit.value}`,
paperWidth - 1,
1.0,
{
maxWidth: (paperWidth - 2.0) / 2,
align: "right"
}
);
break;

case CalibrationBoardTypes.Charuco:
// TODO: Dynamically generate ChArUco using opencv
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot I left this TODO in here. Dynamic ChArUco generation might be the topic of another PR though.

// Add pregenerated ChArUco
const charucoImage = new Image();
charucoImage.src = CharucoImage;
Expand Down Expand Up @@ -220,8 +226,8 @@ const isCalibrating = computed(

const startCalibration = () => {
useCameraSettingsStore().startPnPCalibration({
squareSizeIn: squareSizeIn.value,
markerSizeIn: markerSizeIn.value,
squareSizeMm: squareSizeMm.value,
markerSizeMm: markerSizeMm.value,
patternHeight: patternHeight.value,
patternWidth: patternWidth.value,
boardType: boardType.value,
Expand Down
4 changes: 2 additions & 2 deletions photon-client/src/stores/settings/CameraSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ export const useCameraSettingsStore = defineStore("cameraSettings", {
*/
startPnPCalibration(
calibrationInitData: {
squareSizeIn: number;
markerSizeIn: number;
squareSizeMm: number;
markerSizeMm: number;
patternWidth: number;
patternHeight: number;
boardType: CalibrationBoardTypes;
Expand Down
4 changes: 2 additions & 2 deletions photon-client/src/types/WebsocketDataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export interface WebsocketCalibrationData {
minCount: number;
videoModeIndex: number;
patternHeight: number;
squareSizeIn: number;
markerSizeIn: number;
squareSizeMm: number;
markerSizeMm: number;
}

export interface IncomingWebsocketData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class UICalibrationData {
public int count;
public int minCount;
public boolean hasEnough;
public double squareSizeIn;
public double squareSizeMm;
public int patternWidth;
public int patternHeight;
public BoardType boardType;
public double markerSizeIn;
public double markerSizeMm;
public boolean useOldPattern;
public TagFamily tagFamily;

Expand All @@ -39,8 +39,8 @@ public UICalibrationData(
int videoModeIndex,
int minCount,
boolean hasEnough,
double squareSizeIn,
double markerSizeIn,
double squareSizeMm,
double markerSizeMm,
int patternWidth,
int patternHeight,
BoardType boardType,
Expand All @@ -50,8 +50,8 @@ public UICalibrationData(
this.minCount = minCount;
this.videoModeIndex = videoModeIndex;
this.hasEnough = hasEnough;
this.squareSizeIn = squareSizeIn;
this.markerSizeIn = markerSizeIn;
this.squareSizeMm = squareSizeMm;
this.markerSizeMm = markerSizeMm;
this.patternWidth = patternWidth;
this.patternHeight = patternHeight;
this.boardType = boardType;
Expand Down Expand Up @@ -94,10 +94,10 @@ public String toString() {
+ minCount
+ ", hasEnough="
+ hasEnough
+ ", squareSizeIn="
+ squareSizeIn
+ ", markerSizeIn="
+ markerSizeIn
+ ", squareSizeMm="
+ squareSizeMm
+ ", markerSizeMm="
+ markerSizeMm
+ ", patternWidth="
+ patternWidth
+ ", patternHeight="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.photonvision.vision.pipeline.result.CVPipelineResult;
import org.photonvision.vision.target.TargetModel;
import org.photonvision.vision.target.TrackedTarget;
import org.wpilib.math.util.Units;
import org.wpilib.vision.camera.CameraServerJNI;
import org.wpilib.vision.camera.VideoException;

Expand Down Expand Up @@ -383,8 +382,8 @@ public void startCalibration(UICalibrationData data) {
+ data.videoModeIndex
+ " and settings "
+ data);
settings.gridSize = Units.inchesToMeters(data.squareSizeIn);
settings.markerSize = Units.inchesToMeters(data.markerSizeIn);
settings.gridSize = data.squareSizeMm / 1000;
settings.markerSize = data.markerSizeMm / 1000;
settings.boardHeight = data.patternHeight;
settings.boardWidth = data.patternWidth;
settings.boardType = data.boardType;
Expand Down
Loading