Option Explicit Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long,ByVal X As Long,ByVal Y As Long) As Long Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long,ByVal Y As Long,ByVal crColor As Long) As Long Function GetRValue&(ByVal rgbColor&) GetRValue = rgbColor And &HFF End Function Function GetGValue&(ByVal rgbColor&) GetGValue = (rgbColor And &HFF00&) / &HFF& End Function Function GetBValue&(ByVal rgbColor&) GetBValue = (rgbColor& And &HFF0000) / &HFF00& End Function Sub ChangePicGray(ByVal SrcDC&,ByVal nx&,ByVal ny&,Optional ByVal nMaskColor& = -1) Dim rgbColor&,Gray& Dim RValue&,GValue&,BValue& Dim dl& rgbColor = GetPixel(SrcDC,nx,ny) '取得一个像素的RGB值 If rgbColor = nMaskColor Then GoTo Release RValue = GetRValue(rgbColor) '获取R值 GValue = GetGValue(rgbColor) '获取G值 BValue = GetBValue(rgbColor) '获取B值 Gray = (9798 * RValue + 19235 * GValue + 3735 * BValue) / 32768 '调整灰度 rgbColor = RGB(Gray,Gray,Gray) Form1.Picture3.PSet (nx,ny),rgbColor '绘制点 Release: rgbColor = 0 Gray = 0 RValue = 0 GValue = 0 BValue = 0 dl = 0 End Sub
在验证码识别上应用较大。
彩色转为灰度度,根据一个阈值,再进行二值化,处理成黑白色。黑白色中根据黑色来判断是什么验证码。
原文链接:https://www.f2er.com/vb/259014.html