Home > Net >  Painting stroke generation algorithm for robot arm
Painting stroke generation algorithm for robot arm

Time:07-08

I am writing a code that generate start and end points of strokes of a picture (Raster images) to let robot arm paint.

I have wrote an algorithm but with too many overlapping strokes: enter image description here

and the output (which is mirrored and re-assigned to the colors I have) with 50 ThresholdOfError (you can see the strokes are overlapping): enter image description here

Things to notice are:

*The strokes needs to be none overlapping (if overlapping then have too many strokes)

*Painting have different colors, the same color better draw together

*The stroke size is like rectangles

I am not sure which algorithm should I use, here is some possible ones I have thought about:

Method 1.Generate 50k (or more) random direction and position large size rectangles, if its area overlap the same color area and not overlapping other rectangles, then keep it, then decrease generated rectangle size and after a couple rounds keep decreasing again

Method 2.Extract certain color first then generate random direction and position large size rectangles (we have less area and calculation time)

Method 3.Do edge detection first, then rectangles are generated with direction along the edge, if its area overlap the same color area and not overlapping other rectangles, then keep it, then decrease generated rectangle size and after a couple rounds keep decreasing again

Method 4: Generate random circle, let the pen draw points instead (but may result too many points)

Any suggestions about which algorithm I should use?

CodePudding user response:

Suggest you use the flood fill algorithm.

  • Start at top right pixel.
  • Flood fill that pixel color. ROI

    In case your colors are combinable you can use CMY color space and process each C,M,Y channel separately (max 3 overlapping strokes) to have much better color match.

    If you want much better colors you can also add dithering however that will slow down the painting a lot as it requires much much more path segments and its not optimal for ploter with tool up/down movement (they are better for printing heads or printing triggered without additional movements ...)

    there are a lot of things you can improve/add to this like:

    • remove outline from ROI (to limit the overlaps and prevent details overpaint)
    • do all infills first and then all outlines
    • set infill brush width based on ROI size
    • adjust infill hatching pattern to better match your arm kinematics
    • order ROIs so they painted faster (variation of Traveling Sailsman problem TSP)
    • infill with more than just one brush width to preserve details near borders
  • Related