繁体   English   中英

使用openCV进行序列号检测

[英]Serial Number Detection with openCV

我有一个带有序列号的视频。 就像在图片中一样。 我如何使用openCV检测该顾客的位置。 我唯一需要的是检测此顾客的位置。 这个顾客总是有12个数字,并且会是白色的。

使用形态转换,您可以找到数字的位置。

尝试下面的代码(不是完美的代码,仅用于指导)

#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    Mat src=imread("dnpaP.jpg");
    Mat thresh = src.clone();

    dilate(thresh,thresh,Mat(),Point(-1,-1), 5);
    erode(thresh,thresh,Mat(),Point(-1,-1), 5);
    cvtColor(thresh, thresh, COLOR_BGR2GRAY);
    threshold(thresh, thresh, 200, 255, THRESH_BINARY);
    erode(thresh,thresh,Mat(),Point(-1,-1), 3);
    dilate(thresh,thresh,Mat(),Point(-1,-1), 3);

    vector<vector<Point> > contours;

    findContours(thresh.clone(), contours, RETR_LIST, CHAIN_APPROX_SIMPLE);

    for( size_t i = 0; i< contours.size(); i++ )
    {
        Rect boundingRect_ = boundingRect( contours[i] );
        if(boundingRect_.width > boundingRect_.height * 12)
        rectangle(src,boundingRect_,Scalar(0,0,255),2);
    }
    imshow("thresh",thresh);
    imshow("src",src);
    waitKey();
}

在此处输入图片说明 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM