opencv 智能答卷识别系统(一)

目标

这里是2 智能答卷之别系统二

识别答卷答案,识别准号证号码,识别姓名

识别试卷类别

试卷是有标记的,如试卷上方的黑框,
排序结构,使用c++的标准排序算法

struct Ruley {
	bool operator()(const Rect &a1, const Rect &a2) {
		return (a1.y) < (a2.y);
	}
};
```c
 ```c

 void findpos(Mat img)
{
	Mat gray,edge;
	cv::cvtColor(img, gray, COLOR_BGR2GRAY);

	cv::threshold(gray, gray, 200, 255, cv::THRESH_BINARY_INV);
#if 1
	int edgeT = 1;
	Canny(gray, edge, edgeT, 3, 7);
	//cv::HoughLinesP()
	//edge = MyDilate(edge);
#endif

	//gray = MyDilate(gray);
	vector<vector<Point>> contours;
	vector<Vec4i> hierarchy;
	findContours(edge, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_NONE);
	vector<Rect> recs;
	vector<vector<Point>>::iterator It;
	int littleflag = 0;
	for (It = contours.begin(); It < contours.end(); It++) {                        //画出可包围数字的最小矩形

		Rect rect = boundingRect(*It);
		if (rect.area() > 100 && rect.y > 10)
		{
			if ((rect.area() > 2000 && rect.width > 800 && rect.x < img.cols / 5) || (rect.y < 150))
			{
				if (rect.y < 150)
					littleflag++;
				Point2f vertex[4];
				vertex[0] = rect.tl();                                                              //矩阵左上角的点
				vertex[1].x = (float)rect.tl().x, vertex[1].y = (float)rect.br().y;                 //矩阵左下方的点
				vertex[2] = rect.br();                                                              //矩阵右下角的点
				vertex[3].x = (float)rect.br().x, vertex[3].y = (float)rect.tl().y;                 //矩阵右上方的点
				for (int j = 0; j < 4; j++)
					line(img, vertex[j], vertex[(j + 1) % 4], Scalar(0, 0, 255), 1);
				recs.push_back(rect);
			}
		}
	}
	std::sort(recs.begin() , recs.end(), Ruley());
	int r_answer1 = littleflag + 1; //跳过最上面最大的就是答案的地方圆角矩形
	int r_answer2 = littleflag + 2; //被包含的矩形
	Rect &a1 = recs[r_answer1];
	Rect &a2 = recs[r_answer2];
	if (a1.x < a2.x && (a2.y + a2.height)<(a1.y + a1.height) && a1.width > a2.width)
	{
		//cout << "find it";
		//cout << "the rect is :" << a2.x << " " << a2.y << a2.width << a2.height << endl;
	}
	cout << "little flag is " << littleflag << endl;
	cout << "the size is " << recs.size() << endl;
}

答卷识别第一步

调用主函数

int main()
{
	Mat img; //声明一个保存图像的类
	img = imread("D:/opencv/5.tif"); //读取图像,根据图片所在位置填写路径即可
	if (img.empty()) //判断图像文件是否存在
	{
		cout << "请确认图像文件名称是否正确" << endl;
		return -1;
	}
	findpos(img);
	img = GetSmallPic(img);
	imshow("img", img);
	//imshow("edge", edge);
	waitKey(0);
}

识别1 号码 2 答案和多选答案

1 识别号码函数

2 识别答案

比如ABC这种答案,多选识别
未完待续

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qianbo_insist

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值