1

I am using BoofCV version 0.27 for Android, I am detecting a rectangle in a image. For this, I am using the following as given here

public static void fitCannyBinary( GrayF32 input ) {

        BufferedImage displayImage = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB);
        GrayU8 binary = new GrayU8(input.width,input.height);

        // Finds edges inside the image
        CannyEdge<GrayF32,GrayF32> canny =
                FactoryEdgeDetectors.canny(2, false, true, GrayF32.class, GrayF32.class);

        canny.process(input,0.1f,0.3f,binary);

        // Only external contours are relevant
        List<Contour> contours = BinaryImageOps.contourExternal(binary, ConnectRule.EIGHT);

        Graphics2D g2 = displayImage.createGraphics();
        g2.setStroke(new BasicStroke(2));

        // used to select colors for each line
        Random rand = new Random(234);

        for( Contour c : contours ) {
            List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(c.external,true, minSide,cornerPenalty);

            g2.setColor(new Color(rand.nextInt()));
            VisualizeShapes.drawPolygon(vertexes,true,g2);
        }

        gui.addImage(displayImage, "Canny Contour");
    }

This is working perfectly fine and giving me my expected output but it is taking up to 15 seconds for the following line to execute

canny.process(input,0.1f,0.3f,binary);

And the entire function takes almost 20 seconds to execute. Can someone help me in optimizing this?

My Requirement:

enter image description here

I need to detect a rectangle like this in an image taken by a mobile camera.

Thanks in Advance.

Phenomenal One
  • 2,501
  • 4
  • 19
  • 29

0 Answers0