Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hey there, i'm stuck on this!
 
I need to crop every letter square out of this picture, and store each letter in an image array of some sort, basically the reason for this is to compare the images to a preset alphabet of these letters to figure out what letter it is (OCR would work better for this, but i can't find a free working OCR class for vb.net).
I am using the System.Drawing Library
I hope someone can help me! Smile | :)
Picture here
 
here is what I had that doesn't work:
Dim grid(4, 4) As Point
    Dim letters() As Image
    Dim boardCoord As New Point(0, 0)
    Dim curLetter As Integer = 0
    Dim b As Image 'The image file provided
    Dim gRec(4, 4) As Rectangle
    Private Sub captureBoard()
        Dim tPoint As Point
        b = PictureBox1.Image
       'Should set the coords of the upper left corner of each square.
        For i As Integer = 0 To 3
            ' down, y
            For ii As Integer = 0 To 3 ' -> |||| x
                tPoint = New Point(boardCoord.X + (25 * ii), boardCoord.Y + (25 * i))
                grid(ii, i) = tPoint
            Next
        Next
 
        'Should save all the rectangles for each of the letters, to easily use when cropping.
        For x As Integer = 1 To 4
            For y As Integer = 1 To 4
                gRec(x, y) = New Rectangle(grid(x, y), New Size(20, 20))
            Next
        Next
        'Should crop each of the 16 total squares, using the preset rectangles
        For i As Integer = 1 To 16
            For x As Integer = 1 To 4
                For y As Integer = 1 To 4
                    Dim j = gRec(x, y)
                    letters(i) = CropLetters(b, j.X, j.Y, j.Size.Width, j.Size.Height)(i)
                Next
            Next
        Next
    End Sub
 

    Private Function CropLetters(ByVal board As Bitmap, ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer) As Image()
        Dim rect As Rectangle = New Rectangle(X, Y, Width, Height) 'the current rectangle to crop
        Dim tBitmaps() As Bitmap 'the holding variable
        For i As Integer = 1 To 16 'cycles through the 16 squares and crops each one
            Dim g As Graphics = Graphics.FromImage(board)
            g.DrawImage(tBitmaps(i), 0, 0, rect, GraphicsUnit.Pixel) 'Should crop the "letter" to the holding var item
        Next
        Return tBitmaps
    End Function
Posted 13-Nov-12 9:37am
Edited 14-Nov-12 19:37pm
v3
Comments
Sergey Alexandrovich Kryukov at 13-Nov-12 18:32pm
   
Would you explain why?! And your picture does not explain much -- letters as letters. Do you want to crop empty space out, or the graphics of the glyph itself?
 
Also, what have you done so far? It does not seem to be a problem.
Also, you need to tag the UI library or graphics library you want to use or are using.
 
But first of all, please explain why. I don't see how it might makes sense. And not many members will volunteer to waste time on something which may net make sense...
 
I removed your last question -- you should not re-post. It cannot help you, but you can get down-voted and abuse reports.
 
--SA
Sergey Alexandrovich Kryukov at 14-Nov-12 22:31pm
   
What's going on? I deleted one more re-post you have recently done. I have to warn you: by systematic re-posting, you risk not just down-voting, but also reports for the abuse, which can go as far as the reports for spamming, if re-posts become too annoying (in my opinion, this is not the case at all, but better be on safe side).
 
Instead, use "Improve question" above, or comment on existing posts...
--SA
TechKidd at 15-Nov-12 0:28am
   
Sorry about the re-post, i didn't notice your comment on here, and i only noticed my posts being deleted for no apparent reason..
Can you possibly delete the "solution" below?
Sergey Alexandrovich Kryukov at 15-Nov-12 0:49am
   
Sorry, I don't think deleting it would be correct treatment of the author of this post...
It does not really hurts you -- just don't accept it formally.
--SA
TechKidd at 15-Nov-12 22:32pm
   
Well, I'm just guessing, but doesn't that mean that my question is no longer under the "unanswered" questions?
Sergey Alexandrovich Kryukov at 15-Nov-12 22:53pm
   
It does not make a big difference, I would say. Number of answers is shown, but having one is not a reason for not giving another answer.
--SA
TechKidd at 17-Nov-12 17:15pm
   
I doubt that anyone is looking to answer questions not listed as "unanswered"..
Sergey Alexandrovich Kryukov at 17-Nov-12 21:16pm
   
It's not even close to the real facts. There is no reason to trust that some answer is correct or comprehensive; that's why many questions have several answers. Having an "answered" mark is not a criterion at all...
--SA
TechKidd at 18-Nov-12 0:37am
   
But, seriously.. no one tries to answer a question that appears to be answered already, even if there's just one answer..
Sergey Alexandrovich Kryukov at 18-Nov-12 10:58am
   
This is because you are looking at much less representative set of cases than I do...
The real problem is that it's not this easy to address you problem.
 
After all, what do you want to achieve? Provide a better description of the problem using "Improve question"; it will pop your post on top of the question queue again...
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To work out what is a letter in an image is largely an OCR task, and not trivial. You didn't include a link to the picture, so the code is largely meaningless. If you want the user to SELECT the letters, then it becomes trivial. You need to create new bitmaps for each letter, there's no better way to store them.
  Permalink  
Comments
TechKidd at 13-Nov-12 16:48pm
   
I know OCR would be A LOT easier, but i haven't found a way to use it without having to spend a lot of money.
I did include a picture..
But thanks for your feedback. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100