2016-06-11 155 views
0

我有一个序列号的视频。就像在图片中。我如何用openCV检测这位顾客的位置。我唯一需要的是检测这位顾客的位置。总是这个赞助人将有12个数字,并将是白色的。使用openCV进行序列号检测

example

+0

不管你做什么都会有区别刻字“卡塔尔航空”其中也有12白色字符。 –

+0

我需要检测图片右上角的12位数字,数字是从0到9. – user3373406

+0

如果文本总是白色并显示在相同的位置,那么您可能不需要使用OpenCV。只需剪切图像的这一部分,将其设为黑色背景上的白色文本,然后使用OCR软件(如tesseract)来识别字符。 –

回答

0

使用Morphological Transformations你可以找到号码的位置。

尝试下面的代码(不是一个完美的代码,它只是一个指令)

#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(); 
} 

enter image description here enter image description here

+0

谢谢,这是非常好的 – user3373406