BoofCV-canny.process()函数花费大量时间

时间:2019-05-29 17:46:31

标签: java android performance image-processing boofcv

我正在使用Android的BoofCV版本0.27,正在检测图像中的矩形。为此,我使用以下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");
    }

这工作得很好,并给了我预期的输出,但是下一行执行最多需要15秒的时间

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

整个功能执行几乎需要20秒。有人可以帮助我进行优化吗?

谢谢。

0 个答案:

没有答案