Android Question Text to GCode CNC Machine

fernando.oliboni

Active Member
Licensed User
Longtime User
Hi, I need to create an app that transforms texts into GCodes. Example:
upload_2018-7-27_8-22-8.png


Can someone help me?

Thank you
 

fernando.oliboni

Active Member
Licensed User
Longtime User
Yes, I am very grateful for all who have tried to help. I appreciate the effort you have made. But the problem is still alive and I need to find a solution. Thank you all.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Not sure if I'm arriving too late to this thread. :eek:

Anyway, I've been playing a bit using OpenCV and findContours, in order to face the 'first part' of the problem: from a given 'drawn' text, find each one of the N closed paths as lists of coordinates (The string has been drawn on a bitmap and this bitmap processed with OpenCV)

The code doesn't face the second part (conversion from paths to GCode), but it should be the easy part


See attached code.:)
 

Attachments

  • Font2Contours.zip
    8.2 KB · Views: 410
Upvote 0

ilan

Expert
Licensed User
Longtime User
Not sure if I'm arriving too late to this thread. :eek:

Anyway, I've been playing a bit using OpenCV and findContours, in order to face the 'first part' of the problem: from a given 'drawn' text, find each one of the N closed paths as lists of coordinates (The string has been drawn on a bitmap and this bitmap processed with OpenCV)

The code doesn't face the second part (conversion from paths to GCode), but it should be the easy part


See attached code.:)

this looks awesome. can you explain what exactly you are doing?
i mean how are you getting the path of the letters? would it be possible to do it without opencv?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Thanks Ilan,
If you look at the attached code, you'll find that most of it is just UI and preparing things...The 'ProcessImage' (it's really short) is where the magic is.

This is what is done:
  • First we draw a white text (with the chosen font and size) on a black bitmap (<-- this is what findContours needs)
  • Give this bitmap to findcontours. With the appropiate options, it will fill a list with as many independent paths as can be detected on the bitmap.
  • Each one of these paths is 'optimized' so that it contains the minimum number of points but is still exact.
  • You will notice that the inner part of "4" in "B4X" still gives many points, but it is because there is a slight curvature at the corners. If desired, these paths can be further reduced in size, approximating the paths by polygons.
  • So converting it to GCode would obviously need scaling and defining an origin. I guess that the machine would be 'working' between points in a path, and only 'translating' between the last point of a path and the first of the next one.

I'm sure it can be done without OpenCV, doing your own bitmap processing, but what OpenCV gives you is already optimized for these purposes. So if you are asking this in order to use it with B4J, perhaps it would be much better to add OpenCV for Java for the given plattform, and use inline Java to translate just the critical lines (input: bitmap --> output: a list with the paths). I could help you with it if this is the case :)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
thank you, Jordi :)

what i was thinking to do is drawing the letter (in black) on a white background using canvas. then i go through all pixels and with a simple algorithm i am getting all points on the outside of the letter (you can see the result here: https://www.b4x.com/android/forum/threads/text-to-gcode-cnc-machine.95534/page-2#post-603729)

now i have a list with lots of dots. this is a good start but what i need to do is connect all dots to each other in the right way so i am looking for the top/left dot of all dots and this will be my starting dot. now i start looking clockwise if this dot has a neighbor and if yes i add now that dot to a new listarray and do again the search (looking for a neighbor "clockwise") until i reach again the starting dot. like this i create a path of all dots. and now i can reduce the points so if point1 and point 2 and point 3 have the same y value but not the same x value then point 2 can be deleted and i check again for the next point. then i can create a path and also a gcode from that path.

what do you think??
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
what do you think??
I see. It is not a bad approach at all to implement a path follower, specially if you already have it done or nearly done. However, I have some comments
  • If I understood correctly, the points that you get are already ordered (at least for each path) since you are discovering them one after the other by exploring the neighbours, right?
  • You can decrease the list size if 3 or more consecutive points have the same X or same Y, but that won't help for those points in a non-horizontal nor non-vertical line. However, this is not an issue if the final weight (number of points) isn't too large.
  • Does the algorithm work well with different paths? (I mean different letters or letters with more than one path, for instance "A" or "4") --> from your post it seems that yes...

So my opinion is that if you already have the "path detector" working, then it is ok, but if not you can save a lot of work and use the OpenCV code. Its implementation is optimized for speed and accuracy.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
To me, Ilan's answer is closer to the solution..
You will need to write an interpreter (conversion engine) using stringutils, but before that you will need to know the xy bit array of each character.
 
Upvote 0

Indic Software

Active Member
Licensed User
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
I see. It is not a bad approach at all to implement a path follower, specially if you already have it done or nearly done. However, I have some comments
  • If I understood correctly, the points that you get are already ordered (at least for each path) since you are discovering them one after the other by exploring the neighbours, right?
  • You can decrease the list size if 3 or more consecutive points have the same X or same Y, but that won't help for those points in a non-horizontal nor non-vertical line. However, this is not an issue if the final weight (number of points) isn't too large.
  • Does the algorithm work well with different paths? (I mean different letters or letters with more than one path, for instance "A" or "4") --> from your post it seems that yes...

So my opinion is that if you already have the "path detector" working, then it is ok, but if not you can save a lot of work and use the OpenCV code. Its implementation is optimized for speed and accuracy.

Hi Jordi, could you send the library link? Thank you
 
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
[QUOTE = "JordiCP, post: 604115, membro: 33472"]
Não tenho certeza se estou chegando tarde demais para esta discussão. : eek:

De qualquer forma, estou jogando um pouco usando o OpenCV e o findContours, para enfrentar a 'primeira parte' do problema: a partir de um determinado texto 'desenhado', encontre cada um dos N caminhos fechados como listas de coordenadas (A string foi desenhado em um bitmap e esse bitmap processado com OpenCV)

O código não está voltado para a segunda parte (conversão de caminhos para GCode), mas deve ser a parte mais fácil

[MÍDIA = youtube] I63XL7JP10k [/ MÍDIA]

Veja o código em anexo.:)
[/CITAR]


Olá Jordi
1) como fazer para aumentar a precisão ou o número de pontos em cada perfil encontrado?
2) E Possível Controlar a Ordem dos Contornos? Por exemplo, preciso que a letra B seja a primeira, depois o furo mais alto no B e depois o mais baixo e assim por diante.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
This is my take to the "real" question:
CNC, as I guess 90% of us know, stands for "Computerized Numerical Control" machines. These can be things as a Industrial 5-axis multi-tool CNC, to a "simple" XY lazer engraver or plotter.
So, taking as a starting point the simplest XY lazer engraver, the first thing you need to establish is the workplate size and how it will scale in the screen.
Then, its a matter of "mapping" every non white point coordinate. You will also need to establish if your tool moves will be relative to last position or absolute coordinates.
The mapping can be done by converting your workplate into a canvas and sweep it to find the pixels.

This, to me, is the simplest...
And yes, B4A can do anything you wish, as long as YOU, the developer, have the needed skills to do it
 
Last edited:
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
[QUOTE = "OGmac, postagem: 751044, membro: 107192"]
Eu fiz um projeto divertido com o B4J e o OpenCv no passado e compartilharei sua biblioteca em breve.

[MÍDIA = vimeo] 437789714 [/ MÍDIA]
[/CITAR]



Muito bom OGmac, parabéns. Se você puder disponibilizá-lo no B4A, estarei esperando
 
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
[QUOTE = "amidgeha, post: 751056, membro: 41090"]
Não há necessidade de conversão, basta enviar a string e anexar a ela caracteres ASCII # 13 # 10 (CRLF) e enviá-la para sua porta serial
Nota: você deve fazer isso linha por linha
[/CITAR]


Como assim amidgeha?
Tanto quanto eu sei, as máquinas CNC entendem apenas a linguagem do código G para se mover. Explique-nos, por favor.
 
Upvote 0
Top