答题卡识别

 © Fu Xianjun. All Rights Reserved

分别进行预处理,轮廓检测轮廓排序,透视变换寻找圆圈轮廓输出每个轮廓,对比答案

import cv2
import numpy as np
def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
def order_points(pts):
    rect = np.zeros((4,2),dtype = "float32")#初始化同样大小的图像变量
    s = pts.sum(axis=1)#根据y坐标,提取参数
    rect[0] = pts[np.argmin(s)]
    rect[2] = pts[np.argmax(s)]
    d = np.diff(pts,axis=1)
    rect[1] = pts[np.argmin(d)]
    rect[3] = pts[np.argmax(d)]
    return rect
def four_point_transform(img,pts):
    rect = order_points(pts)
    (tl,tr,br,bl) = rect
    widthA = np.sqrt((br[0]-bl[0])**2+(br[1]-bl[1])**2)
    w
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Declare Function GetCursorPos Lib "user32" (lpPoint As pointapi) As Long Private Declare Function CreateDCA& Lib "gdi32" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Type pointapi X As Long Y As Long End Type Private Sub Command1_Click() Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) GetCursorPos p Me.BackColor = GetPixel(a, p.X, p.Y) Command1.Caption = GetPixel(a, p.X, p.Y) DeleteDC a End Sub Private Sub Command2_Click() 'Shell "C:\WINDOWS\Pbrush.exe c:\9.bmp", 1 'SendKeys ("%{f}") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") 'SendKeys ("%a") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") 'SendKeys ("%{F4}") End Sub Private Sub Command3_Click() Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) GetCursorPos p Label3.Caption = GetPixel(a, Text2.Text, Text3.Text) Label4.Caption = GetPixel(a, Text4.Text, Text5.Text) End Sub Private Sub Command4_Click() Form2.Show End Sub Private Sub Command5_Click() Cls For i = 1 To 85 Print ti(i) Next i End Sub Private Sub Command6_Click() Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) GetCursorPos p Public kaohao, haowei(10), kh(10, 10) As Integer Public kemu As String 10: '读取答题卡信息点作标 Dim fileso As New Scripting.FileSystemObject Dim ts As TextStream Set ts = fileso.OpenTextFile("\\teacher\记录$\a卡zuobiao.txt", ForReading, 1) '识别a 卡 X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then GoTo 100 '如果是b卡则专到100执行 '识别科目 X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "综文" X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "数学" X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "外语" X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "理综" '识别10位考号 For i = 0 To 10 For j = 0 To 10 X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then haowei(i) = j Next j Next i For i = 0 To 10 kaohao = kaohao & haowei(i) Next '识别80道判断题 For i = 1 To 80 X = ts.ReadLine Y = ts.ReadLine a(i) = GetPixel(a, X, Y) X = ts.ReadLine Y = ts.ReadLine b(i) = GetPixel(a, X, Y) X = ts.ReadLine Y = ts.ReadLine c(i) = GetPixel(a, X, Y) X = ts.ReadLine Y = ts.ReadLine d(i) = GetPixel(a, X, Y) If ti(i) = a(i) * 1 + b(i) * 2 + c(i) * 4 + d(i) * 8 Then fenshu = fenshu + 1 Next i 100: '识别b卡 Set ts = fileso.OpenTextFile("\\teacher\记录$\b卡zuobiao.txt", ForReading, 1) '识别b卡 X = ts.ReadLine Y = ts.ReadLine 'If GetPixel(a, x, y) = 0 Then GoTo 100 '如果是a卡则专到50执行 '识别科目 X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "综文" X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "数学" X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "外语" X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then kemu = "理综" '识别10位考号 For i = 0 To 10 For j = 0 To 10 X = ts.ReadLine Y = ts.ReadLine If GetPixel(a, X, Y) = 0 Then haowei(i) = j Next j Next i For i = 0 To 10 kaohao = kaohao & haowei(i) Next '识别80道判断题 For i = 1 To 80 X = ts.ReadLine Y = ts.ReadLine a(i) = GetPixel(a, X, Y) X = ts.ReadLine Y = ts.ReadLine b(i) = GetPixel(a, X, Y) X = ts.ReadLine Y = ts.ReadLine c(i) = GetPixel(a, X, Y) X = ts.ReadLine Y = ts.ReadLine d(i) = GetPixel(a, X, Y) If ti(i) = a(i) * 1 + b(i) * 2 + c(i) * 4 + d(i) * 8 Then fenshu = fenshu + 1 Next i Set shuju = zhuce.OpenTextFile("\\teacher\记录$\fenshu.txt", ForAppending, True) shuju.WriteLine xingming shuju.WriteLine xuehao shuju.WriteLine fenshu shuju.WriteLine kemu If fenshu = 0 Then GoTo 500 '如果部分为0则专到结束 shuju.WriteLine "@@@@@@@@@@" GoTo 10 500: MsgBox "识别结束,请查看\\teacher\记录$\fenshu.txt" End Sub Private Sub Command7_Click() Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) 'GetCursorPos p 'Me.BackColor = GetPixel(a, p.X, p.Y) 'Command1.Caption = GetPixel(a, p.X, p.Y) For j = 1 To Int(Text6.Width / 22) For i = 1 To Int(Text6.Height / 22) X = i Y = j m = m + 1 'a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) 'GetCursorPos p If GetPixel(a, X, Y) > 0 Then Print " "; If GetPixel(a, X, Y) = 0 Then Print "a"; Print ""; ';If m > 15 Then Print: m = 0 Next i Print Next j 'Dim a As Long 'Dim p As pointapi 'Me.BackColor = GetPixel(a, p.X, p.Y) 'Command1.Caption = GetPixel(a, p.X, p.Y) Label1.Caption = X Label2.Caption = Y DeleteDC a End Sub Private Sub Command8_Click() End End Sub Private Sub Form_Load() Set Image1 = LoadPicture("c:\9.bmp") 'Shell "C:\WINDOWS\Pbrush.exe c:\9.bmp", 1 End Sub Private Sub Image1_Click() Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) GetCursorPos p Me.BackColor = GetPixel(a, p.X, p.Y) Command1.Caption = GetPixel(a, p.X, p.Y) Label1.Caption = p.X Label2.Caption = p.Y DeleteDC a Dim fileso As New Scripting.FileSystemObject Dim ts As TextStream Set ts = fileso.OpenTextFile("\\teacher\记录$\zuobiao.txt", ForAppending, 1) ts.Write " x:" ts.Write Label1.Caption For i = 0 To 5 - Len(Label1.Caption) ts.Write " " Next i ts.Write " y:" ts.Write Label2.Caption For i = 0 To 5 - Len(Label2.Caption) ts.Write " " Next i ts.WriteLine End Sub Private Sub Text1_DblClick() Cls Text6.Text = Text1.Text End Sub Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) Cls Text6.Text = Text1.Text Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) 'GetCursorPos p 'Me.BackColor = GetPixel(a, p.X, p.Y) 'Command1.Caption = GetPixel(a, p.X, p.Y) jc = Text6.Width / 16 ic = Text6.Height / 16 For j = 1 To Int(Text6.Width / jc) For i = 1 To Int(Text6.Height / ic) X = i Y = j m = m + 1 'a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) 'GetCursorPos p If GetPixel(a, X, Y) > 0 Then Print " "; If GetPixel(a, X, Y) = 0 Then Print "a"; Print ""; ';If m > 15 Then Print: m = 0 Next i Print Next j 'Dim a As Long 'Dim p As pointapi 'Me.BackColor = GetPixel(a, p.X, p.Y) 'Command1.Caption = GetPixel(a, p.X, p.Y) Label1.Caption = X Label2.Caption = Y DeleteDC a End Sub Private Sub Text6_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) GetCursorPos p Me.BackColor = GetPixel(a, p.X, p.Y) Command1.Caption = GetPixel(a, p.X, p.Y) DeleteDC a End Sub Private Sub Text7_Change() Cls End Sub Private Sub Timer1_Timer() Dim a As Long Dim p As pointapi a = CreateDCA("DISPLAY", vbNullString, vbNullString, 0) GetCursorPos p Me.BackColor = GetPixel(a, p.X, p.Y) Command1.Caption = GetPixel(a, p.X, p.Y) Label1.Caption = p.X Label2.Caption = p.Y DeleteDC a 'SendKeys "你好" 'SendKeys "{enter}" ''Shell ("C:\显示桌面.scf") 'Shell "C:\WINDOWS\Pbrush.exe c:\3333.bmp", 1 'SendKeys ("%{F4}") 'SendKeys "a" End Sub Private Sub Timer2_Timer() 'SendKeys ("%{F4}") 'SendKeys ("%{f}") 'Timer2.Interval = 0 'SendKeys "你好" 'SendKeys "{enter}" ''Shell ("C:\显示桌面.scf") 'Shell "C:\WINDOWS\Pbrush.exe c:\3333.bmp", 1 'SendKeys ("%{F4}") 'Shell "C:\WINDOWS\Pbrush.exe c:\3333.bmp", 1 End Sub Private Sub Timer3_Timer() 'SendKeys ("{a}") Timer3.Interval = 0 End Sub Private Sub Timer4_Timer() 'SendKeys ("{tab}") 'SendKeys ("{单}") 'SendKeys ("{tab}") 'SendKeys ("{s}") 'SendKeys ("{y}") 'SendKeys ("{y}") 'SendKeys ("%{F4}") Timer4.Interval = 0 End Sub

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值