Skip to content

Commit 9bb45b3

Browse files
committed
v1.7.3
1 parent 773b2e6 commit 9bb45b3

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

easyopencv/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
33
ext {
44
PUBLISH_GROUP_ID = 'org.openftc'
55
PUBLISH_ARTIFACT_ID = 'easyopencv'
6-
PUBLISH_VERSION = '1.7.2'
6+
PUBLISH_VERSION = '1.7.3'
77
}
88

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

easyopencv/src/main/java/org/openftc/easyopencv/OpenCvWebcamImpl.java

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
package org.openftc.easyopencv;
3636

37+
import android.annotation.SuppressLint;
3738
import android.graphics.ImageFormat;
3839

3940
import com.qualcomm.robotcore.util.RobotLog;
@@ -258,10 +259,10 @@ public void startStreaming(int width, int height)
258259
@Override
259260
public void startStreaming(int width, int height, OpenCvCameraRotation rotation)
260261
{
261-
startStreaming(width, height, rotation, StreamFormat.YUY2);
262+
startStreaming(width, height, rotation, null);
262263
}
263264

264-
private int streamFormat2ImageFormat(StreamFormat streamFormat)
265+
private static int streamFormat2ImageFormat(StreamFormat streamFormat)
265266
{
266267
switch (streamFormat)
267268
{
@@ -271,9 +272,47 @@ private int streamFormat2ImageFormat(StreamFormat streamFormat)
271272
}
272273
}
273274

275+
private static boolean isSizeSupportedForFormat(CameraCharacteristics characteristics, int width, int height, StreamFormat format)
276+
{
277+
for(Size s : characteristics.getSizes(streamFormat2ImageFormat(format)))
278+
{
279+
if(s.getHeight() == height && s.getWidth() == width)
280+
{
281+
return true;
282+
}
283+
}
284+
285+
return false;
286+
}
287+
288+
@SuppressLint("DefaultLocale")
289+
private static String getSizeAndFpsListForFormat(CameraCharacteristics characteristics, StreamFormat format)
290+
{
291+
StringBuilder builder = new StringBuilder();
292+
293+
boolean areAnySupported = false;
294+
295+
for(Size s : characteristics.getSizes(streamFormat2ImageFormat(format)))
296+
{
297+
int fps = characteristics.getMaxFramesPerSecond(streamFormat2ImageFormat(format), s);
298+
builder.append(String.format("[%dx%d @ %dFPS], ", s.getWidth(), s.getHeight(), fps));
299+
areAnySupported = true;
300+
}
301+
302+
return areAnySupported ? builder.toString() : "NONE";
303+
}
304+
305+
@SuppressLint("DefaultLocale")
274306
@Override
275307
public void startStreaming(final int width, final int height, OpenCvCameraRotation rotation, StreamFormat streamFormat)
276308
{
309+
boolean userExplicitlyRequestedFormat = streamFormat != null;
310+
311+
if (streamFormat == null)
312+
{
313+
streamFormat = StreamFormat.YUY2;
314+
}
315+
277316
final int format = streamFormat2ImageFormat(streamFormat);
278317

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

300339
final CountDownLatch captureStartResult = new CountDownLatch(1);
301340

302-
boolean sizeSupported = false;
303-
for(Size s : cameraCharacteristics.getSizes(format))
341+
boolean sizeSupportedForReqFormat = isSizeSupportedForFormat(cameraCharacteristics, width, height, streamFormat);
342+
boolean sizeSupportedForMjpeg = isSizeSupportedForFormat(cameraCharacteristics, width, height, StreamFormat.MJPEG);
343+
344+
if(!sizeSupportedForReqFormat)
304345
{
305-
if(s.getHeight() == height && s.getWidth() == width)
306-
{
307-
sizeSupported = true;
308-
break;
309-
}
346+
throw new OpenCvCameraException(String.format(
347+
"Camera does not support requested resolution for format %s!" +
348+
"\nSupported resolutions for YUY2 are: %s\n" +
349+
"\nSupported resolutions for MJPEG are: %s\n",
350+
streamFormat,
351+
getSizeAndFpsListForFormat(cameraCharacteristics, StreamFormat.YUY2),
352+
getSizeAndFpsListForFormat(cameraCharacteristics, StreamFormat.MJPEG)
353+
));
310354
}
311355

312-
if(!sizeSupported)
356+
final Size size = new Size(width, height);
357+
358+
if (!userExplicitlyRequestedFormat && streamFormat == StreamFormat.YUY2 && sizeSupportedForMjpeg)
313359
{
314-
StringBuilder supportedSizesBuilder = new StringBuilder();
360+
int maxFpsYuy2 = cameraCharacteristics.getMaxFramesPerSecond(streamFormat2ImageFormat(StreamFormat.YUY2), size);
361+
int maxFpsMjpeg = cameraCharacteristics.getMaxFramesPerSecond(streamFormat2ImageFormat(StreamFormat.MJPEG), size);
315362

316-
for(Size s : cameraCharacteristics.getSizes(format))
363+
if (maxFpsMjpeg > maxFpsYuy2)
317364
{
318-
supportedSizesBuilder.append(String.format("[%dx%d], ", s.getWidth(), s.getHeight()));
365+
RobotLog.addGlobalWarningMessage(String.format(
366+
"You are using YUY2 image format for this camera. You could increase your maximum " +
367+
"FPS from %d to %d by choosing MJPEG format. To suppress this warning, explicitly " +
368+
"request YUY2 format.", maxFpsYuy2, maxFpsMjpeg
369+
));
319370
}
320-
321-
throw new OpenCvCameraException("Camera does not support requested resolution! Supported resolutions are " + supportedSizesBuilder.toString());
322371
}
323372

324373
try
@@ -330,7 +379,6 @@ public void onConfigured( CameraCaptureSession session)
330379
{
331380
try
332381
{
333-
Size size = new Size(width, height);
334382
int fps = cameraCharacteristics.getMaxFramesPerSecond(format, size);
335383

336384
//Indicate how we want to stream

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ As of FTC SDK v8.2, EasyOpenCV is now packaged with the SDK as part of the Visio
4444

4545
## Changelog:
4646

47+
### v1.7.3
48+
- Updates `libjpeg-turbo` to 3.0.3
49+
- Updates OpenCV to v4.10.0
50+
- Show more detail about camera supported resolutions and formats when user requests unsupported configuration
51+
- Show warning if performance could be improved by using MJPEG format
52+
4753
### v1.7.2
4854

4955
- Fix race conditions when handling exception during viewport insertion

0 commit comments

Comments
 (0)