use of boofcv.alg.feature.detect.edge.EdgeSegment in project BoofCV by lessthanoptimal.
the class VisualizeImageData method drawEdgeContours.
/**
* Draws each contour using a unique color. Each segment of each edge is drawn using the same colors.
*
* @param contours List of edge contours
* @param colors RGB color for each edge
* @param output Where the output is written to
* @param storage Optional working buffer for Bitmap image. Can be null.
*/
public static void drawEdgeContours(List<EdgeContour> contours, int[] colors, Bitmap output, byte[] storage) {
if (output.getConfig() != Bitmap.Config.ARGB_8888)
throw new IllegalArgumentException("Only ARGB_8888 is supported");
if (storage == null)
storage = declareStorage(output, null);
else
Arrays.fill(storage, (byte) 0);
for (int i = 0; i < contours.size(); i++) {
EdgeContour e = contours.get(i);
int c = colors[i];
for (int j = 0; j < e.segments.size(); j++) {
EdgeSegment s = e.segments.get(j);
for (int k = 0; k < s.points.size(); k++) {
Point2D_I32 p = s.points.get(k);
int index = p.y * 4 * output.getWidth() + p.x * 4;
storage[index++] = (byte) (c >> 16);
storage[index++] = (byte) (c >> 8);
storage[index++] = (byte) c;
storage[index] = (byte) 0xFF;
}
}
}
output.copyPixelsFromBuffer(ByteBuffer.wrap(storage));
}
use of boofcv.alg.feature.detect.edge.EdgeSegment in project BoofCV by lessthanoptimal.
the class VisualizeImageData method drawEdgeContours.
/**
* Draws each contour using a single color.
*
* @param contours List of edge contours
* @param color The RGB color that each edge pixel should be drawn
* @param output Where the output is written to
* @param storage Optional working buffer for Bitmap image. Can be null.
*/
public static void drawEdgeContours(List<EdgeContour> contours, int color, Bitmap output, byte[] storage) {
if (output.getConfig() != Bitmap.Config.ARGB_8888)
throw new IllegalArgumentException("Only ARGB_8888 is supported");
if (storage == null)
storage = declareStorage(output, null);
else
Arrays.fill(storage, (byte) 0);
byte r = (byte) ((color >> 16) & 0xFF);
byte g = (byte) ((color >> 8) & 0xFF);
byte b = (byte) (color);
for (int i = 0; i < contours.size(); i++) {
EdgeContour e = contours.get(i);
for (int j = 0; j < e.segments.size(); j++) {
EdgeSegment s = e.segments.get(j);
for (int k = 0; k < s.points.size(); k++) {
Point2D_I32 p = s.points.get(k);
int index = p.y * 4 * output.getWidth() + p.x * 4;
storage[index++] = b;
storage[index++] = g;
storage[index++] = r;
storage[index] = (byte) 0xFF;
}
}
}
output.copyPixelsFromBuffer(ByteBuffer.wrap(storage));
}
use of boofcv.alg.feature.detect.edge.EdgeSegment in project BoofCV by lessthanoptimal.
the class ExampleFitPolygon method fitCannyEdges.
/**
* Fits a sequence of line-segments into a sequence of points found using the Canny edge detector. In this case
* the points are not connected in a loop. The canny detector produces a more complex tree and the fitted
* points can be a bit noisy compared to the others.
*/
public static void fitCannyEdges(GrayF32 input) {
BufferedImage displayImage = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
// Finds edges inside the image
CannyEdge<GrayF32, GrayF32> canny = FactoryEdgeDetectors.canny(2, true, true, GrayF32.class, GrayF32.class);
canny.process(input, 0.1f, 0.3f, null);
List<EdgeContour> contours = canny.getContours();
Graphics2D g2 = displayImage.createGraphics();
g2.setStroke(new BasicStroke(2));
// used to select colors for each line
Random rand = new Random(234);
for (EdgeContour e : contours) {
g2.setColor(new Color(rand.nextInt()));
for (EdgeSegment s : e.segments) {
// fit line segments to the point sequence. Note that loop is false
List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(s.points, false, minSide, cornerPenalty);
VisualizeShapes.drawPolygon(vertexes, false, g2);
}
}
gui.addImage(displayImage, "Canny Trace");
}
use of boofcv.alg.feature.detect.edge.EdgeSegment in project BoofCV by lessthanoptimal.
the class VisualizeBinaryData method renderContours.
public static BufferedImage renderContours(List<EdgeContour> edges, int[] colors, int width, int height, BufferedImage out) {
if (out == null) {
out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
} else {
Graphics2D g2 = out.createGraphics();
g2.setColor(Color.BLACK);
g2.fillRect(0, 0, width, height);
}
colors = checkColors(colors, edges.size());
for (int i = 0; i < edges.size(); i++) {
EdgeContour e = edges.get(i);
int color = colors[i];
for (EdgeSegment s : e.segments) {
for (Point2D_I32 p : s.points) {
out.setRGB(p.x, p.y, color);
}
}
}
return out;
}
Aggregations