BoofCV - canny.process() function is taking a lot of time

廉价感情. 提交于 2019-12-24 14:26:24

问题


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:

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

Thanks in Advance.

来源:https://stackoverflow.com/questions/56366012/boofcv-canny-process-function-is-taking-a-lot-of-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!