Java 如何使用BoofCV变换顶点列表,使它们形成的多边形的中心移动到图像的中间?

Java 如何使用BoofCV变换顶点列表,使它们形成的多边形的中心移动到图像的中间?,java,center,polygon,boofcv,Java,Center,Polygon,Boofcv,我使用下面的代码来检测形状,并为找到的每个形状(存储在列表顶点中)提取顶点列表。如何变换形状的顶点以确保在绘制顶点时形状位于图像的中心 在这里完成>可视化图形.drawPolygon(顶点,真,g2) 是否有一种内置的方法可以使用BoofCV实现,还是必须手动实现 /** * Fits polygons to found contours around binary blobs. */ public static void fitBinaryImage(ImageFloat32 input)

我使用下面的代码来检测形状,并为找到的每个形状(存储在列表顶点中)提取顶点列表。如何变换形状的顶点以确保在绘制顶点时形状位于图像的中心

在这里完成>可视化图形.drawPolygon(顶点,真,g2)

是否有一种内置的方法可以使用BoofCV实现,还是必须手动实现

/**
 * Fits polygons to found contours around binary blobs.
 */
public static void fitBinaryImage(ImageFloat32 input) 
{
    ImageUInt8 binary = new ImageUInt8(input.width,input.height);
    BufferedImage polygon = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB);

    // the mean pixel value is often a reasonable threshold when creating a binary image
    double mean = ImageStatistics.mean(input);

    // create a binary image by thresholding
    ThresholdImageOps.threshold(input, binary, (float) mean, true);

    // reduce noise with some filtering
    ImageUInt8 filtered = BinaryImageOps.erode8(binary, 1, null);
    filtered = BinaryImageOps.dilate8(filtered, 1, null);

    // Find the contour around the shapes
    List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT,null);

    // Fit a polygon to each shape and draw the results
    Graphics2D g2 = polygon.createGraphics();
    g2.setStroke(new BasicStroke(2));

    for( Contour c : contours )
    {
        // Fit the polygon to the found external contour. Note loop = true
        List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(c.external,true,toleranceDist,toleranceAngle,100);
        g2.setColor(Color.RED);
        VisualizeShapes.drawPolygon(vertexes,true,g2);

        // handle internal contours now
        g2.setColor(Color.BLUE);
        for( List<Point2D_I32> internal : c.internal )
        {
            vertexes = ShapeFittingOps.fitPolygon(internal,true,toleranceDist,toleranceAngle,100);
            //********************************************************************************************************************
            //** how can I transform the vertexes here so that the polygon they form is centered at the middle of the image ? ****
            //********************************************************************************************************************
            VisualizeShapes.drawPolygon(vertexes,true,g2);
        }

        System.out.println(vertexes.toString());
        System.out.println(vertexes.size());

    }

    UtilImageIO.saveImage(polygon, "/Users/m/temp/3_fitbinaryimage.png");

}
/**
*将多边形拟合到在二进制斑点周围找到的轮廓。
*/
公共静态void fitBinaryImage(ImageFloat32输入)
{
ImageUInt8 binary=新的ImageUInt8(input.width,input.height);
BuffereImage polygon=新的BuffereImage(输入.宽度,输入.高度,BuffereImage.TYPE_INT_RGB);
//在创建二值图像时,平均像素值通常是一个合理的阈值
双平均值=图像统计。平均值(输入);
//通过阈值化创建二值图像
ThresholdImageOps.阈值(输入,二进制,(浮点)平均值,真);
//通过一些过滤来减少噪音
ImageUInt8 filtered=BinaryImageOps.8(二进制,1,null);
filtered=BinaryImageOps.8(filtered,1,null);
//找到形状周围的轮廓
列表轮廓=BinaryImageOps.contour(过滤,连接规则.8,空);
//将多边形拟合到每个形状并绘制结果
Graphics2D g2=polygon.createGraphics();
g2.设定行程(新基本行程(2));
用于(等高线c:等高线)
{
//将多边形拟合到找到的外部轮廓。注意loop=true
列出顶点=ShapeFittingOps.fitPolygon(c.external,true,toleranceDist,toleranceAngle,100);
g2.设置颜色(颜色为红色);
可视化图形。绘制多边形(顶点,真,g2);
//现在处理内部轮廓
g2.setColor(颜色为蓝色);
对于(内部列表:c.内部)
{
顶点=ShapeFittingOps.fitPolygon(内部、真实、公差距离、公差角度,100);
//********************************************************************************************************************
//**我如何在这里变换顶点,使它们形成的多边形位于图像的中间****
//********************************************************************************************************************
可视化图形。绘制多边形(顶点,真,g2);
}
System.out.println(vertexs.toString());
System.out.println(vertexs.size());
}
保存图像(多边形,“/Users/m/temp/3_fitbinaryimage.png”);
}