验证码识别

caedmon1985 2009-05-12 11:43:10
网上搜索的很多资料都不是我想要的,我想识别http://www.fjjj.gov.cn/Article/getcode.asp这个图片
不知道有人知道验证码识别时怎么做的,希望有人提供这方面的资料,谢谢!!!(网址也行)
-----------
ps:再次推一下我的小站:)bo工具网,大家别拿砖头砸我,哈哈
...全文
616 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
验证码识别 2011-07-16
  • 打赏
  • 举报
回复
专业验证码识别网站
yanzhengmashibie.com
dingwenxin 2010-11-01
  • 打赏
  • 举报
回复
不是很明白,期待高人解答
jmu_xiaocai 2009-05-13
  • 打赏
  • 举报
回复
post的时候又产出新的验证码了-_-```
有没有好的解决方法
caedmon1985 2009-05-12
  • 打赏
  • 举报
回复
楼上理解错了
我不是生成验证码
我是读取验证码
中年秃头大叔 2009-05-12
  • 打赏
  • 举报
回复
RandomCreate.aspx页面:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

public partial class RandomCreate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SetValidateCode();
Response.Cache.SetNoStore();
}
private void SetValidateCode()
{
Bitmap newBitmap = new Bitmap(45,18, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(newBitmap);
Random r = new Random();
g.Clear(Color.White);
for (int i = 0; i < 50; i++)
{
int x1 = r.Next(newBitmap.Width);
int x2 = r.Next(newBitmap.Width);
int y1 = r.Next(newBitmap.Height);
int y2 = r.Next(newBitmap.Height);
g.DrawLine(new Pen(Color.FromArgb(r.Next())), x1, y1, x2, y2);
}
for (int i = 0; i < 100; i++)
{
int x = r.Next(newBitmap.Width);
int y = r.Next(newBitmap.Height);
newBitmap.SetPixel(x, y, Color.FromArgb(r.Next()));
}
string value = GenerateRandom(4);
Session["RandCode"] = value;
Font font = new Font("Arial", 12, FontStyle.Bold);
Random rr = new Random();
int yy = rr.Next(1, 4);
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, 71, 23), Color.Red, Color.Blue, 1.2f, true);
g.DrawString(value, font, brush, 2, yy);
g.DrawRectangle(new Pen(Color.Silver), 0,0, 45, 17);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
newBitmap.Save(ms, ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/gif";
Response.BinaryWrite(ms.ToArray());
}
private static char[] constant ={ '0','1','2','3','4','5','6','7','8','9'
};
public static string GenerateRandom(int Length)
{
System.Text.StringBuilder newRandom = new System.Text.StringBuilder(36);
Random rd = new Random();
for (int i = 0; i < Length; i++)
{
newRandom.Append(constant[rd.Next(10)]);
}
return newRandom.ToString();
}
}


然后在另外一个页面调用:
<img src="RandomCreate.aspx" align="absmiddle" id="randomming" />
CPPACE 2009-05-12
  • 打赏
  • 举报
回复
好像c#画图类中有识别方法
chenyunkun2008 2009-05-12
  • 打赏
  • 举报
回复
好像用image写的一个图片,我在java里做过类似的,

如果要,请联系我


msn chenyunkun1989@hotmail.com
pdsnet 2009-05-12
  • 打赏
  • 举报
回复
第一个不会. 第二个 :网站不错...
柳晛 2009-05-12
  • 打赏
  • 举报
回复
把这个图片的0~9全都裁下来,改成黑白的再单独做成10个不同的图片。
获取验证码时要除色,然后比较。
步慢生错 2009-05-12
  • 打赏
  • 举报
回复
你的小站用户体验没过关啊。首页flash一直放。设个cookie,放一次就行了。
另外仿apple的导航条建议放顶端。
不要一直打开新窗口用self就行了。
另外,flash在opera里有问题。
peng_weida 2009-05-12
  • 打赏
  • 举报
回复
以前接触过,但还是没弄懂,帮顶一下
dugupiaoyun 2009-05-12
  • 打赏
  • 举报
回复
源代码下载地址:
http://download.csdn.net/source/1301978
dugupiaoyun 2009-05-12
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Web.UI.HtmlControls;
using mshtml;
using System.Drawing.Imaging;
namespace ReadImageCode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string url_1 = "http://www.fjjj.gov.cn/chs/jf_main.asp?t=1";
private string url_2 = "http://www.fjjj.gov.cn/article/getcode.asp";


private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate(url_1);
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HTMLDocument doc = (HTMLDocument)this.webBrowser1.Document.DomDocument;
IHTMLControlRange range = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
IHTMLControlElement codeimg = null;
foreach (IHTMLImgElement img in doc.images)
{
if (img.src.ToLower().IndexOf(url_2.ToLower())!=-1)
codeimg = (IHTMLControlElement)img;
}
range.add(codeimg);
range.execCommand("Copy", false, null);
codeimg = null;
range = null;
doc = null;
if (Clipboard.ContainsImage())
{
this.pictureBox1.Image = Clipboard.GetImage();
MemoryStream ns = new MemoryStream();
this.pictureBox1.Image.Save(ns, ImageFormat.Bmp);
Bitmap sourcebm = (Bitmap)(Bitmap.FromStream(ns));
sourcebm=ConvertToGrayscale(sourcebm);
sourcebm = ConvertToMonochrome(sourcebm);
this.pictureBox1.Image = (Image)sourcebm;
string codestr = this.GetCodeString(sourcebm);
this.codeLabel.Text = this.GetCodeNumber(codestr);//数字验证码
//this.textBox1.Text += codestr + System.Environment.NewLine + System.Environment.NewLine;
ns = null;
sourcebm = null;

}
else
{
MessageBox.Show("读取失败");
}
Clipboard.Clear();
}

private Bitmap ConvertToGrayscale(Bitmap sourcebm)
{
//将彩色转换为灰度
for (int x = 0; x < sourcebm.Width; x++)
{
for (int y = 0; y < sourcebm.Height; y++)
{
Color c = sourcebm.GetPixel(x, y);
int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);//转换灰度的算法
sourcebm.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
}
}
return sourcebm;
}
byte critical_value = 238;//灰色背景色

private Bitmap ConvertToMonochrome(Bitmap sourcebm)
{

//去杂色,转换为黑白图片
for (int x = 0; x < sourcebm.Width; x++)
{
for (int y = 0; y < sourcebm.Height; y++)
{
Color c = sourcebm.GetPixel(x, y);
if (c.R == 238)
sourcebm.SetPixel(x, y, Color.FromArgb(255, 255, 255));
else
sourcebm.SetPixel(x, y, Color.FromArgb(0, 0, 0));
}
}
return sourcebm;
}

private string GetCodeString(Bitmap sourcebm)
{
int[] widthStartX = new int[40];//图片宽40像素
int[] widthEndX = new int[40];
bool myColumn = true;
bool charStart = true;
int charNum = 0;
for (int x = 0; x < sourcebm.Width; x++)
{
myColumn = true;
for (int y = 0; y < sourcebm.Height; y++)
{
Color c = sourcebm.GetPixel(x, y);
if (c.R == 0 && charStart == false)//第一次出现黑点
{
widthStartX[charNum] = x;
charStart = true;
break;
}
if (c.R == 0 && charStart == true)//后续出现黑点
{
myColumn = false;
break;
}
}
if (myColumn == true && charStart == true && widthStartX[charNum] < x)//如果当列没有黑点并且前面出现过黑点还没结束
{
widthEndX[charNum] = x - 1;
charStart = false;
charNum++;
}
if (charStart == true && myColumn == false && x == (sourcebm.Width - 1))//如果开始出现黑点了,并且最后一列也有黑点
{
widthEndX[charNum] = x;
charStart = false;
charNum++;
}
}
string str = "";
int sp = 0;
for (int x = 0; x < sourcebm.Width; x++)
{
for (int y = 0; y < sourcebm.Height; y++)
{
sp++;
Color c1 = sourcebm.GetPixel(x, y);
if (c1.R == 0)
str = str + "1";
else
str = str + "0";
if (sp == 100)
{
sp = 0;
str = str + "|";//由此可分析出数字组成部分,即numstr
}
}
}
return str;
}

private string GetCodeNumber(string str)
{
string[] num = str.Split('|');
return GetNum(num[0]) + GetNum(num[1]) + GetNum(num[2]) + GetNum(num[3]);
}

private string GetNum(string str)
{
string ret = "0";
for (int i = 0; i < numstr.Length; i++)
{
if (numstr[i] == str)
{
ret = i.ToString();
break;
}
}
return ret;
}

private string[] numstr = {
"0111111110100000000110000000011000000001100000000101111111100000000000000000000000000000000000000000",//0
"0100000001010000000111111111110000000001000000000100000000000000000000000000000000000000000000000000",//1
"0100000011100000010110000010011000010001100010000101110000010000000000000000000000000000000000000000",//2
"0100000010100000000110001000011000100001100010000101110111100000000000000000000000000000000000000000",//3
"0000011000000010100000110010000100001001111111111100000010010000000000000000000000000000000000000000",//4
"1111100010100010000110001000011000100001100010000110000111100000000000000000000000000000000000000000",//5
"0011111110010001000110001000011000100001100010000100000111100000000000000000000000000000000000000000",//6
"1100000000100000001110000011001000110000101100000011000000000000000000000000000000000000000000000000",//7
"0111011110100010000110001000011000100001100010000101110111100000000000000000000000000000000000000000",//8
"0111100000100001000110000100011000010001100010001001111111000000000000000000000000000000000000000000" //9
};

private void button1_Click(object sender, EventArgs e)
{
string url = url_1;
url = url + "&rnd=" + DateTime.Now.ToString();
this.webBrowser1.Navigate(url);
}
}
}
dugupiaoyun 2009-05-12
  • 打赏
  • 举报
回复
已经帮你解决了,准备结贴吧
jmu_xiaocai 2009-05-12
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20081218/14/61cca1eb-46d4-492f-8006-0a61adf6aebc.html
-------
是不是类似这问题
有人帮忙解释一下吗?
jmu_xiaocai 2009-05-12
  • 打赏
  • 举报
回复
难道post的时候又产出新的验证码了-_-```
楼上的有什么解决方案吗
zgke 2009-05-12
  • 打赏
  • 举报
回复
你的验证码提交多次了把.
jmu_xiaocai 2009-05-12
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 zgke 的回复:]
数字不匹配...???还有这事呢
[/Quote]

我是把识别出来的验证码,post上去,那边的服务器提示验证码错误!
:(
niitnanfeng 2009-05-12
  • 打赏
  • 举报
回复
up
zgke 2009-05-12
  • 打赏
  • 举报
回复
数字不匹配...???还有这事呢
加载更多回复(7)

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