本技术来源:

3DCaptcha http://www-personal.umich.edu/~mressl/3dcaptcha/

下载地址 http://code.google.com/p/3dcaptcha/

官方LOGO

本例完全由此样例程序翻译而来,未作任何附加处理.

以下是C#对此算法的实现

/** 3DCaptcha for .net* * http://www-personal.umich.edu/~mressl/3dcaptcha/     (php)* http://code.google.com/p/3dcaptcha/                  (php)* * Translate :  Aimeast* Blog      :  http://www.cnblogs.com/Aimeast/*/using System;
using System.Drawing;namespace Captcha
{public static class Captcha{private static double[] addVector(double[] a, double[] b){return new double[] { a[0] + b[0], a[1] + b[1], a[2] + b[2] };}private static double[] scalarProduct(double[] vector, double scalar){return new double[] { vector[0] * scalar, vector[1] * scalar, vector[2] * scalar };}private static double dotProduct(double[] a, double[] b){return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];}private static double norm(double[] vector){return Math.Sqrt(dotProduct(vector, vector));}private static double[] normalize(double[] vector){return scalarProduct(vector, 1.0 / norm(vector));}// http://en.wikipedia.org/wiki/Cross_productprivate static double[] crossProduct(double[] a, double[] b){return new double[] {(a[1] * b[2] - a[2] * b[1]),(a[2] * b[0] - a[0] * b[2]),(a[0] * b[1] - a[1] * b[0])};}private static double[] vectorProductIndexed(double[] v, double[] m, int i){return new double[]{v[i + 0] * m[0] + v[i + 1] * m[4] + v[i + 2] * m[8] + v[i + 3] * m[12],v[i + 0] * m[1] + v[i + 1] * m[5] + v[i + 2] * m[9] + v[i + 3] * m[13],v[i + 0] * m[2] + v[i + 1] * m[6] + v[i + 2] * m[10]+ v[i + 3] * m[14],v[i + 0] * m[3] + v[i + 1] * m[7] + v[i + 2] * m[11]+ v[i + 3] * m[15]};}private static double[] vectorProduct(double[] v, double[] m){return vectorProductIndexed(v, m, 0);}private static double[] matrixProduct(double[] a, double[] b){double[] o1 = vectorProductIndexed(a, b, 0);double[] o2 = vectorProductIndexed(a, b, 4);double[] o3 = vectorProductIndexed(a, b, 8);double[] o4 = vectorProductIndexed(a, b, 12);return new double[]{o1[0], o1[1], o1[2], o1[3],o2[0], o2[1], o2[2], o2[3],o3[0], o3[1], o3[2], o3[3],o4[0], o4[1], o4[2], o4[3]};}// http://graphics.idav.ucdavis.edu/education/GraphicsNotes/Camera-Transform/Camera-Transform.htmlprivate static double[] cameraTransform(double[] C, double[] A){double[] w = normalize(addVector(C, scalarProduct(A, -1)));double[] y = new double[] { 0, 1, 0 };double[] u = normalize(crossProduct(y, w));double[] v = crossProduct(w, u);double[] t = scalarProduct(C, -1);return new double[]{u[0], v[0], w[0], 0,u[1], v[1], w[1], 0,u[2], v[2], w[2], 0,dotProduct(u, t), dotProduct(v, t), dotProduct(w, t), 1};}// http://graphics.idav.ucdavis.edu/education/GraphicsNotes/Viewing-Transformation/Viewing-Transformation.htmlprivate static double[] viewingTransform(double fov, double n, double f){fov *= (Math.PI / 180);double cot = 1.0 / Math.Tan(fov / 2);return new double[]{cot,   0,      0,      0,0,        cot,    0,      0, 0,       0,      (f + n) / (f - n),     -1,0,       0,      2 * f * n / (f - n),    0};}public static Image Generate(string captchaText){Random rnd = new Random();// 3dcha parametersint fontsize = 24;Font font = new Font("Arial", fontsize);SizeF sizeF;using (Graphics g = Graphics.FromImage(new Bitmap(1, 1))){sizeF = g.MeasureString(captchaText, font, 0, StringFormat.GenericDefault);}int image2d_x = (int)sizeF.Width;int image2d_y = (int)(fontsize * 1.3);double bevel = 4;// Create 2d imageBitmap image2d = new Bitmap(image2d_x, image2d_y);Color black = Color.Black;Color white = Color.White;// Paint 2d imageusing (Graphics g = Graphics.FromImage(image2d)){g.Clear(black);g.DrawString(captchaText, font, Brushes.White, 0, 0);}// Calculate projection matrixdouble[] T = cameraTransform(new double[] { rnd.Next(-90, 90), -200, rnd.Next(150, 250) },new double[] { 0, 0, 0 });T = matrixProduct(T,viewingTransform(60, 300, 3000));// Calculate coordinatesdouble[][] coord = new double[image2d_x * image2d_y][];int count = 0;for (int y = 0; y < image2d_y; y += 2){for (int x = 0; x < image2d_x; x++){// calculate x1, y1, x2, y2int xc = x - image2d_x / 2;int zc = y - image2d_y / 2;double yc = -(double)(image2d.GetPixel(x, y).ToArgb() & 0xff) / 256 * bevel;double[] xyz = new double[] { xc, yc, zc, 1 };xyz = vectorProduct(xyz, T);coord[count] = xyz;count++;}}// Create 3d imageint image3d_x = 256;//$image3d_y = $image3d_x / 1.618;int image3d_y = image3d_x * 9 / 16;Bitmap image3d = new Bitmap(image3d_x, image3d_y);Color fgcolor = Color.White;Color bgcolor = Color.Black;using (Graphics g = Graphics.FromImage(image3d)){g.Clear(bgcolor);count = 0;double scale = 1.75 - (double)image2d_x / 400;for (int y = 0; y < image2d_y; y += 2){for (int x = 0; x < image2d_x; x++){if (x > 0){double x0 = coord[count - 1][0] * scale + image3d_x / 2;double y0 = coord[count - 1][1] * scale + image3d_y / 2;double x1 = coord[count][0] * scale + image3d_x / 2;double y1 = coord[count][1] * scale + image3d_y / 2;g.DrawLine(new Pen(fgcolor), (float)x0, (float)y0, (float)x1, (float)y1);}count++;}}}return image3d;}}
}

