Skip to content

Commit

Permalink
v1.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Windwoes committed Jun 15, 2024
1 parent 773b2e6 commit 9bb45b3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
4 changes: 2 additions & 2 deletions easyopencv/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'org.openftc'
PUBLISH_ARTIFACT_ID = 'easyopencv'
PUBLISH_VERSION = '1.7.2'
PUBLISH_VERSION = '1.7.3'
}

android {
Expand Down Expand Up @@ -70,7 +70,7 @@ android {
dependencies {
//compileOnly fileTree(include: ['*.aar'], dir: '../libs')
debugApi project(':OpenCV-Android-SDK')
releaseApi 'org.openftc:opencv-repackaged-bundled-dylibs:4.7.0-A'
releaseApi 'org.openftc:opencv-repackaged-bundled-dylibs:4.10.0-A'
compileOnly 'org.firstinspires.ftc:RobotCore:9.0.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

package org.openftc.easyopencv;

import android.annotation.SuppressLint;
import android.graphics.ImageFormat;

import com.qualcomm.robotcore.util.RobotLog;
Expand Down Expand Up @@ -258,10 +259,10 @@ public void startStreaming(int width, int height)
@Override
public void startStreaming(int width, int height, OpenCvCameraRotation rotation)
{
startStreaming(width, height, rotation, StreamFormat.YUY2);
startStreaming(width, height, rotation, null);
}

private int streamFormat2ImageFormat(StreamFormat streamFormat)
private static int streamFormat2ImageFormat(StreamFormat streamFormat)
{
switch (streamFormat)
{
Expand All @@ -271,9 +272,47 @@ private int streamFormat2ImageFormat(StreamFormat streamFormat)
}
}

private static boolean isSizeSupportedForFormat(CameraCharacteristics characteristics, int width, int height, StreamFormat format)
{
for(Size s : characteristics.getSizes(streamFormat2ImageFormat(format)))
{
if(s.getHeight() == height && s.getWidth() == width)
{
return true;
}
}

return false;
}

@SuppressLint("DefaultLocale")
private static String getSizeAndFpsListForFormat(CameraCharacteristics characteristics, StreamFormat format)
{
StringBuilder builder = new StringBuilder();

boolean areAnySupported = false;

for(Size s : characteristics.getSizes(streamFormat2ImageFormat(format)))
{
int fps = characteristics.getMaxFramesPerSecond(streamFormat2ImageFormat(format), s);
builder.append(String.format("[%dx%d @ %dFPS], ", s.getWidth(), s.getHeight(), fps));
areAnySupported = true;
}

return areAnySupported ? builder.toString() : "NONE";
}

@SuppressLint("DefaultLocale")
@Override
public void startStreaming(final int width, final int height, OpenCvCameraRotation rotation, StreamFormat streamFormat)
{
boolean userExplicitlyRequestedFormat = streamFormat != null;

if (streamFormat == null)
{
streamFormat = StreamFormat.YUY2;
}

final int format = streamFormat2ImageFormat(streamFormat);

synchronized (cameraDeviceStateSync)
Expand All @@ -299,26 +338,36 @@ public void startStreaming(final int width, final int height, OpenCvCameraRotati

final CountDownLatch captureStartResult = new CountDownLatch(1);

boolean sizeSupported = false;
for(Size s : cameraCharacteristics.getSizes(format))
boolean sizeSupportedForReqFormat = isSizeSupportedForFormat(cameraCharacteristics, width, height, streamFormat);
boolean sizeSupportedForMjpeg = isSizeSupportedForFormat(cameraCharacteristics, width, height, StreamFormat.MJPEG);

if(!sizeSupportedForReqFormat)
{
if(s.getHeight() == height && s.getWidth() == width)
{
sizeSupported = true;
break;
}
throw new OpenCvCameraException(String.format(
"Camera does not support requested resolution for format %s!" +
"\nSupported resolutions for YUY2 are: %s\n" +
"\nSupported resolutions for MJPEG are: %s\n",
streamFormat,
getSizeAndFpsListForFormat(cameraCharacteristics, StreamFormat.YUY2),
getSizeAndFpsListForFormat(cameraCharacteristics, StreamFormat.MJPEG)
));
}

if(!sizeSupported)
final Size size = new Size(width, height);

if (!userExplicitlyRequestedFormat && streamFormat == StreamFormat.YUY2 && sizeSupportedForMjpeg)
{
StringBuilder supportedSizesBuilder = new StringBuilder();
int maxFpsYuy2 = cameraCharacteristics.getMaxFramesPerSecond(streamFormat2ImageFormat(StreamFormat.YUY2), size);
int maxFpsMjpeg = cameraCharacteristics.getMaxFramesPerSecond(streamFormat2ImageFormat(StreamFormat.MJPEG), size);

for(Size s : cameraCharacteristics.getSizes(format))
if (maxFpsMjpeg > maxFpsYuy2)
{
supportedSizesBuilder.append(String.format("[%dx%d], ", s.getWidth(), s.getHeight()));
RobotLog.addGlobalWarningMessage(String.format(
"You are using YUY2 image format for this camera. You could increase your maximum " +
"FPS from %d to %d by choosing MJPEG format. To suppress this warning, explicitly " +
"request YUY2 format.", maxFpsYuy2, maxFpsMjpeg
));
}

throw new OpenCvCameraException("Camera does not support requested resolution! Supported resolutions are " + supportedSizesBuilder.toString());
}

try
Expand All @@ -330,7 +379,6 @@ public void onConfigured( CameraCaptureSession session)
{
try
{
Size size = new Size(width, height);
int fps = cameraCharacteristics.getMaxFramesPerSecond(format, size);

//Indicate how we want to stream
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ As of FTC SDK v8.2, EasyOpenCV is now packaged with the SDK as part of the Visio

## Changelog:

### v1.7.3
- Updates `libjpeg-turbo` to 3.0.3
- Updates OpenCV to v4.10.0
- Show more detail about camera supported resolutions and formats when user requests unsupported configuration
- Show warning if performance could be improved by using MJPEG format

### v1.7.2

- Fix race conditions when handling exception during viewport insertion
Expand Down

0 comments on commit 9bb45b3

Please sign in to comment.