Fix large calibration datasets crashes (#1453)

The target list in networktables is limited to 127 items. When you
capture more than 127 calibration images it breaks this limit and errors
out and dies. Do not publish calibration targets to nt. And also move cal images into their own folder
This commit is contained in:
Cameron (3539)
2024-10-13 01:29:17 -04:00
committed by GitHub
parent d9b6199cf0
commit 0766d0e802
10 changed files with 141 additions and 58 deletions

View File

@@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.Optional;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.MatOfInt;
import org.opencv.imgcodecs.Imgcodecs;
@@ -579,11 +580,23 @@ public class RequestHandler {
// encode as jpeg to save even more space. reduces size of a 1280p image from 300k to 25k
var jpegBytes = new MatOfByte();
Imgcodecs.imencode(
".jpg",
calList.observations.get(observationIdx).snapshotData.getAsMat(),
jpegBytes,
new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 60));
Mat img = null;
try {
img =
Imgcodecs.imread(
calList.observations.get(observationIdx).snapshotDataLocation.toString());
} catch (Exception e) {
ctx.status(500);
ctx.result("Unable to read calibration image");
return;
}
if (img == null || img.empty()) {
ctx.status(500);
ctx.result("Unable to read calibration image");
return;
}
Imgcodecs.imencode(".jpg", img, jpegBytes, new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 60));
ctx.result(jpegBytes.toArray());
jpegBytes.release();