我在Vb 6.0中实现了水平sobel探测器,但我得到了#34;溢出" (宏)值中的错误,这是我写的sobel函数:
Public Sub HorSobel()
Dim Op_X(-1 To 1, -1 To 1) As Integer, Op_Y(-1 To 1, -1 To 1) As Integer
Dim X As Integer, Y As Integer, i As Integer, J As Integer
'Pic5.Cls
Dim Grand As Double
Grad = 0
Op_X(-1, -1) = -1: Op_X(0, -1) = -2: Op_X(1, -1) = -1
Op_X(-1, 0) = 0: Op_X(0, 0) = 0: Op_X(1, 0) = 0
Op_X(-1, 1) = 1: Op_X(0, 1) = 2: Op_X(1, 1) = 1
For Y = 0 To Pic1.Height - 1
For X = 0 To Pic1.Width - 1
GradX = 0: GradY = 0: Grad = 0
If X = 0 Or Y = 0 Or X = Pic1.Width - 1 Or Y = Pic1.Height - 1 Then
Grad = 0
Else
For i = -1 To 1
For J = -1 To 1
PixelValue = GetPixel(Pic5.hdc, X + i, Y + J)
GradX = GradX + (PixelValue * Op_X(i, J))
Next J
Next i
Grad = Round(Sqr(Abs(GradX * GradX)))
End If
If Grad <= 0 Then Grad = 0: If Grad >= 255 Then Grad = 255
SetPixel Pic6.hdc, X, Y, RGB(Grad, Grad, Grad)
'Pic5.Refresh
Next X
Next Y
Pic6.Refresh
End Sub
答案 0 :(得分:0)
您尚未在所提供的代码中声明以下变量:
如果您将它们声明为Long或Integer,那么这可能是您出现溢出错误的原因。