OpenCV C++基于AI模型的场景文本检测(OCR)
2026/7/25 1:06:48 网站建设 项目流程

这个程序使用OpenCV检测场景中的文本。

输入图片:

程序运行后会用绿色的多边形标注出图片里的两行文本:

用到的AI模型是frozen_east_text_detection.pb

代码:

#include <iostream> #include <fstream> #include <opencv2/imgproc.hpp> #include <opencv2/highgui.hpp> int main() { Mat frame = imread("/path/to/text_det_test.png"); TextDetectionModel_EAST model("/path/to/EAST.pb"); float confThreshold = 0.5; float nmsThreshold = 0.4; model.setConfidenceThreshold(confThresh) .setNMSThreshold(nmsThresh); double detScale = 1.0; Size detInputSize = Size(320, 320); Scalar detMean = Scalar(123.68, 116.78, 103.94); bool swapRB = true; model.setInputParams(detScale, detInputSize, detMean, swapRB); std::vector<std::vector<Point>> detResults; model.detect(detResults); polylines(frame, results, true, Scalar(0, 255, 0), 2); imshow("Text Detection", image); waitKey(); }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询