Skip to content

set maximum FPS for webcams #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down