Search in sources :

Example 1 with OrientationImageAverage

use of boofcv.alg.feature.orientation.OrientationImageAverage in project BoofCV by lessthanoptimal.

the class ShowFeatureOrientationApp method setActiveAlgorithm.

@Override
public synchronized void setActiveAlgorithm(int indexFamily, String name, Object cookie) {
    if (input == null)
        return;
    RegionOrientation orientation = (RegionOrientation) cookie;
    orientation.setObjectRadius(10);
    T workImage = ConvertBufferedImage.convertFromSingle(input, null, imageType);
    AnyImageDerivative<T, D> deriv = GImageDerivativeOps.derivativeForScaleSpace(imageType, derivType);
    deriv.setInput(workImage);
    int r = 2;
    GeneralFeatureDetector<T, D> detector = FactoryDetectPoint.createHarris(new ConfigGeneralDetector(NUM_FEATURES, r, 1), false, derivType);
    D derivX = null, derivY = null, derivXX = null, derivYY = null, derivXY = null;
    if (detector.getRequiresGradient()) {
        derivX = deriv.getDerivative(true);
        derivY = deriv.getDerivative(false);
    } else if (detector.getRequiresHessian()) {
        derivXX = deriv.getDerivative(true, true);
        derivYY = deriv.getDerivative(false, false);
        derivXY = deriv.getDerivative(true, false);
    }
    detector.process(workImage, derivX, derivY, derivXX, derivYY, derivXY);
    QueueCorner points = detector.getMaximums();
    FancyInterestPointRender render = new FancyInterestPointRender();
    if (orientation instanceof OrientationGradient) {
        ((OrientationGradient<D>) orientation).setImage(deriv.getDerivative(true), deriv.getDerivative(false));
    } else if (orientation instanceof OrientationIntegral) {
        T ii = GIntegralImageOps.transform(workImage, null);
        ((OrientationIntegral<T>) orientation).setImage(ii);
    } else if (orientation instanceof OrientationImageAverage) {
        ((OrientationImageAverage) orientation).setImage(workImage);
    } else {
        throw new IllegalArgumentException("Unknown algorithm type.");
    }
    for (int i = 0; i < points.size; i++) {
        Point2D_I16 p = points.get(i);
        double angle = orientation.compute(p.x, p.y);
        render.addCircle(p.x, p.y, radius, Color.RED, angle);
    }
    BufferedImage temp = new BufferedImage(input.getWidth(), input.getHeight(), input.getType());
    Graphics2D g2 = (Graphics2D) temp.getGraphics();
    g2.drawImage(input, 0, 0, null);
    g2.setStroke(new BasicStroke(2.5f));
    render.draw(g2);
    panel.setImage(temp);
    panel.repaint();
}
Also used : Point2D_I16(georegression.struct.point.Point2D_I16) FancyInterestPointRender(boofcv.gui.feature.FancyInterestPointRender) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) OrientationImageAverage(boofcv.alg.feature.orientation.OrientationImageAverage) FactoryDetectPoint(boofcv.factory.feature.detect.interest.FactoryDetectPoint) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) QueueCorner(boofcv.struct.QueueCorner)

Aggregations

ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)1 OrientationImageAverage (boofcv.alg.feature.orientation.OrientationImageAverage)1 FactoryDetectPoint (boofcv.factory.feature.detect.interest.FactoryDetectPoint)1 FancyInterestPointRender (boofcv.gui.feature.FancyInterestPointRender)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 QueueCorner (boofcv.struct.QueueCorner)1 Point2D_I16 (georegression.struct.point.Point2D_I16)1 BufferedImage (java.awt.image.BufferedImage)1