Как я могу использовать BoofCV для преобразования списка вершин так, чтобы центр многоугольника, который они формируют, был перемещен в середину изображения?
Я использую приведенный ниже код для обнаружения фигур и извлечения списка вершин для каждой найденной фигуры (хранится в списке вершин). Как я могу преобразовать вершины для фигуры, чтобы гарантировать, что фигура будет расположена в центре изображения, когда я рисую вершины?
сделано здесь> VisualizeShapes.drawPolygon(vertexes,true,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");
}