|
-
May 4th, 2011, 02:48 PM
#1
Thread Starter
Banned
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.
-
May 7th, 2011, 12:29 AM
#2
Re: Vb.net image recognition ( aka higashi no eden ) beta version
Could you please include an example image or something ? 
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
May 7th, 2011, 03:42 AM
#3
Thread Starter
Banned
Re: Vb.net image recognition ( aka higashi no eden ) beta version
-
May 7th, 2011, 11:40 PM
#4
Member
Re: Vb.net image recognition ( aka higashi no eden ) beta version
Considering the issue of accuracy, I'm worried!
Thinking And Saying Java is great because it works on All operating Systems is same as saying Anal is good because it works on all genders - By Arslan
-
May 8th, 2011, 11:42 AM
#5
Thread Starter
Banned
Re: Vb.net image recognition ( aka higashi no eden ) beta version
worried ? what are your concernce ?
also it is clibratable : the jump variable, the black color
-
May 13th, 2011, 02:34 PM
#6
Thread Starter
Banned
Re: Vb.net image recognition ( aka higashi no eden ) beta version
Code:
Imports System.IO
Public Class Form1
Sub RGB_breakerBuster(ByVal inColor As Color, ByRef red As Integer, ByRef green As Integer, ByRef blue As Integer)
' returns value of red,green,blue in a pixel of a bitmap as integers
red = inColor.R
green = inColor.G
blue = inColor.B
End Sub
Public Function getPixelColor(ByVal r As Integer, ByVal g As Integer, ByVal b As Integer) As Char
' r= red, g = green, b = blue
Dim colorchar As Char
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 Integer
PictureBox1.ImageLocation = TextBox2.Text ' image path string
Dim fs As IO.FileStream = New IO.FileStream(TextBox2.Text, IO.FileMode.Open)
Dim image1 As Image = Image.FromStream(fs)
fs.Close()
Dim bm As Bitmap
bm = image1
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
Try
RGB_breakerBuster(bm.GetPixel(index * jump, j * jump), r1, g1, b1)
Catch ex As Exception
MsgBox(index & " " & j)
End Try
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
Last edited by moti barski; May 13th, 2011 at 02:49 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|