Results 1 to 6 of 6

Thread: Vb.net image recognition ( aka higashi no eden ) beta version

Threaded View

  1. #1

    Thread Starter
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Vb.net image recognition ( aka higashi no eden ) beta version

    MADE BY MOTI BARSKI (JUST SAYING)

    outer path

    Code:
    'Imports System.Math
    Imports System.IO
    ' for i or j to smaller of h or w
    Public Class Form1
        Sub RGB_breakerBuster(ByVal color As String, ByRef red As String, ByRef green As String, ByRef blue As String)
            red = color.Substring(color.IndexOf("R=") + 2)
            color = red
            red = red.Substring(0, red.IndexOf(","))
            green = color.Substring(color.IndexOf("G=") + 2)
            color = green
            green = green.Substring(0, green.IndexOf(","))
            blue = color.Substring(color.IndexOf("B=") + 2)
            blue = blue.Substring(0, blue.IndexOf("]"))
        End Sub
        Public Function getPixelColor(ByVal red As String, ByVal green As String, ByVal blue As String) As Char
            Dim r, g, b As Integer
            Dim colorchar As Char
            r = red
            g = green
            b = blue
            If r > 245 And g > 245 And b > 245 Then
                colorchar = "w" ' white
            ElseIf r < 20 And g < 20 And b < 20 Then
                colorchar = "k" ' black (kuro in japanese)
            ElseIf r > g And g > b And g < 100 Then
                colorchar = "r" ' red
            ElseIf r > g And g > b And g > 200 Then
                colorchar = "y" ' yellow
            ElseIf r > g And g > b And 100 < g < 200 Then
                colorchar = "o" 'orange
            ElseIf (g > r And r > b) Or (g > b And b > r) Then
                colorchar = "g" 'green
            ElseIf b > g And g > r Then
                colorchar = "b" 'blue
            ElseIf (b > r And r > g) Or (r > b And g < 20) Then
                colorchar = "v" ' violet
            Else
                colorchar = "u" ' yet undefined
            End If
            Return colorchar
        End Function
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox3.Text = ""
            Dim r1, g1, b1 As String
            r1 = "x"
            g1 = "x"
            b1 = "x"
            PictureBox1.ImageLocation = TextBox2.Text ' image path string
            Dim bm As Bitmap
            bm = PictureBox1.Image
            Dim h, w As Integer
            h = bm.Height()
            w = bm.Width()
            Dim jump As Integer
            jump = 35 ' jump ~= sqrt(h*w \ 250), jump < h, jump < w, jump > 1
            Try
                Dim jump2 As Integer
                jump2 = TextBox1.Text
                If jump2 > 1 And jump2 < h And jump2 < w Then
                    jump = jump2
                End If
            Catch ex As Exception
    
            End Try
            Dim recoString As String = "" ' string of image
            Dim prevColor, curColor As Char
            If h > w Then
                h = w
            End If
            Dim xi As Integer
            xi = h \ jump
            For index As Integer = 1 To xi
                recoString &= "_"
                prevColor = "-"
                For j As Integer = 1 To xi
                    RGB_breakerBuster(bm.GetPixel(index * jump, j * jump).ToString(), r1, g1, b1)
                    curColor = getPixelColor(r1, g1, b1)
                    If curColor <> prevColor Then
                        recoString &= curColor
                        prevColor = curColor
                    End If
                Next
            Next
            If recoString.Length > 238 Then
                recoString = recoString.Substring(0, 238)
            End If
            TextBox4.Text = recoString
            If File.Exists("C:\higashiDB\" & recoString & ".txt") Then
                TextBox3.Text = File.ReadAllText("C:\higashiDB\" & recoString & ".txt")
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If TextBox4.Text <> "" Then
                If File.Exists("C:\higashiDB\" & TextBox4.Text & ".txt") Then
                    File.Delete("C:\higashiDB\" & TextBox4.Text & ".txt")
                    'File.Delete("path string")
                End If
                File.WriteAllText("C:\higashiDB\" & TextBox4.Text & ".txt", TextBox3.Text)
            End If
        End Sub
    End Class
    see post #6 for amped source code

    walkthrough for using the program :
    add a higashiDB named folder in c:\
    while running the program :
    type image path (+ image name + image ending ), click the button 2 or 4 times, type description, click save button to save new description for the image.
    TextBox1.Text: jump ~= sqrt(h*w \ 250), jump < h (image height), jump < w (image width), jump > 1, the bigger the more recognition chance and results
    Last edited by moti barski; May 13th, 2011 at 02:34 PM.

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