diff --git a/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcam.java b/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcam.java index 48aa914..3eb11fa 100644 --- a/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcam.java +++ b/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcam.java @@ -58,6 +58,13 @@ enum StreamFormat */ void startStreaming(int width, int height, OpenCvCameraRotation rotation, StreamFormat streamFormat); + /** + * Same as {@link #startStreaming(int, int, OpenCvCameraRotation)} except for + * @param streamFormat indicates the desired stream format and + * @param maxFps indicates the maximum fps. + */ + void startStreaming(int width, int height, OpenCvCameraRotation rotation, StreamFormat streamFormat, int maxFps); + /*** * Gets the {@link ExposureControl} for this webcam. * Please see that interface's javadoc for how to use diff --git a/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcamImpl.java b/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcamImpl.java index f5b291d..b1754ef 100644 --- a/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcamImpl.java +++ b/easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcamImpl.java @@ -259,7 +259,13 @@ public void startStreaming(int width, int height) @Override public void startStreaming(int width, int height, OpenCvCameraRotation rotation) { - startStreaming(width, height, rotation, null); + startStreaming(width, height, rotation, null, 0); + } + + @Override + public void startStreaming(final int width, final int height, OpenCvCameraRotation rotation, StreamFormat streamFormat) + { + startStreaming(width, height, rotation, streamFormat, 0); } private static int streamFormat2ImageFormat(StreamFormat streamFormat) @@ -302,9 +308,22 @@ private static String getSizeAndFpsListForFormat(CameraCharacteristics character return areAnySupported ? builder.toString() : "NONE"; } + /*** + * Set a specific number of frames per second the image sensor should capture. + * + * Note that your pipeline may not be fast enough to keep up with what you ask the sensor + * to send, which will result in your pipeline FPS not matching what you set here. + * + * For instance, suppose you request 24FPS, but your pipeline requires an amount of + * compute time that results in it only being able to run at 15FPS. In that case, your + * pipeline will still run at 15FPS. + * + * Conversely, if your pipeline is capable of processing 100 frames per second, but + * you request only 15FPS from the sensor, your pipeline will run at 15FPS. + * + */ @SuppressLint("DefaultLocale") - @Override - public void startStreaming(final int width, final int height, OpenCvCameraRotation rotation, StreamFormat streamFormat) + public void startStreaming(final int width, final int height, OpenCvCameraRotation rotation, StreamFormat streamFormat, final int maxFps) { boolean userExplicitlyRequestedFormat = streamFormat != null; @@ -380,6 +399,7 @@ public void onConfigured( CameraCaptureSession session) try { int fps = cameraCharacteristics.getMaxFramesPerSecond(format, size); + if (maxFps > 0 && maxFps < fps) fps = maxFps; //Indicate how we want to stream final CameraCaptureRequest cameraCaptureRequest = camera.createCaptureRequest(format, size, fps); diff --git a/examples/src/main/java/org/firstinspires/ftc/teamcode/WebcamExample.java b/examples/src/main/java/org/firstinspires/ftc/teamcode/WebcamExample.java index 4d0d692..914a73c 100644 --- a/examples/src/main/java/org/firstinspires/ftc/teamcode/WebcamExample.java +++ b/examples/src/main/java/org/firstinspires/ftc/teamcode/WebcamExample.java @@ -97,7 +97,7 @@ public void onOpened() * For a rear facing camera or a webcam, rotation is defined assuming the camera is facing * away from the user. */ - webcam.startStreaming(320, 240, OpenCvCameraRotation.UPRIGHT); + webcam.startStreaming(960, 600, OpenCvCameraRotation.UPRIGHT, OpenCvWebcam.StreamFormat.YUY2, 30); } @Override