Hello Guest it is June 18, 2019, 09:29:24 PM

Author Topic: transforming a list of x,y coordinates into a curve, then into gcode  (Read 3197 times)

0 Members and 1 Guest are viewing this topic.


Hi folks,

taking a short break from trying to remove backlash, I wanted to turn to something simpler...

I want to do some engraving of of Japanese characters, so I had some written and scanned scanned that. The image had grey zones (folds in the paper), so wrote a small python program to decide if a grey was a black or a white, then removed all the blacks that were not an "edge" of the picture - so I have now the outline of the character - neat.

now I could easily "read" that image and generate a long list of coordinates that need to be drilled - x,y pixels. But this would look bad - the spindle would move at x=0 from y=0 to y=end and drill every black pixel on that line, then do x=1 and y=0 to end and drill the pixels on that line... etc, rather like an old TV. This would look quite bad, especially given the backlash I have

What I need is all these pixels to be joined by a single line (okay, several as the lines don't always intersect in "holes", such as in the letter "O") that can be then drilled as a curve - any ideas of how I could do that?? I am sure there are programs that take a list of coordinates, finds the function that goes throught the points - that is what I need I guess!

If anyone is interested in sending me some picture files to see the output, please feel free! High contrast will give better results - see examples attached

many thanks

Thomas
Really sorry - found the obvious way: transform the picture into a .dxf file using "Img2CAD", then imported that to LazyCam

the offer is still there if someone want to try the "outlining" software
T

Offline Vogavt

*
  •  258 258
    • View Profile
Skip the IMG2CAD and go straight to G-Code with Image to GCode

www.imagetogcode.com/

Offline ger21

*
  • *
  •  6,261 6,261
    • View Profile
    • The CNC Woodworker
Have your python program write the g-code. All g-code is is basically a list of coordinates.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Ger21 - sure, it is easy to get the coordinates out of the images. The problem is, these coordinates are cartesian, and milling that would look like printing with an old matrix printer.
In other words, if you had a picture of a spiral, what would look better: printing it with a matrix printer using the cartesian coordinates, or printing it with a plotter using polar coordinates? Print dots or plot the curve directly?
My small mill has some backlash I can't solve right now (my mechanical understanding/skills are close to zero) so "matrix printing" will look bad and not smooth.

Unless you know a technique to transform these cartesian coordinates into a vector? - which was my original question

Anyway, it looks good on wood now - it is not perfect but I am quite happy with it!

cheers

Thomas

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Hi Thomas

Unless you know a technique to transform these cartesian coordinates into a vector? - which was my original question
Your technique so far has yeilded cartesian coordinates because you've scanned your red image above in a cartesian (raster) manner. In order to produce vectors you need to scan the right hand image in a vector manner. A basic technique for this is to:

1) raster scan from the top left to bottom right until you find a black pixel. we'll call that the "start" pixel and the "focus" pixel. turn it red and store its coordinates.
2) treat that "focus" pixel as being at the centre of a 9 pixel (3x3) square.
3) starting from the pixel to the left, test each pixel around that pixel in a clockwise direction until you get a black pixel. turn it red and store it's coordinates.
4) that pixel becomes the new focus pixel.
5) repeat from 3) until you hit the "start" pixel. (a red pixel).
6) repeat from 1) until you can't find any black pixels.

Optional: Do a test at each found pixel and see how far it is from the previous pixel and only store the coordinates that exceed some distance your happy with. (less points in your vector but less resolution).

This is NOT an optimum search but you can tart it up to taste.

Have fun

Ian

Thanks Ian - very nice. A friend of mine send me a Python program in which he generates Bezier curves between the pixels... this guy is far too smart!

Will have a try at your idea anyway - Python is a nice break from trying to get my mill working!

thanks

Thomas

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Thanks Ian - very nice. A friend of mine send me a Python program in which he generates Bezier curves between the pixels... this guy is far too smart!
Nice.

It could be argued though that he's producing an overly complex vector that then has to be simplified into arc/line primitives (a further stage) for (Mach) gcode as Beziers arn't supported. On the other hand possibly worthwhile as ultimately the arcs should improve the finish over lots of small line segments - depending on how CV is feeling at the time!

Anyway all good fun.

Ian
Re: transforming a list of x,y coordinates into a curve, then into gcode
« Reply #8 on: September 26, 2012, 11:07:29 AM »
I know this topic is kind of old but it relates directly to my question.

I see Bezier curves are not supported.
Does that also include vector spline, etc - ie: vector based curves without a defined center point and consistent radius?

(it is true any arc can be converted to a series of consistent radii, but can be quite a chore)

Seems I've seen Vcarve users produce with Mach3 nonconsistent curves

Any info greatly appreciated
Christian

Offline ger21

*
  • *
  •  6,261 6,261
    • View Profile
    • The CNC Woodworker
Re: transforming a list of x,y coordinates into a curve, then into gcode
« Reply #9 on: September 26, 2012, 11:36:37 AM »
Mach3, and most controls, can only do G2 and G3 moves, which are simple arcs with constant radius.
V-Carve Pro either fits arcs to the splines, or outputs straight segment moves.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html