0

我正在尝试在可变阈值上将图像更改为黑白,以便在 ocr 程序中使用。我的问题是我没有在应该处理的图像中看到任何结果。渲染时我确实经历了一小段等待,所以我假设它实际上正在做某事。

Imports System.Object
Imports System.Drawing.Bitmap

Public Class Form1
    Dim x As Integer, y As Integer
    Dim imgx As Integer, imgy As Integer
    Dim img As Bitmap
    Dim thresh As Bitmap
    Dim pixelColor As Color
    Dim threshcolor As Color
    Dim tempcolor As Color

    Public Function getpixel(ByRef x As Integer, ByRef y As Integer) As Color

    End Function

    Public Sub find_img_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles find_img.Click
        open_img.ShowDialog()
        img_dsp.Text = open_img.FileName()
        img_loc.Text = open_img.FileName
        img_dsp.ImageLocation = img_dsp.Text
    End Sub

    Public Sub find_img_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles find_img.LostFocus
        img = (img_dsp.Image)
        img_dsp.Refresh()
        img_dsp.Text = open_img.FileName()
        img_dsp.ImageLocation = img_dsp.Text
        img = (img_dsp.Image)
        img_dsp.Refresh()
    End Sub

    Public Sub render_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles render.Click
        Dim myx As Integer
        Dim myy As Integer

        img_threshold.Image = img
        thresh = img_threshold.Image

        For myy = 1 To (img.Height - 1)
            For myx = 1 To (img.Width - 1)
                tempcolor = img.GetPixel(myx, myy)

                If tempcolor.GetBrightness < NumericUpDown1.Value Then
                    thresh.SetPixel(x, y, Color.Black)
                End If

                If tempcolor.GetBrightness > NumericUpDown1.Value Then
                    thresh.SetPixel(x, y, Color.White)
                End If
            Next myx
        Next myy

        img_threshold.Image = thresh
        img_threshold.Refresh()
    End Sub
End Class    
4

1 回答 1

0

你知道什么是参考吗?写A = B,改变A,写B = A?如果你指定 A 和 B 指向同一个对象(对同一个对象的引用),改变一个也会改变另一个,它们在内存中占用相同的存储空间!请在编写程序之前自学基础知识。

于 2011-09-11T18:37:05.770 回答