use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class ExampleTrackerObjectQuad method main.
public static void main(String[] args) {
MediaManager media = DefaultMediaManager.INSTANCE;
String fileName = UtilIO.pathExample("tracking/wildcat_robot.mjpeg");
// Create the tracker. Comment/Uncomment to change the tracker.
TrackerObjectQuad tracker = FactoryTrackerObjectQuad.circulant(null, GrayU8.class);
// FactoryTrackerObjectQuad.sparseFlow(null,GrayU8.class,null);
// FactoryTrackerObjectQuad.tld(null,GrayU8.class);
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(), ImageType.pl(3, GrayU8.class));
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(true),ImageType.pl(3,GrayU8.class));
// Mean-shift likelihood will fail in this video, but is excellent at tracking objects with
// a single unique color. See ExampleTrackerMeanShiftLikelihood
// FactoryTrackerObjectQuad.meanShiftLikelihood(30,5,255, MeanShiftLikelihoodType.HISTOGRAM,ImageType.pl(3,GrayU8.class));
SimpleImageSequence video = media.openVideo(fileName, tracker.getImageType());
// specify the target's initial location and initialize with the first frame
Quadrilateral_F64 location = new Quadrilateral_F64(211.0, 162.0, 326.0, 153.0, 335.0, 258.0, 215.0, 249.0);
ImageBase frame = video.next();
tracker.initialize(frame, location);
// For displaying the results
TrackerObjectQuadPanel gui = new TrackerObjectQuadPanel(null);
gui.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight()));
gui.setImageUI((BufferedImage) video.getGuiImage());
gui.setTarget(location, true);
ShowImages.showWindow(gui, "Tracking Results", true);
// Track the object across each video frame and display the results
long previous = 0;
while (video.hasNext()) {
frame = video.next();
boolean visible = tracker.process(frame, location);
gui.setImageUI((BufferedImage) video.getGuiImage());
gui.setTarget(location, visible);
gui.repaint();
// shoot for a specific frame rate
long time = System.currentTimeMillis();
BoofMiscOps.pause(Math.max(0, 80 - (time - previous)));
previous = time;
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestConvolveJustBorder_General_SB method createInputParam.
@Override
protected Object[][] createInputParam(Method candidate, Method validation) {
Class<?>[] paramTypes = candidate.getParameterTypes();
KernelBase kernel = createKernel(paramTypes[0], kernelWidth, kernelWidth / 2);
ImageBase src = ConvolutionTestHelper.createImage(validation.getParameterTypes()[1], width, height);
GImageMiscOps.fillUniform(src, rand, 0, 5);
ImageBase dst = ConvolutionTestHelper.createImage(validation.getParameterTypes()[2], width, height);
Object[][] ret = new Object[2][paramTypes.length];
// normal symmetric odd kernel
ret[0][0] = kernel;
ret[0][1] = GrayF32.class == src.getClass() ? ImageBorderValue.wrap((GrayF32) src, fillValue) : ImageBorderValue.wrap((GrayI) src, fillValue);
ret[0][2] = dst;
// change the offset
kernel = createKernel(paramTypes[0], kernelWidth, kernelWidth / 2 - 1);
ret[1][0] = kernel;
ret[1][1] = GrayF32.class == src.getClass() ? ImageBorderValue.wrap((GrayF32) src, fillValue) : ImageBorderValue.wrap((GrayI) src, fillValue);
ret[1][2] = ConvolutionTestHelper.createImage(validation.getParameterTypes()[2], width, height);
return ret;
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkRemoveIntrinsic.
/**
* Provide an intrinsic model then remove it
*/
@Test
public void checkRemoveIntrinsic() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
// detect with no intrinsics
FiducialDetector detector = createDetector(type);
detector.detect(image);
assertFalse(detector.is3D());
assertTrue(detector.totalFound() >= 1);
Results expected = extractResults(detector);
checkBounds(detector);
// detect with intrinsics
detector.setLensDistortion(loadDistortion(true), image.width, image.height);
assertTrue(detector.is3D());
assertTrue(detector.totalFound() >= 1);
// detect without intrinsics again
detector.setLensDistortion(null, 0, 0);
assertFalse(detector.is3D());
assertTrue(detector.totalFound() >= 1);
Results found = extractResults(detector);
// compare results
assertEquals(expected.id.length, found.id.length);
for (int i = 0; i < expected.id.length; i++) {
assertEquals(expected.id[i], found.id[i]);
assertTrue(expected.pose.get(i).T.distance(found.pose.get(i).T) <= 1e-4);
assertTrue(MatrixFeatures_DDRM.isIdentical(expected.pose.get(i).getR(), found.pose.get(i).R, 1e-4));
assertTrue(found.pixel.get(i).distance(expected.pixel.get(i)) <= 1e-4);
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method clearLensDistortion.
/**
* Make sure lens distortion is removed if it was set previously and then removed
*/
// TODO remove test? This should be a non-issue now
@Test
public void clearLensDistortion() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
// save the results
detector.setLensDistortion(loadDistortion(false), image.width, image.height);
detector.detect(image);
assertTrue(detector.totalFound() >= 1);
Results before = extractResults(detector);
// run with lens distortion
detector.setLensDistortion(loadDistortion(true), image.width, image.height);
detector.detect(image);
// remove lens distortion
detector.setLensDistortion(loadDistortion(false), image.width, image.height);
detector.detect(image);
Results after = extractResults(detector);
// see if it's the same
for (int i = 0; i < after.id.length; i++) {
assertEquals(before.id[i], after.id[i]);
assertEquals(0, before.pose.get(i).T.distance(after.pose.get(i).T), 1e-8);
assertTrue(MatrixFeatures_DDRM.isIdentical(before.pose.get(i).R, after.pose.get(i).R, 1e-8));
assertEquals(0, before.pixel.get(i).distance(after.pixel.get(i)), 1e-8);
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkImageLocation.
@Test
public void checkImageLocation() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
// It's not specified if the center should be undistorted or distorted. Just make it easier by
// using undistorted
LensDistortionNarrowFOV distortion = loadDistortion(false);
detector.setLensDistortion(distortion, image.width, image.height);
detector.detect(image);
assertTrue(detector.totalFound() >= 1);
assertTrue(detector.is3D());
for (int i = 0; i < detector.totalFound(); i++) {
Se3_F64 fidToCam = new Se3_F64();
Point2D_F64 found = new Point2D_F64();
detector.getFiducialToCamera(i, fidToCam);
detector.getCenter(i, found);
Point2D_F64 rendered = new Point2D_F64();
WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(distortion, fidToCam);
worldToPixel.transform(new Point3D_F64(0, 0, 0), rendered);
// see if the reprojected is near the pixel location
assertTrue(rendered.distance(found) <= pixelAndProjectedTol);
}
}
}
Aggregations