使用方法

this.BackgroundImage = Captcha.Generate("Code");

效果截图

转载于:https://www.cnblogs.com/Aimeast/archive/2011/05/02/2034525.html

【C#】三维立体验证码 (3DCaptcha)相关推荐

  1. 三维立体图_原来三维立体图片是这样制作的,学会以后自己也可以设计

    最近很多朋友私信问我,三维立体图片是怎么制作的呢?我今天就教教大家三维立体图的设计方法,以后大家也就可以自己设计了. 准备工具 第一:3dmax设计软件和ps软件 第二:三维立体图合成器 首先这是设计 ...

  2. 三维立体动画制作_三维立体动画制作相比传统方式的特点

    三维立体动画制作是利用计算机软件建立起虚拟的环境,设计模型以及场景,再根据需要表现的效果,设定模型的动画参数.运动轨迹和方向等.三维立体动画制作相比传统方式具有众多的特点,艺虎动画做出了以下总结: 三 ...

  3. 三维立体动画制作技巧

    三维动画制作技术要求比较高,掌握技巧才能制作得更加完美,视频工厂为大家分享三维立体动画制作技巧. 一.调查沟通 在三维动画制作之前,要与客户沟通需求.客户的企业文化背景以及客户的产品特色等信息.通过内 ...

  4. 利用PCL库做简单的三维立体图形

    利用PCL库画简单的三维立体图形需要知道各种图形的参数方程,然后给每个参数赋值便可以. 圆柱面的参数方程为:x = R*cos(θ); y = R*sin(θ); z = z;其中 θ范围是[-2*P ...

  5. Visual C++6.0画三维立体图形

    在画三维立体图之前,主要是先要找到二维和三维的对应关系,这是转化的关键. 关键代码如下: S[i].x=P[i][1]+sqrt(2)/3.0*(-P[i][0]);S[i].y=P[i][2]+sq ...

  6. matlab画图三维立体,matlab的三维图形绘制

    1 基本命令 plot3(x,y,z,'s')      %绘制三维曲线 plot3(x1,y1,z1,'s1',x2,y2,z2,'s2',...)   %绘制多条三维曲线 说明:当xyz为同维向量 ...

  7. Matlab画三维立体网状图形(类似魔方)

    第一次用Matlab画这种三维立体的图形,搞了半天发现这个样例图片真的是个坑!发现选择Matlab画这种图真的是大材小用了. 样例图片: Matlab中有很多绘制三维立体图形的函数,搜了很多资料之后发 ...

  8. 最新三维立体画·换个角度看世界

    90年前后第一次在一本杂志上看到三维立体画,感觉很神奇.从另一个角度看世界会发现另一种美,就像对每件事都可以有罗生门的叙述,乐观主义自会发现其阳光一面. 最佳情绪=2/3积极+1/3消极,既不乐观过度 ...

  9. MATLAB 三维立体绘图

    % 三维立体绘图 t = 0:pi/50:10*pi plot3(sin(t),cos(t),t) xlabel('sin(t)') ylabel('cos(t)') zlabel('t') grid ...

最新文章

  1. 极客新闻——07、团队管理方法,让员工做事效率翻倍
  2. 求职面试的十大错误,你犯过吗? | 每日趣闻
  3. MyBatis 架构分层与模块划分-接口层
  4. 参加计算机竞赛需要学什么知识,数学和计算机专业,我应该参加那些比赛?
  5. mysql通过局域网访问数据库_MySQL数据库之局域网内访问同一个mysql数据库
  6. 一种页面数据错误输入提示方法 【转】
  7. arraylist插入数据_集合系列 List(二):ArrayList
  8. Rainbond 5.0正式发布, 支持对接管理已有Kubernetes集群...
  9. 简单的LRU Cache设计与实现
  10. TF2.0—tf.keras.losses.BinaryCrossentropy
  11. Linux 压缩文件 排除指定的目录和 指定的后缀,超实用
  12. HART转PROFIBUS DP(V0)+RS485方法
  13. 基于docker搭开源iredmail邮箱服务器
  14. MacOS查看DNS服务器地址
  15. VS2017 和 Matlab R2016b 混合编程配置问题解决!
  16. 大曝光:淘宝店卖论文,10年卖100多篇SCI获利300万!
  17. js解决动态绑定事件时不能传参的问题
  18. springboot实现邮箱接收验证码
  19. 什么是C端 什么是B端 这里告诉你
  20. 深度学习(Deep Learning)

热门文章

  1. Oracle JDK 和 OpenJDK 有什么区别?
  2. Cookie或将被替换!Chrome工程师提议新型HTTP状态管理协议
  3. SpringBoot应用之消息队列rabbitmq
  4. Redis:redis和memcached 比较
  5. 39.左值、左值引用、右值、右值引用
  6. 青少年蓝桥杯_2020_steam考试_初级组_第三题
  7. 数据结构-简单选择排序(C语言)
  8. spring 学习—spring的相关概念(01)
  9. 无符号 byte java_我们能用Java做无符号字节吗?
  10. mybatisplus or查询_MybatisPlus的各种查询方式