CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2009
    Posts
    2

    I need some ideas for an algorithym

    Hi. New member. I'm not trying to learn VB in one day, but I only have one project that I want to make with VB, then probably won't need it for a while.

    What I want to do:
    I have a lot of old books (many with bad, frayed spines) that I really don't want to put on a book scanner where I have to hold the book upside down. I intend to build a bookscanner with my camera (on supports) where I will take *.jpg files. The books will lie in a cradel and I will have to take pictures of all of the left pages, then all of the right pages.

    When pictures are imported into a folder from the SD card, they do seem to be sequentially numbered "xxxxxxxxxx01.jpg", xxxxxxxxx02.jpg" etc. So here's what I want to accomplish:
    I want to import all of the jpg files into a (listfile? combobox? textbox? something else?), then rename them (from xxxxxx01.jpg) to page 1.jpg, page3.jpg, page5.jpg etc. Then I will send them to some software where it will convert the many jpg files to a large pdf file.

    So, do I import them into a listbox, combobox, textbox? Would I use the common dialog box to open the files and import them into the "box"?, would you export them into a different folder? Is renaming files after they've been imported difficult?

    Thanks for any input.

    Steve

  2. #2
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: I need some ideas for an algorithym

    Renaming all the pages in a book seems to be a bit tedious to me. I would suggest that you pull up 2 images, and then ask where the "Middle" is in a text box. You can display the images in 2 picture boxes. And the 2 images would be displayed just for verification. So lets say your book has 10 pages. You would display pages 5 and 6, just so you can see which one you want to stop the first set of renaming. You put 5 in the textbox, then rename image01 through image05 as page1, page3, page 5, page7, page9. Then starting at 6, page 2, page4, page6, page8, page10.

    Lastly, put a TextBox on the screen for the last image number (textbox2).
    To rename the files, I think you can do.

    Name "c:\images\image01.jpg" As "c:\images\page01.jpg"

    You will need 2 loops.
    Code:
       For I = 1 to cint(textbox1.text)
          InFileName = "C:\images\image" + format(I,"00") + ".jpg"
          OutFileName = "C:\images\page" + format((I - 1) * 2 + 1,"00") + ".jpg"
          Name InFileName As OutFileName
       Next I
    Now rename 6-10
    Code:
       Start = CINT(textbox1.text) + 1    ' 5 + 1
       For I = Start to cint(textbox2.text)
          InFileName = "C:\images\image" + format(I,"00") + ".jpg"
          OutFileName = "C:\images\page" + format((I - Start) * 2 + 2,"00") + ".jpg"
          Name InFileName As OutFileName
       Next I
    I Just wrote the code here and have not tested any but I think it should work.

  3. #3
    Join Date
    Apr 2009
    Posts
    394

    Re: I need some ideas for an algorithym

    One problem with renaming the files and then trying to sort them...

    File Page10.jpg will come before Page1.jpg, so it may be advantagous to just leave them numbered as they are already in order or put enough padding zeros in there to keep the files in place/order.

    Second, to be able to read the text in the page before/after conversion to pdf, you will need to take your picture at a very high resolution and this may cause you some space problems on your hard drive.

    Third, converting jpeg's to pdf's saves no space...


    Suggestion: Search for and find one of the many free/trial OCR engines out there and convert from jpeg to text. However, you will need to double check the ocr results to make sure it has done its job properly. Then, when you convert to PDF, you will have a nice small size file to store instead of something that could potentially be gigabytes in size.



    Good Luck

  4. #4
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: I need some ideas for an algorithym

    for the renaming part I recommend total commander. you can enable the renamer with CTRL+M (there are lots of options)
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  5. #5
    Join Date
    Oct 2009
    Posts
    12

    Re: I need some ideas for an algorithym

    dear,

    I hope this is a solution for you. (see attachment)
    How it works:

    Select in the driver list and the folderlist the path of the files to rename.
    Enter the filenames in the flexgrid with the command "Add to list"
    Enter the PREFIX like: "PAGE_" or "BLZ " or ...
    Enter the number of digits you want in the pagenumber like: 5 = 00001, 00002,...
    Enter the number of the first page scanned like: scan001 is page 15 => filename will be "Page_00015.JPG".
    Klick on "Create New Name" to add the new names in the flexgrid.
    Klick on "Rename Files" to rename.

    If you want modifications, please let me know.

    br,
    Attached Files Attached Files

  6. #6
    Join Date
    Oct 2009
    Posts
    12

    Re: I need some ideas for an algorithym

    dear,


    Sorry but I have made a mistake in numbering the pages=
    NOT 1, 2, 3, ... but must be 2, 4, 6 (increment by 2 !)

    I have modified the error = see attachment

    br,
    Attached Files Attached Files

  7. #7
    Join Date
    Dec 2009
    Posts
    2

    Re: I need some ideas for an algorithym

    Thank you all for your suggestions. The sample code you guys made for me took quite a while to write and I appreciate it. I'm not the world's fastest VB user, I play with it when I get home from work, so it will probably be awhile before I email back to let you know what worked. Thanks again for your valuable time.

    Steve

  8. #8
    Join Date
    Oct 2009
    Posts
    12

    Re: I need some ideas for an algorithym

    Dear Steve,

    I have added some features to the program:

    Possibility to save the last settings and added an "increment" field.


    br,
    Attached Files Attached Files

  9. #9
    Join Date
    Dec 2001
    Posts
    6,332

    Re: I need some ideas for an algorithym

    I'd suggest not saving as JPEG, because of the inherent loss of clarity in the format. This is even more important if you'll be using OCR software. PNG files will not only be small (especially since it's presumably mostly black and white), but are lossless. For your particular purposes, even GIF files will be clearer than JPEG. If the scanner software doesn't support saving as PNG or GIF directly, then I'd suggest saving as BMP, and then doing a batch conversion, which many good image editors can do.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

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
  •  





Click Here to Expand Forum to Full Width

Featured