(一)答题表格设计与识别

实际设计好的表格如下图

为了图像精确,表格和四角的标记都是由程序生成的,文字和数据是后期排版软件添加上去的.

图中四角的四个黑方块主要用来定位表格,然后就可以切割出每个单元格,最后去做字符识别.

具体步骤为:

1,灰度化并二值化;

2,查找轮廓,把找出四个定位标记;

3,透视变换,校正变形;

4,切割表格,分别识别每个表格;

实际操作中发现最关键的是表格一定要平整,变形对识别影响较大;

部分代码:

int table_recognition(IplImage* img,unsigned char * result)
{
    //大图二值化
    IplImage* bin_img = cvCloneImage(img);
    image_threshold(bin_img);
    //去噪
    IplImage* tmp_img = cvCloneImage(bin_img);
    cvErode(tmp_img, tmp_img, NULL, ); //腐蚀
    cvDilate(tmp_img, tmp_img, NULL, ); //膨胀
    //查找轮廓
    CvSeq* contours;
    CvMemStorage * storage = cvCreateMemStorage();

    cvSetImageROI(tmp_img, cvRect(, , bin_img->width, bin_img->height));
    cvFindContours(tmp_img, storage, &contours, , ));

    ];
    ];
    ];
    CvPoint points[][];
    ;
    // 检测每个轮廓
    for (; contours; contours = contours->h_next)
    {
        //用指定精度逼近多边形曲线
        CvSeq* result;
        result = cvApproxPoly(contours, );

        //不是四边形的不要
        )
            continue;
        //不是凸多边形不要
        if (!cvCheckContourConvexity(result))
            continue;
        //面积大小或小于指定值的排除
        ));
        )
            continue;

        //解码每个轮廓标志,正确的保存下来**********************************************
        CvPoint2D32f  srcQuad[];
        ; i < ; i++){
            CvPoint* pt = (CvPoint*)cvGetSeqElem(result, i);//取标记四边形的四个顶点
            points[n][i] = *pt;
            srcQuad[i].x = (float)pt->x;
            srcQuad[i].y = (float)pt->y;
        }
        //透视变换取出marker
        IplImage * mark_img = cvCreateImage(cvSize(,), , );
        perspective(bin_img, mark_img, srcQuad);

        //
        int rt = marker_decode(mark_img, &ids[n], &rotates[n], &vals[n]);
        )
            continue;

        //
        n++;
        )
            break;
    }
    )//发现四个标记
        ;
    //if (rotates[0] != rotates[1] || rotates[1] != rotates[2] || rotates[2] != rotates[3])//四个标记旋转一致
    //    return -1;
    //marker 0123
    ] !=  && ids[] !=  && ids[] !=  && ids[] != )
        ;
    ] !=  && ids[] !=  && ids[] !=  && ids[] != )
        ;
    ] !=  && ids[] !=  && ids[] !=  && ids[] != )
        ;
    ] !=  && ids[] !=  && ids[] !=  && ids[] != )
        ;

    //确定表格四个点
    CvPoint2D32f  pts[];
    ; i < ; i++)
    {
        int id = ids[i];
        int rotate = rotates[i];
        CvPoint pt;
        ){
            pt = points[i][( + rotate)%];
        }
        ){
            pt = points[i][( + rotate) % ];
        }
        ){
            pt = points[i][( + rotate) % ];
        }
        ){
            pt = points[i][( + rotate) % ];
        }
        pts[id].x = pt.x;
        pts[id].y = pt.y;
    }

    //CvPoint2D32f tmp_ptf = pts[1];
    //pts[1] = pts[3];
    //pts[3] = tmp_ptf;

    IplImage * table_img = cvCreateImage(cvSize(*, *+), , );
    perspective(img, table_img, pts);

    //表格分割
    ;
    IplImage* gird_img = cvCreateImage(cvSize(, ), , );
    ; j < ; j+=)
    {
        ; i < ; i++)
        {
            cvSetImageROI(table_img, cvRect(+*i, +*j, , ));
            cvCopy(table_img, gird_img);
#ifdef _WIN32
            save_gird(gird_img, nt);
#endif
            int rt = svm_recognition(gird_img);
            result[nt] = rt;
            nt++;
        }
    }

    //cvNamedWindow("Image", CV_WINDOW_NORMAL);
    //cvShowImage("Image", gird_img);
    //cvWaitKey(0);

    cvReleaseImage(&bin_img);
    cvClearMemStorage(storage);

    ;
}

