use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestCreateSyntheticOverheadView method checkPrecomputedTransform.
@Test
public void checkPrecomputedTransform() {
// Easier to make up a plane in this direction
Se3_F64 cameraToPlane = new Se3_F64();
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, UtilAngle.degreeToRadian(0), 0, 0, cameraToPlane.getR());
cameraToPlane.getT().set(0, -5, 0);
Se3_F64 planeToCamera = cameraToPlane.invert(null);
CreateSyntheticOverheadView alg = new CreateSyntheticOverheadView() {
@Override
public void process(ImageBase input, ImageBase output) {
}
};
int overheadW = 500;
int overheadH = 600;
double cellSize = 0.05;
double centerX = 1;
double centerY = overheadH * cellSize / 2.0;
alg.configure(param, planeToCamera, centerX, centerY, cellSize, overheadW, overheadH);
// directly below camera, should not be in view
assertTrue(null == alg.getOverheadToPixel(0, 300));
// point at the end of the map should be in view
assertTrue(null != alg.getOverheadToPixel(overheadW - 1, 300));
// check the value at one point by doing the reverse transform
Point2D_F32 found = alg.getOverheadToPixel(400, 320);
CameraPlaneProjection proj = new CameraPlaneProjection();
proj.setPlaneToCamera(planeToCamera, true);
proj.setIntrinsic(param);
Point2D_F64 expected = new Point2D_F64();
proj.pixelToPlane(found.x, found.y, expected);
// put into overhead pixels
expected.x = (expected.x + centerX) / cellSize;
expected.y = (expected.y + centerY) / cellSize;
assertEquals(400, expected.x, 1e-4);
assertEquals(320, expected.y, 1e-4);
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class BatchDownSizeImage method main.
public static void main(String[] args) {
parseArguments(args);
ImageBase input = new GrayU8(1, 1);
ImageBase small = null;
int index = 0;
int numDigits = BoofMiscOps.numDigits(images.size() - 1);
String format = "%" + numDigits + "d";
String format0 = "%0" + numDigits + "d";
for (File f : images) {
BufferedImage orig = UtilImageIO.loadImage(f.getPath());
WritableRaster info = orig.getRaster();
boolean missMatch = false;
if (input.getWidth() != info.getWidth() || input.getHeight() != info.getHeight()) {
missMatch = true;
}
if (info.getNumBands() == 1) {
if (!(input instanceof ImageGray))
missMatch = true;
} else {
if (!(input instanceof Planar)) {
missMatch = true;
} else if (info.getNumBands() != ((Planar) input).getNumBands()) {
missMatch = true;
}
}
if (missMatch) {
// declare the BoofCV image to conver the input into
if (info.getNumBands() == 1) {
input = new GrayU8(info.getWidth(), info.getHeight());
} else {
input = new Planar<>(GrayU8.class, info.getWidth(), info.getHeight(), info.getNumBands());
}
// Now declare storage for the small image
int smallHeight, smallWidth;
if (useSide) {
if (input.getWidth() > input.getHeight()) {
width = side;
height = 0;
} else {
height = side;
width = 0;
}
}
if (height == 0) {
smallWidth = width;
smallHeight = input.getHeight() * width / input.getWidth();
} else if (width == 0) {
smallWidth = input.getWidth() * height / input.getHeight();
smallHeight = height;
} else {
smallWidth = width;
smallHeight = height;
}
small = input.createNew(smallWidth, smallHeight);
}
System.out.printf(" " + format + " out of " + format + " %s\n", index + 1, images.size(), f.getName());
ConvertBufferedImage.convertFrom(orig, input, true);
AverageDownSampleOps.down(input, small);
String nout;
if (rename) {
nout = String.format("image" + format0 + ".png", index);
} else {
nout = f.getName();
nout = nout.substring(0, nout.length() - 3) + "png";
}
File fout = new File(outputDir, nout);
UtilImageIO.saveImage(small, fout.getPath());
index++;
}
System.out.println("Done");
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class CompareIdenticalFunctions method compareResults.
@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
for (int i = 0; i < targetParam.length; i++) {
if (!ImageBase.class.isAssignableFrom(targetParam[i].getClass()))
continue;
ImageBase t = (ImageBase) targetParam[i];
ImageBase v = (ImageBase) validationParam[i];
// todo is this tolerance too big? some operations with a slightly different ordering seem to require it
BoofTesting.assertEqualsRelative(v, t, 1e-4);
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestBlurStorageFilter method median.
@Test
public void median() {
for (ImageType c : imageTypes) {
ImageBase input = c.createImage(width, height);
ImageBase found = c.createImage(width, height);
ImageBase expected = c.createImage(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 100);
BlurStorageFilter alg = new BlurStorageFilter<>("median", c, 2);
GBlurImageOps.median(input, found, 2);
alg.process(input, expected);
BoofTesting.assertEquals(expected, found, 1e-4);
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestBlurStorageFilter method mean.
@Test
public void mean() {
for (ImageType c : imageTypes) {
ImageBase input = c.createImage(width, height);
ImageBase found = c.createImage(width, height);
ImageBase expected = c.createImage(width, height);
ImageBase storage = c.createImage(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 100);
BlurStorageFilter alg = new BlurStorageFilter<>("mean", c, 2);
GBlurImageOps.mean(input, found, 2, storage);
alg.process(input, expected);
BoofTesting.assertEquals(expected, found, 1e-4);
}
}
Aggregations