use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class ExampleFisheyeToPinhole method main.
public static void main(String[] args) {
// Path to image data and calibration data
String fisheyePath = UtilIO.pathExample("fisheye/theta/");
// load the fisheye camera parameters
CameraUniversalOmni fisheyeModel = CalibrationIO.load(new File(fisheyePath, "front.yaml"));
// Specify what the pinhole camera should look like
CameraPinhole pinholeModel = new CameraPinhole(400, 400, 0, 300, 300, 600, 600);
// Create the transform from pinhole to fisheye views
LensDistortionNarrowFOV pinholeDistort = new LensDistortionPinhole(pinholeModel);
LensDistortionWideFOV fisheyeDistort = new LensDistortionUniversalOmni(fisheyeModel);
NarrowToWidePtoP_F32 transform = new NarrowToWidePtoP_F32(pinholeDistort, fisheyeDistort);
// Load fisheye RGB image
BufferedImage bufferedFisheye = UtilImageIO.loadImage(fisheyePath, "front_table.jpg");
Planar<GrayU8> fisheyeImage = ConvertBufferedImage.convertFrom(bufferedFisheye, true, ImageType.pl(3, GrayU8.class));
// Create the image distorter which will render the image
InterpolatePixel<Planar<GrayU8>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, fisheyeImage.getImageType());
ImageDistort<Planar<GrayU8>, Planar<GrayU8>> distorter = FactoryDistort.distort(false, interp, fisheyeImage.getImageType());
// Pass in the transform created above
distorter.setModel(new PointToPixelTransform_F32(transform));
// Render the image. The camera will have a rotation of 0 and will thus be looking straight forward
Planar<GrayU8> pinholeImage = fisheyeImage.createNew(pinholeModel.width, pinholeModel.height);
distorter.apply(fisheyeImage, pinholeImage);
BufferedImage bufferedPinhole0 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
// rotate the virtual pinhole camera to the right
transform.setRotationWideToNarrow(ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0.8f, 0, 0, null));
distorter.apply(fisheyeImage, pinholeImage);
BufferedImage bufferedPinhole1 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
// Display the results
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(bufferedPinhole0, "Pinehole Forward");
panel.addImage(bufferedPinhole1, "Pinehole Right");
panel.addImage(bufferedFisheye, "Fisheye");
panel.setPreferredSize(new Dimension(600, 450));
ShowImages.showWindow(panel, "Fisheye to Pinhole", true);
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class ExampleRemoveLensDistortion method displayResults.
/**
* Displays results in a window for easy comparison..
*/
private static void displayResults(BufferedImage orig, Planar<GrayF32> distortedImg, ImageDistort allInside, ImageDistort fullView) {
// render the results
Planar<GrayF32> undistortedImg = new Planar<>(GrayF32.class, distortedImg.getWidth(), distortedImg.getHeight(), distortedImg.getNumBands());
allInside.apply(distortedImg, undistortedImg);
BufferedImage out1 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
fullView.apply(distortedImg, undistortedImg);
BufferedImage out2 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
// display in a single window where the user can easily switch between images
ListDisplayPanel panel = new ListDisplayPanel();
panel.addItem(new ImagePanel(orig), "Original");
panel.addItem(new ImagePanel(out1), "Undistorted All Inside");
panel.addItem(new ImagePanel(out2), "Undistorted Full View");
ShowImages.showWindow(panel, "Removing Lens Distortion", true);
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestSegmentMeanShiftSearchColor method simpleTest.
/**
* Process a random image and do a basic sanity check on the output
*/
@Test
public void simpleTest() {
Planar<GrayF32> image = new Planar<>(GrayF32.class, 20, 25, 2);
GImageMiscOps.fillUniform(image, rand, 0, 256);
SegmentMeanShiftSearchColor<Planar<GrayF32>> alg = new SegmentMeanShiftSearchColor<>(30, 0.05f, interp, 2, 2, 200, false, imageType);
alg.process(image);
FastQueue<Point2D_I32> locations = alg.getModeLocation();
GrowQueue_I32 counts = alg.getRegionMemberCount();
GrayS32 peaks = alg.getPixelToRegion();
FastQueue<float[]> values = alg.getModeColor();
// there should be a fair number of local peaks due to the image being random
assertTrue(locations.size > 20);
// all the lists should be the same size
assertEquals(locations.size, counts.size);
assertEquals(locations.size, values.size);
// total members should equal the number of pixels
int totalMembers = 0;
for (int i = 0; i < counts.size; i++) {
totalMembers += counts.get(i);
}
assertEquals(20 * 25, totalMembers);
// see if the peak to index image is set up correctly and that all the peaks make sense
for (int y = 0; y < peaks.height; y++) {
for (int x = 0; x < peaks.width; x++) {
int peak = peaks.get(x, y);
// can't test the value because its floating point location which is interpolated using the kernel
// and the location is lost
// assertEquals(x+" "+y,computeValue(peakX,peakY,image),value,50);
assertTrue(counts.get(peak) > 0);
}
}
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestVisualDepthOps method depthTo3D_with_rgb.
@Test
public void depthTo3D_with_rgb() {
GrayU16 depth = new GrayU16(width, height);
depth.set(200, 80, 3400);
depth.set(600, 420, 50);
Planar<GrayU8> rgb = new Planar<>(GrayU8.class, width, height, 3);
GImageMiscOps.fillUniform(rgb, rand, 0, 200);
FastQueue<Point3D_F64> pts = new FastQueue<>(Point3D_F64.class, true);
FastQueueArray_I32 color = new FastQueueArray_I32(3);
VisualDepthOps.depthTo3D(param, rgb, depth, pts, color);
assertEquals(2, pts.size());
assertEquals(2, color.size());
assertEquals(0, compute(200, 80, 3400).distance(pts.get(0)), 1e-8);
assertEquals(0, compute(600, 420, 50).distance(pts.get(1)), 1e-8);
color(200, 80, rgb, color.get(0));
color(600, 420, rgb, color.get(1));
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestCreateSyntheticOverheadViewPL method checkRender.
@Test
public void checkRender() {
// 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);
CreateSyntheticOverheadViewPL<GrayF32> alg = new CreateSyntheticOverheadViewPL<>(InterpolationType.BILINEAR, 3, GrayF32.class);
alg.configure(param, planeToCamera, centerX, centerY, cellSize, overheadW, overheadH);
Planar<GrayF32> input = new Planar<>(GrayF32.class, width, height, 3);
for (int i = 0; i < 3; i++) ImageMiscOps.fill(input.getBand(i), 10 + i);
Planar<GrayF32> output = new Planar<>(GrayF32.class, overheadW, overheadH, 3);
alg.process(input, output);
for (int i = 0; i < 3; i++) {
GrayF32 o = output.getBand(i);
// check parts that shouldn't be in view
assertEquals(0, o.get(0, 300), 1e-8);
assertEquals(0, o.get(5, 0), 1e-8);
assertEquals(0, o.get(5, 599), 1e-8);
// check areas that should be in view
assertEquals(10 + i, o.get(499, 300), 1e-8);
}
}
Aggregations