Skip to content

Commit

Permalink
We do it in frontend I guess.
Browse files Browse the repository at this point in the history
  • Loading branch information
BytingBulldogs3539 committed May 10, 2024
1 parent eb0fb2d commit afe82d2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 104 deletions.
91 changes: 68 additions & 23 deletions photon-client/src/components/cameras/CameraCalibrationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,88 @@ import PvSwitch from "@/components/common/pv-switch.vue";
import PvSelect from "@/components/common/pv-select.vue";
import PvNumberInput from "@/components/common/pv-number-input.vue";
import { WebsocketPipelineType } from "@/types/WebsocketDataTypes";
import { getResolutionString } from "@/lib/PhotonUtils";
import { getResolutionString, resolutionsAreEqual } from "@/lib/PhotonUtils";
import CameraCalibrationInfoCard from "@/components/cameras/CameraCalibrationInfoCard.vue";
import { useSettingsStore } from "@/stores/settings/GeneralSettingsStore";
const settingsValid = ref(true);
const getUniqueVideoFormatsByResolution = (): VideoFormat[] => {
const uniqueResolutions: VideoFormat[] = [];
useCameraSettingsStore().currentCameraSettings.uniqueVideoFormats.forEach((format) => {
const calib = useCameraSettingsStore().getCalibrationCoeffs(format.resolution);
if (calib !== undefined) {
// For each error, square it, sum the squares, and divide by total points N
if (calib.meanErrors.length) format.mean = calib.meanErrors.reduce((a, b) => a + b, 0) / calib.meanErrors.length;
else format.mean = NaN;
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.cameraIntrinsics.data[4] / calib.cameraIntrinsics.data[0])) ** 2
) / 2,
calib.cameraIntrinsics.data[0]
) *
(180 / Math.PI);
useCameraSettingsStore().currentCameraSettings.validVideoFormats.forEach((format, ind) => {

Check warning on line 24 in photon-client/src/components/cameras/CameraCalibrationCard.vue

View workflow job for this annotation

GitHub Actions / PhotonClient Lint and Formatting

'ind' is defined but never used
const index = uniqueResolutions.findIndex((v) => resolutionsAreEqual(v.resolution, format.resolution));
const contains = index!=-1;
let skip = false;
if(contains && format.fps>uniqueResolutions[index].fps){
uniqueResolutions.splice(index, 1);
} else if(contains) {
skip = true;
}
if (!skip) {
const calib = useCameraSettingsStore().getCalibrationCoeffs(format.resolution);
if (calib !== undefined) {
// For each error, square it, sum the squares, and divide by total points N
if (calib.meanErrors.length)
format.mean = calib.meanErrors.reduce((a, b) => a + b, 0) / calib.meanErrors.length;
else format.mean = NaN;
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.cameraIntrinsics.data[4] / calib.cameraIntrinsics.data[0])) ** 2
) / 2,
calib.cameraIntrinsics.data[0]
) *
(180 / Math.PI);
}
uniqueResolutions.push(format);
}
uniqueResolutions.push(format);
});
uniqueResolutions.sort(
(a, b) => b.resolution.width + b.resolution.height - (a.resolution.width + a.resolution.height)
);
return uniqueResolutions;
};
// const getUniqueVideoFormatsByResolution = (): VideoFormat[] => {
// const uniqueResolutions: VideoFormat[] = [];
// useCameraSettingsStore().currentCameraSettings.uniqueVideoFormats.forEach((format) => {
// const calib = useCameraSettingsStore().getCalibrationCoeffs(format.resolution);
// if (calib !== undefined) {
// // For each error, square it, sum the squares, and divide by total points N
// if (calib.meanErrors.length) format.mean = calib.meanErrors.reduce((a, b) => a + b, 0) / calib.meanErrors.length;
// else format.mean = NaN;
// 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.cameraIntrinsics.data[4] / calib.cameraIntrinsics.data[0])) ** 2
// ) / 2,
// calib.cameraIntrinsics.data[0]
// ) *
// (180 / Math.PI);
// }
// uniqueResolutions.push(format);
// });
// uniqueResolutions.sort(
// (a, b) => b.resolution.width + b.resolution.height - (a.resolution.width + a.resolution.height)
// );
// return uniqueResolutions;
// };
const getUniqueVideoResolutionStrings = (): { name: string; value: number }[] =>
getUniqueVideoFormatsByResolution().map<{ name: string; value: number }>((f) => ({
name: `${getResolutionString(f.resolution)}`,
Expand Down
17 changes: 0 additions & 17 deletions photon-client/src/stores/settings/CameraSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,6 @@ export const useCameraSettingsStore = defineStore("cameraSettings", {
standardDeviation: v.standardDeviation,
mean: v.mean
})),
uniqueVideoFormats: Object.entries(d.uniqueFormatList)
.sort(([firstKey], [secondKey]) => parseInt(firstKey) - parseInt(secondKey))
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.map<VideoFormat>(([k, v], i) => ({
resolution: {
width: v.width,
height: v.height
},
fps: v.fps,
pixelFormat: v.pixelFormat,
index: v.index || i,
diagonalFOV: v.diagonalFOV,
horizontalFOV: v.horizontalFOV,
verticalFOV: v.verticalFOV,
standardDeviation: v.standardDeviation,
mean: v.mean
})),
completeCalibrations: d.calibrations,
isCSICamera: d.isCSICamera,
pipelineNicknames: d.pipelineNicknames,
Expand Down
18 changes: 0 additions & 18 deletions photon-client/src/types/SettingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export interface CameraSettings {
};

validVideoFormats: VideoFormat[];
uniqueVideoFormats: VideoFormat[];
completeCalibrations: CameraCalibrationResult[];

lastPipelineIndex?: number;
Expand Down Expand Up @@ -225,23 +224,6 @@ export const PlaceholderCameraSettings: CameraSettings = {
pixelFormat: "RGB"
}
],
uniqueVideoFormats: [
{
resolution: { width: 1920, height: 1080 },
fps: 60,
pixelFormat: "RGB"
},
{
resolution: { width: 1280, height: 720 },
fps: 60,
pixelFormat: "RGB"
},
{
resolution: { width: 640, height: 480 },
fps: 30,
pixelFormat: "RGB"
}
],
completeCalibrations: [
{
resolution: { width: 1920, height: 1080 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public static class UICameraConfiguration {
public int currentPipelineIndex;
public List<String> pipelineNicknames;
public HashMap<Integer, HashMap<String, Object>> videoFormatList;
public HashMap<Integer, HashMap<String, Object>> uniqueFormatList;
public int outputStreamPort;
public int inputStreamPort;
public List<UICameraCalibrationCoefficients> calibrations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,26 +534,7 @@ public PhotonConfiguration.UICameraConfiguration toUICameraConfig() {

temp.put(k, internalMap);
}

var uniqueMap = new HashMap<Integer, HashMap<String, Object>>();
var uniqueVideoModes = visionSource.getSettables().getUniqueVideoModes();
for (var k : uniqueVideoModes.keySet()) {
var internalMap = new HashMap<String, Object>();

internalMap.put("width", uniqueVideoModes.get(k).width);
internalMap.put("height", uniqueVideoModes.get(k).height);
internalMap.put("fps", uniqueVideoModes.get(k).fps);
internalMap.put("index", k);
internalMap.put(
"pixelFormat",
((uniqueVideoModes.get(k) instanceof LibcameraGpuSource.FPSRatedVideoMode)
? "kPicam"
: uniqueVideoModes.get(k).pixelFormat.toString())
.substring(1)); // Remove the k prefix
uniqueMap.put(k, internalMap);
}
ret.videoFormatList = temp;
ret.uniqueFormatList = uniqueMap;
ret.outputStreamPort = this.outputStreamPort;
ret.inputStreamPort = this.inputStreamPort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,6 @@ public void setVideoModeIndex(int index) {

public abstract HashMap<Integer, VideoMode> getAllVideoModes();

public HashMap<Integer, VideoMode> getUniqueVideoModes() {
HashMap<Integer, VideoMode> output = new HashMap<Integer, VideoMode>();
HashMap<Integer, VideoMode> map = getAllVideoModes();
for (Map.Entry<Integer, VideoMode> mode : map.entrySet()) {
boolean skip = false;
for (Map.Entry<Integer, VideoMode> otherMode : output.entrySet()) {
if (otherMode.getValue().height == mode.getValue().height
&& otherMode.getValue().width == mode.getValue().width) {
if (mode.getValue().fps > otherMode.getValue().fps) {
output.remove(otherMode.getKey());
output.put(mode.getKey(), mode.getValue());
skip = true;
break;
} else {
skip = true;
break;
}
}
}
if (!skip) {
output.put(mode.getKey(), mode.getValue());
}
}
return output;
}

public double getFOV() {
return configuration.FOV;
}
Expand Down

0 comments on commit afe82d2

Please sign in to comment.