mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +00:00
Show board outliers in calibration info card (#1267)
This commit is contained in:
@@ -32,7 +32,6 @@ import java.util.LinkedList;
|
||||
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.core.Size;
|
||||
@@ -525,7 +524,7 @@ public class RequestHandler {
|
||||
public static void onDataCalibrationImportRequest(Context ctx) {
|
||||
try {
|
||||
DataCalibrationImportRequest request =
|
||||
kObjectMapper.readValue(ctx.body(), DataCalibrationImportRequest.class);
|
||||
kObjectMapper.readValue(ctx.req().getInputStream(), DataCalibrationImportRequest.class);
|
||||
|
||||
var uploadCalibrationEvent =
|
||||
new IncomingWebSocketEvent<>(
|
||||
@@ -1000,6 +999,41 @@ public class RequestHandler {
|
||||
ctx.status(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the calibration JSON for a specific observation. Excludes camera image data
|
||||
*
|
||||
* <p>This is excluded from UICalibrationCoefficients by default to save bandwidth on large
|
||||
* calibrations
|
||||
*/
|
||||
public static void onCalibrationJsonRequest(Context ctx) {
|
||||
String cameraUniqueName = ctx.queryParam("cameraUniqueName");
|
||||
var width = Integer.parseInt(ctx.queryParam("width"));
|
||||
var height = Integer.parseInt(ctx.queryParam("height"));
|
||||
|
||||
var module = VisionSourceManager.getInstance().vmm.getModule(cameraUniqueName);
|
||||
if (module == null) {
|
||||
ctx.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
CameraCalibrationCoefficients calList =
|
||||
module.getStateAsCameraConfig().calibrations.stream()
|
||||
.filter(
|
||||
it ->
|
||||
Math.abs(it.unrotatedImageSize.width - width) < 1e-4
|
||||
&& Math.abs(it.unrotatedImageSize.height - height) < 1e-4)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (calList == null) {
|
||||
ctx.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.json(calList);
|
||||
ctx.status(200);
|
||||
}
|
||||
|
||||
private record CalibrationRemoveRequest(int width, int height, String cameraUniqueName) {}
|
||||
|
||||
public static void onCalibrationRemoveRequest(Context ctx) {
|
||||
@@ -1065,28 +1099,18 @@ public class RequestHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// encode as jpeg to save even more space. reduces size of a 1280p image from
|
||||
// 300k to 25k
|
||||
// encode as jpeg to save even more space. reduces size of a 1280p image from 300k to 25k
|
||||
var mat = calList.observations.get(observationIdx).annotateImage();
|
||||
if (mat == null) {
|
||||
ctx.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
var jpegBytes = new MatOfByte();
|
||||
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));
|
||||
|
||||
Imgcodecs.imencode(".jpg", mat, jpegBytes, new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 60));
|
||||
ctx.result(jpegBytes.toArray());
|
||||
|
||||
mat.release();
|
||||
jpegBytes.release();
|
||||
|
||||
ctx.status(200);
|
||||
|
||||
Reference in New Issue
Block a user