584,800 active members*
4,658 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 23
  1. #1
    Join Date
    May 2005
    Posts
    20

    Photo Silhoutte (Profile) in VB

    I would like to write a VB program that would write GCode to cut a Silhoutte ( I don't know how to spell Silhoutte) from a digital photo. Please don't suggest buying software to do this. I built JGRO's router. SWMBO (for yall who still don't know what that is She Who Must Be Obeyed) does not share nor appreciate my enthusiasm for the CNC router. She says we need new carpet, the bathroom remodeled, and our 30 year old oven replaced. And in fairness to her the router has not done much more than take up space in my already cluttered wood working shop.

    I have some expericnce in VB. I have written extensive applications in MSAccess which uses VBA. I have a program that was free on the internet that does a good job of edge detection and the person who wrote it was good enough to allow public access to the source code. The way the program works is after determining the width in x pixels and the height in y pixel it starts at X1 and moves across the entire photo one x pixel at a time. At each x pixel it moves up the y pixels for the entire height of the photo. If a pixel need to be turned on it does it. I can capture the xy position of those turned on pixels. The big problem is that they are far from cnc order. I have begun to try to figure out an algorythm to compute the logical order for cutting and write the Gcode. I would assume that each pixel is a unit. Of course it would have to be scaled down drastically. It seems that there are seven possible positions (9 minus present and last positions) for the next point. This seems relatively simple but there are times when I have seen gaps when zooming in on the edge detection and I have have seen multiple lines. I can imagine the program hanging up looking for a nonexistant point or going back and forth between multiple lines. I have not really started on this project and very possibly might never. I would just like to hear some ideas from others if you would be willing to share.

  2. #2
    Join Date
    Jul 2005
    Posts
    66
    Hi, this is possible to do by writing a "following" algorithm which walks the edge of the image. Firstly,however, for a digital photo image you need to do image enhancement using and edge detector called a canny edge detector. The canny detector usually gives you a nice 1 pixel edge. After that you can use an algorithm which will simply follow the edge - basically tracing along it. This will put the pixels in the right order automatically. After that you can then also walk thru the points and calculate the angles between each pixel - if the pixel is straight, for example, like the pixel above the current one is straight above, you could optimize the line by just jumping to that location until a pixel "shift" occurs which would indicate the line is changing direction.

    Really you only need basic math to do the more complex stuff, the canny edge detector is the most difficult part to implement, but it is certianly doable even in VB (although it may be a bit slower)

    -niko

  3. #3
    Join Date
    Mar 2004
    Posts
    261

  4. #4
    Join Date
    May 2005
    Posts
    20

    Some Progress

    Thanks for the replys fellows. It looked as if there would be no replys.
    Progress:
    I am working with VB Net 2005.
    I have the form built.
    I can load, crop, and flip/rotate the image.
    I am converting the working image to 8bbpindexed monochrome. (Thanks to Bob Powell's tutorials.)
    Problems:
    I made the image 8 bits per pixel instead of 1 bit per pixel to avoid bit shifting etc. in isolating a pixel.
    I made the image only two colors because I thought this would make edge detection easier. I have not been able to accomplish edge detection. The method I have been trying to use compares the current pixel to the left, right, above and below pixels. If it is different from any of these I set the color black. If all are the same I set the pixel white. This should result in a black outline on a white image. I am using Marshal.ReadByte and Marshal.WriteByte to accomplish this. I always end up with a completly white or a completely black image depending on the I set the conditions. I am stumped at present. I must be making some wrong intrepretations. Maybe I will get a revelation during aone of my daily walks.

  5. #5
    Join Date
    May 2005
    Posts
    20

    Outline Is working

    :cheers:
    Just got my outline working. The procedure I was using was right. I was trying to do too much in one step. The photos I am using are already almost silhouttes. They are profiles of my grandaughter taken in front of an outside window. They are backlighted.
    During this fiasco I have learned quite a bit about image manipulation in VB Net. Now I am about to get whipped by databases.
    I think I will take a walk and then jump into coordinate saving, scaling, sorting,etc etc.

  6. #6
    Join Date
    Mar 2004
    Posts
    1147
    imslo - cool...

    i would be interested in seeing your code, just out of curiosity. i am trying to increase my vb-based killing power... havent moved to .net yet tho... i am afraid of loosing my beloved object arrays!

  7. #7
    Join Date
    Apr 2005
    Posts
    3634
    Check out, "Paint .NET" Open source, written in C# (105,000 lines of code). I know you said VB .NET, maybe you can convert what you need with the last link.

    http://www.eecs.wsu.edu/paint.net/download.html#src (Download Source)

    http://www.eecs.wsu.edu/paint.net/index.html

    http://www.developerfusion.co.uk/uti...sharptovb.aspx (Convert C# to VB.NET)

    .
    Free DXF - vectorink.com

  8. #8
    Join Date
    May 2005
    Posts
    20
    vacpress it's just too primative for anyone to run except me right now. There is a certain operating sequence that must be followed, if the image has too much detail the outline results in garble etc, etc. etc.

    Switcher, thanks for the links but I think I am done with graphics on this project. I can't even think about getting into C# now.

    I have just started looking at SQL at first glance it seems to be a booger. I am very familiar with MSAccess and I thought that might help me with SQL. The only thing that Access is helping with is the understanding of tables, queries and relationships.

    It appears that the difference between Access and SQL is like the difference Windows and DOS.

    My goal is to save the xy coordinates of the pixels in the outline, scale them down to a useable size, sort them in a logical cutting order and write a GCode file.

    I thought this would be easier than the graphic manipulation but right now it seems insurmountable. Maybe it will come around.

  9. #9
    Join Date
    Apr 2005
    Posts
    3634
    Since you have the outline working, why not just write the X & Y Pixel location to a textbox, send that info to a simple text file, name the files in the order you want them to be cut (file1.txt , file2.txt , file3.txt ...) then call all the sub files to create a complete file. :cheers:
    Free DXF - vectorink.com

  10. #10
    Join Date
    May 2005
    Posts
    20
    Switcher, I'm afraid it's going to be too complicated to do what you suggest. There are a couple of big problems. The first is size (height and width). I will treat these pixel coordinates as units (inches). These could be hundreds high and wide. The way I would handle this is decide how high or wide I wanted the finished product, probably an options on a form, then divide this number by the max x or y. I then would have to multiply all x and y's by the result of this division.

    The next is order of the coordinates. The coordinates are generated by starting at y0 x0 scanning in the x direction until max x is reached. When a black pixel is found its location is recorded. The scanning would go to y1 x0 etc until the whole image is scanned. I don't believe the order that comes from scanning will be anywhere close to logical cutting order. I think I must store the coordinates in a place where they can be manipulated before they are exported into a G Code file. Database files are ideal for this type stuff. My problem is that I know nothing about Microsoft SQL database operations and must start at the bottom again. (I had to start at the bottom with VB Net Graphics also to get the outline.) Maybe if I keep digging I will get it. Thanks for the suggestion and interest.

  11. #11
    Join Date
    Apr 2005
    Posts
    3634
    Yeah, I know what your talking about ,as far as the graphics. I just started a program with GDI+ (VB .NET 2003). It's not bad though, once you figure out the basics.
    Free DXF - vectorink.com

  12. #12
    Join Date
    May 2005
    Posts
    20
    Switcher, I couldn't help but notice that you say you are using VB.NET 2003. You probably know that Microsoft is giving away VB.NET 2005 Express, or at least were a few months ago. I don't know if there's much difference in the 2 but I always like to have the latest version of any free software.

  13. #13
    Join Date
    Mar 2003
    Posts
    35538
    Quote Originally Posted by IMSlo
    You probably know that Microsoft is giving away VB.NET 2005 Express, or at least were a few months ago.
    Thanks for the tip.

    http://msdn.microsoft.com/vstudio/express/vb/
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

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

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  14. #14
    Join Date
    Apr 2005
    Posts
    3634
    Anyone, try the upgrade fom "VB.NET 2003" to "VB.NET Express 2005", is it worth it ?

  15. #15
    Join Date
    Apr 2006
    Posts
    402
    If you work with only black and white, it could be done with a boolean array, else with an if needed colorarray (long). PixelIsBlack(MaxXSize, MaxYSize). You give the program a looking direction, first to the right,up and down, depending upon the nearness of the next "True". The nearness of the next point is the root of (FoundaPointX - PointWhereIAmNowX)2 + (FoundAPointY - PointWhereIAmNowY)2. If this is ready you rotate the looking direction 90 degrees. Every touched point becomes "False". An array can be saved to disk. The disadvantage of SQL is that you have to define the software in a restricted language, I think less suitable for this application. An array will be a winner in speed (and debugging)

    Carel

  16. #16
    Join Date
    May 2005
    Posts
    20
    fkaCarel I appreciate your suggestion but honestly I have no inkling of what you are saying.

    At least the thread is getting a little discussion now and that's what I wanted from the start.

    I would like to take a moment to state my goal/dream for this project. I stated in my opening post that my router has not earned its keep. I invision making a smaller more portable router and carrying it to craft shows, malls, etc for the purpose of cutting silhouttes on key chains, small wooden blocks, and even etching in granite. The target market ( I just about made a rhyme) for this would be young unmarried couples drunk on romance who might be willing to pay to have their silhouttes on a keychain that would be constantly with them. Another market might be parents/grandparents of small children. The procedure would be to take a picture with a digital camera, down load it into this program, make a suitable outline, make a G Code file and cut the outline. Of course the customer would be invited to look over my shoulder at the whole process and approve the outline before running G Code. The time limit for the whole process should be under 10 minutes. I keep talking about scaling the coordinates because these items will probably be no higher or wider than 1 1/2". Maybe yall can understand more about what I am up against after this explaination.

    Now back to the task at hand. It probably seems that I am bent on putting these coordinates in a database file. I am for at least two reasons. First I think it must be done in order to perform the vast amount of manipulation required. Secondly it has become a personal challenge. I have said several times that I would never try to learn another computer language. I have dabbled in GWBasic, QuickBasic, Pascal, dBaseIV and V, Clipper, MSAccess VBA, Bentley Microstation VBA, VB6 and now VB.Net. I don't claim to be an expert in any of these and in fact have forgotten most. I am very excited about and challenged by VB.Net. I want to at least scratch the surface of this powerful language.
    Will this program every really be used? Probably not. It's really a dream but even if it is not used I will have the satisfaction of having struggled with it until I conquered it.
    Please excuse my longwindedness.
    BTW I have my database set up but am having problems connecting to it.

  17. #17
    Join Date
    Apr 2005
    Posts
    3634
    IMSlo,

    Do you have "101 VB.NET Samples" yet? I believe they have some database stuff. I havn't went thru all the samples yet, the samples I have looked at, are good.

    Here is a link for the download.

    http://www.microsoft.com/downloads/d...displaylang=en

    If for some reason you can't get the download to work, let me know ,I'll send it to you.






    .

  18. #18
    Join Date
    May 2005
    Posts
    20
    :banana:
    Switcher thanks for the link. I think I may already have those files and just forgotten about them. I have been out on the web looking for code for connecting to a database. I found code for connecting to an Access database. I feel much more comfortable with Access than SQL. I have inserted the code in my form and it works!!!! I have been trying to get something to work for 2 days. I feel much like the proverbial dog that caught the car. What am I gonna do with it?

    The next step is to populate the "Raw Coordinate" table with outline pixel coordinates. It will probably take me two more days to accomplish this.

  19. #19
    Join Date
    Apr 2006
    Posts
    402
    A pity you don't get an inkling. My assumption is that you have created a black and white figure in a picture box. Let's assume the outline are black dots. You want to connect these dots. Print it and connect the dots on paper on the kitchentable and study how you do it. First you work to the right looking for the nearest dots. They can be upwards or downwards. If there are no more dots to connect, you rotate the paper 90 degrees and continue.

    Now back to the computer. I'm looking at this screen in 1024 * 768 resolution. If my screen is black and white every pixel can be read and written in an array of 1024(horizontal) by 768(vertical). If I call White (Not Black) "False" and Black "True" then a variable definition of:

    Private WorkScreen(1024, 768) As Boolean

    is perfectly valid. With this you can calculate the distance between your points, because they represent straight lines and triangles.

    Carel

  20. #20
    Join Date
    Mar 2018
    Posts
    15

    Re: Photo Silhoutte (Profile) in VB

    Quote Originally Posted by IMSlo View Post
    fkaCarel I appreciate your suggestion but honestly I have no inkling of what you are saying.

    At least the thread is getting a little discussion now and that's what I wanted from the start.

    I would like to take a moment to state my goal/dream for this project. I stated in my opening post that my router has not earned its keep. I invision making a smaller more portable router and carrying it to craft shows, malls, etc for the purpose of cutting silhouttes on key chains, small wooden blocks, and even etching in granite. The target market ( I just about made a rhyme) for this would be young unmarried couples drunk on romance who might be willing to pay to have their silhouttes on a keychain that would be constantly with them. Another market might be parents/grandparents of small children. The procedure would be to take a picture with a digital camera, down load it into this program, make a suitable outline, make a G Code file and cut the outline. Of course the customer would be invited to look over my shoulder at the whole process and approve the outline before running G Code. The time limit for the whole process should be under 10 minutes. I keep talking about scaling the coordinates because these items will probably be no higher or wider than 1 1/2". Maybe yall can understand more about what I am up against after this explaination.

    Now back to the task at hand. It probably seems that I am bent on putting these coordinates in a database file. I am for at least two reasons. First I think it must be done in order to perform the vast amount of manipulation required. Secondly it has become a personal challenge. I have said several times that I would never try to learn another computer language. I have dabbled in GWBasic, QuickBasic, Pascal, dBaseIV and V, Clipper, MSAccess VBA, Bentley Microstation VBA, VB6 and now VB.Net. I don't claim to be an expert in any of these and in fact have forgotten most. I am very excited about and challenged by VB.Net. I want to at least scratch the surface of this powerful language.
    Will this program every really be used? Probably not. It's really a dream but even if it is not used I will have the satisfaction of having struggled with it until I conquered it.
    Please excuse my longwindedness.
    BTW I have my database set up but am having problems connecting to it.
    Hi you can share with me your project of Silhouette in VisualBasic language?
    you need help ?

Page 1 of 2 12

Similar Threads

  1. photo for cnc
    By madarocsi in forum Mastercam
    Replies: 0
    Last Post: 03-23-2014, 06:41 PM
  2. CPU ERROR: with photo, help
    By =aike= in forum Okuma
    Replies: 13
    Last Post: 09-14-2012, 04:04 PM
  3. Photo
    By dj_pnevans in forum Australia, New Zealand Club House
    Replies: 1
    Last Post: 08-29-2009, 11:29 AM
  4. My first WIP CNC ...photo...
    By Calico in forum DIY CNC Router Table Machines
    Replies: 3
    Last Post: 08-19-2005, 09:34 AM
  5. A Photo
    By murphy625 in forum CamSoft Products
    Replies: 4
    Last Post: 02-25-2005, 09:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •