Android Question Text to GCode CNC Machine

Discussion in 'Android Questions' started by fernando.oliboni, Jul 27, 2018.

  1. fernando.oliboni

    fernando.oliboni Member Licensed User

    I found a library. Maybe it can help. Can it be used on B4A? Please can anyone tell me if it can be used on the B4A platform?

    I found many libraries, I can provide them if they want. This may help.
    Last edited: Jul 29, 2018
  2. fernando.oliboni

    fernando.oliboni Member Licensed User

    Apparently the platform B4A has no solution to this problem. I'll try Android Studio.
  3. marcick

    marcick Well-Known Member Licensed User

    Instead to be disappointed, maybe you can say thank-you to all people that tried to help you
    Peter Simpson, ilan and Sandman like this.
  4. fernando.oliboni

    fernando.oliboni Member Licensed 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.
  5. JordiCP

    JordiCP Well-Known Member Licensed 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.:)

    Attached Files:

    Peter Simpson, Erel and ilan like this.
  6. ilan

    ilan Expert Licensed User

    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?
    JordiCP likes this.
  7. JordiCP

    JordiCP Well-Known Member Licensed 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 :)
    Peter Simpson, inakigarm and ilan like this.
  8. ilan

    ilan Expert Licensed 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:

    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??
    Peter Simpson likes this.
  9. JordiCP

    JordiCP Well-Known Member Licensed 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.
    Peter Simpson and ilan like this.
  10. Beja

    Beja Expert Licensed 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.
  11. Indic Software

    Indic Software Member Licensed User

    ilan likes this.
  12. fernando.oliboni

    fernando.oliboni Member Licensed User

    Thanks Indic Software, great.
    Can I turn it into C#?
  13. Indic Software

    Indic Software Member Licensed User

    That really depends on your expertise
    Last edited: Aug 4, 2018
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice