1

我正在为 Android 使用 BoofCV 0.27 版,我正在检测图像中的矩形。为此,我使用此处给出的以下内容

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 秒。有人可以帮我优化这个吗?

我的要求:

在此处输入图像描述

我需要在移动相机拍摄的图像中检测出这样的矩形。

提前致谢。

4

0 回答 0