- 之前公司软件版本是在通过调用摄像头再手动圈定仪器数字区域进行识别,现在在此基础上实现自动定位,检测出所有的矩形通过其宽高之比和面积进行筛选,部分关键代码如下
//自动定位数字区域
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
cv::Mat frame,tmp;
void Dectector(Mat frame)
{
Mat gray_image;
cvtColor(frame, gray_image, CV_RGB2GRAY);
//滤波处理
Mat blur_image;
GaussianBlur(gray_image, blur_image, Size(3,3),0,0);
//Canny边缘检测
Mat canny_image;
Canny(blur_image, canny_image, 100, 150, 3);
imshow("Canny",canny_image);
//查找轮廓
Mat contour_image;
contour_image = canny_image.clone();
vector<vector<Point>>contours;