OpenCV 文字检测与识别模块

OpenCV 文字检测与识别模块

该模块在扩展模块中,需自行下载
下载地址:https://github.com/opencv/opencv_contrib/tree/4.0.0
说明文档:
文字检测 https://docs.opencv.org/4.0.0/da/d56/group__text__detect.html
文字识别 https://docs.opencv.org/4.0.0/d8/df2/group__text__recognize.html
参考文章:https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/text_recognition_cnn.cpp
https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/webcam_demo.cpp

文字检测

1.textDetectorCNN

OpenCV的文字检测模块textDetectorCNN中使用了TextBoxes:具有单个深度神经网络的快速文本检测器 链接地址为: https://github.com/MhLiao/TextBoxes
其中已经训练过的文件:

函数名 内容 地址
modelWeightsFilename 描述分类器体系结构的prototxt文件的相对或绝对路径。 textbox.prototxt 在下载的扩展模块源码中opencv_contrib/modules/text/samples/textbox.prototxt
modelWeightsFilename 包含caffe-binary形式的模型的预训练权重的文件的相对或绝对路径。 TextBoxes_icdar13.caffemodel http://pan.baidu.com/s/1qY73XHq
        cv::Mat temp;
		src.convertTo(temp, CV_8UC3, 1);//src 输入图像
		cv::imshow("src", temp);
		dst1 = temp.clone();
		cv::Ptr<cv::text::TextDetectorCNN> detector= cv::text::TextDetectorCNN::create("textbox.prototxt", "TextBoxes_icdar13.caffemodel");
		std::vector < cv::Rect > boxes;//识别区域
		std::vector < float > sources;//评估分数
		detector->detect(temp, boxes, sources);
		float threshold = 0.5;
		for (int i = 0; i < boxes.size(); i++)
		{
			if (sources[i] > threshold)
			{
				cv::Rect rect = boxes[i];
				cv::rectangle(dst1, rect, cv::Scalar(255, 0, 0), 2);
			}
		}
		cv::imshow("Text detection result", dst1);

原图
在这里插入图片描述
结果

  • 19
    点赞
  • 217
    收藏
    觉得还不错? 一键收藏
  • 21
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值