From 6a1201432ca7dfff91fd359f81a1a8454e0ca2db Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 30 Dec 2021 23:19:25 -0800 Subject: [PATCH] Hard-code picam resolutions (#366) * Hard-code picam resolutions * Address review comment --- .../vision/camera/USBCameraSource.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java index f22ed6eff..4227682d0 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java @@ -174,7 +174,19 @@ public class USBCameraSource extends VisionSource { videoModes = new HashMap<>(); List videoModesList = new ArrayList<>(); try { - var modes = camera.enumerateVideoModes(); + VideoMode[] modes; + if (cameraQuirks.hasQuirk(CameraQuirk.PiCam)) { + modes = + new VideoMode[] { + new VideoMode(VideoMode.PixelFormat.kBGR, 320, 240, 90), + new VideoMode(VideoMode.PixelFormat.kBGR, 640, 480, 90), + new VideoMode(VideoMode.PixelFormat.kBGR, 960, 720, 60), + new VideoMode(VideoMode.PixelFormat.kBGR, 1280, 720, 45), + new VideoMode(VideoMode.PixelFormat.kBGR, 1920, 1080, 20), + }; + } else { + modes = camera.enumerateVideoModes(); + } for (int i = 0; i < modes.length; i++) { var videoMode = modes[i]; @@ -234,24 +246,6 @@ public class USBCameraSource extends VisionSource { sortedList.remove(badIdx); } - // Filter bogus modes on picam - if (cameraQuirks.hasQuirk(CameraQuirk.PiCam)) { - sortedList.removeIf( - it -> - (it.width == 1296 - && it.height == 730 - && it.pixelFormat == VideoMode.PixelFormat.kBGR) - || (it.width == 1296 - && it.height == 972 - && it.pixelFormat == VideoMode.PixelFormat.kBGR) - || (it.width == 2592 - && it.height == 1944 - && it.pixelFormat == VideoMode.PixelFormat.kBGR) - || (it.width == 160 - && it.height == 120 - && it.pixelFormat == VideoMode.PixelFormat.kBGR)); - } - for (VideoMode videoMode : sortedList) { videoModes.put(sortedList.indexOf(videoMode), videoMode); }