opencv 手写选择题阅卷 (一)表格设计与识别的更多相关文章

  1. opencv 手写选择题阅卷 (二)字符识别

    opencv 手写选择题阅卷 (二)字符识别 选择题基本上只需要识别ABCD和空五个内容,理论上应该识别率比较高的,识别代码参考了网上搜索的代码,因为参考的网址比较多,现在也弄不清是参考何处的代码了, ...

  2. opencv 手写选择题阅卷 (四)Android端 手机应用开发

    opencv 手写选择题阅卷 (四)Android 手机应用开发 在PC端把代码调通以后开始开发Android 手机应用,因为主要功能代码为C++代码,所以需要通过NDK编译,JAVA通过JNI方式调 ...

  3. opencv 手写选择题阅卷 (三)训练分类器

    opencv 手写选择题阅卷 (三)训练分类器 1,分类器选择:SVM 本来一开始用的KNN分类器,但这个分类器目前没有实现保存训练数据的功能,所以选择了SVN分类器; 2,样本图像的预处理和特征提取 ...

  4. OpenCV手写数字字符识别(基于k近邻算法)

    摘要 本程序主要参照论文,<基于OpenCV的脱机手写字符识别技术>实现了,对于手写阿拉伯数字的识别工作.识别工作分为三大步骤:预处理,特征提取,分类识别.预处理过程主要找到图像的ROI部 ...

  5. TF:TF分类问题之MNIST手写50000数据集实现87.4%准确率识别:SGD法+softmax法+cross_entropy法—Jason niu

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # number 1 to 10 ...

  6. AI应用开发实战 - 手写识别应用入门

    AI应用开发实战 - 手写识别应用入门 手写体识别的应用已经非常流行了,如输入法,图片中的文字识别等.但对于大多数开发人员来说,如何实现这样的一个应用,还是会感觉无从下手.本文从简单的MNIST训练出 ...

  7. 背水一战 Windows 10 (62) - 控件(媒体类): InkCanvas 保存和加载, 手写识别

    [源码下载] 背水一战 Windows 10 (62) - 控件(媒体类): InkCanvas 保存和加载, 手写识别 作者:webabcd 介绍背水一战 Windows 10 之 控件(媒体类) ...

  8. 5 TensorFlow入门笔记之RNN实现手写数字识别

    ------------------------------------ 写在开头:此文参照莫烦python教程(墙裂推荐!!!) ---------------------------------- ...

  9. 用tensorflow搭建RNN(LSTM)进行MNIST 手写数字辨识

    用tensorflow搭建RNN(LSTM)进行MNIST 手写数字辨识 循环神经网络RNN相比传统的神经网络在处理序列化数据时更有优势,因为RNN能够将加入上(下)文信息进行考虑.一个简单的RNN如 ...

随机推荐

  1. URAL 1777 D - Anindilyakwa 暴力

    D - AnindilyakwaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  2. C#中如何计算时间差?

    C#中怎么计算两时间相差多少.计算2个时间之间的差,可以计算到时分秒! <1> label1.Text = "2004-1-1 15:36:05"; label2.Te ...

  3. mmc运输问题

    运输问题,有生产和需求平衡,不平衡, 实际模型,没有多大意义,只是变个符号而已. 下面的是平衡的,如果不平衡,约束变一下就可以了.

  4. /proc/sys/net/ipv4/下各项的意义

        /proc/sys/net/ipv4/icmp_timeexceed_rate这个在traceroute时导致著名的“Solaris middle star”.这个文件控制发送ICMP Tim ...

  5. Redis 集合(Set)

      Redis的Set是string类型的无序集合.集合成员是唯一的,这就意味着集合中不能出现重复的数据. Redis 中 集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是O(1). 集合中最 ...

  6. yar

    <?php class Operator { /** * 两数相加 */ public function add($a, $b) { return $this->_add($a, $b); ...

  7. angular 项目回顾

    从学习angular,到实际项目开发不到一周,完全是边写边学呀,都是为了项目,已使用angular 开发了两个项目了,有些技术当时只是会用,都没好好回顾一下,现在有时间回顾一下,项目中用到的一些指令, ...

  8. alfresco 5.0 document

    http://docs.alfresco.com/community/tasks/imagemagick-config.html

  9. Adobe Edge Animate –svg地图交互-精确的边缘及颜色置换

    Adobe Edge Animate –svg地图交互-精确的边缘及颜色置换 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 上一篇我们说到了使用jquer ...

  10. [改善Java代码]不要让类型默默转换

    建议23:不要让类型默默转换 public class Client { // 光速是30万公里/秒,常量 public static final int LIGHT_SPEED = 30 * 100 ...