简体   繁体   English

OpenCv:车牌识别

[英]OpenCv: License Plate Recognition

I have been working on License Plate Recognition based on github repository https://github.com/MicrocontrollersAndMore/OpenCV_3_License_Plate_Recognition_Cpp 我一直致力于基于github存储库的车牌识别https://github.com/MicrocontrollersAndMore/OpenCV_3_License_Plate_Recognition_Cpp

but I need to detect small characters. 但我需要检测小字符。 but I can't figure it out. 但我无法弄清楚。 I think I need to change on the size checking but I can't figure it out. 我想我需要改变尺寸检查,但我无法弄明白。

https://github.com/MicrocontrollersAndMore/OpenCV_3_License_Plate_Recognition_Cpp/blob/master/DetectChars.cpp https://github.com/MicrocontrollersAndMore/OpenCV_3_License_Plate_Recognition_Cpp/blob/master/DetectChars.cpp

bool checkIfPossibleChar(PossibleChar &possibleChar) {
        // this function is a 'first pass' that does a rough check on a contour to see if it could be a char,
        // note that we are not (yet) comparing the char to other chars to look for a group
if (possibleChar.boundingRect.area() > MIN_PIXEL_AREA &&
possibleChar.boundingRect.width > MIN_PIXEL_WIDTH && possibleChar.boundingRect.height > MIN_PIXEL_HEIGHT &&
    MIN_ASPECT_RATIO < possibleChar.dblAspectRatio && possibleChar.dblAspectRatio < MAX_ASPECT_RATIO) {
    return(true);
} else {
    return(false);
}}

AND

    double dblDistanceBetweenChars = distanceBetweenChars(possibleChar,     possibleMatchingChar);
    double dblAngleBetweenChars = angleBetweenChars(possibleChar, possibleMatchingChar);
    double dblChangeInArea = (double)abs(possibleMatchingChar.boundingRect.area() - possibleChar.boundingRect.area()) / (double)possibleChar.boundingRect.area();
    double dblChangeInWidth = (double)abs(possibleMatchingChar.boundingRect.width - possibleChar.boundingRect.width) / (double)possibleChar.boundingRect.width;
    double dblChangeInHeight = (double)abs(possibleMatchingChar.boundingRect.height - possibleChar.boundingRect.height) / (double)possibleChar.boundingRect.height;

            // check if chars match
    if (dblDistanceBetweenChars < (possibleChar.dblDiagonalSize * MAX_DIAG_SIZE_MULTIPLE_AWAY) &&
        dblAngleBetweenChars < MAX_ANGLE_BETWEEN_CHARS &&
        dblChangeInArea < MAX_CHANGE_IN_AREA &&
        dblChangeInWidth < MAX_CHANGE_IN_WIDTH &&
        dblChangeInHeight < MAX_CHANGE_IN_HEIGHT) {
        vectorOfMatchingChars.push_back(possibleMatchingChar);      // if the chars are a match, add the current char to vector of matching chars
    }

Thanks a lot in Advance. 非常感谢提前。

You should first debug to see at which conditions the two A, A fails. 您应该首先调试以查看两个A,A失败的条件。

  1. The MIN_PIXEL_AREA, MIN_PIXEL_WIDTH & MIN_PIXEL_HEIGHT may not be able to accomodate the small size A. MIN_PIXEL_AREA,MIN_PIXEL_WIDTH和MIN_PIXEL_HEIGHT可能无法容纳小尺寸A.

  2. In second code snippet you provided, change the syntax of if statement from if(condition1 && cond2 &&...) to syntax if(condition1) {if(codition2) {....}} . 在您提供的第二个代码段中,将if语句的语法从if(condition1 && cond2 &&...)更改为语法if(condition1) {if(codition2) {....}} This will tell you where these condition fails. 这将告诉您这些条件失败的地方。

  3. Finally, in second snippet, a lot of conditions to check if the bounding rect is a character depends a lot on what kind of character is seen in past. 最后,在第二个片段中,检查边界矩形是否为字符的很多条件在很大程度上取决于过去看到的字符类型。 Since in your case, the character AA differs in size, distance and direction(vertical) as well. 因为在你的情况下,角色AA的大小,距离和方向(垂直)也不同。 Thus it would be better to reinitialize for AA instead of using previous characters, or some more conditions should be added for validating characters.[Like if both height and width decreased] 因此,最好重新初始化AA而不是使用以前的字符,或者应该添加一些更多的条件来验证字符。[如果高度和宽度都减少了]

Once you know which conditions fails in step 2 and why, making relevant changes of step 3 should be simple. 一旦知道步骤2中哪些条件失败以及为什么,对步骤3进行相关更改应该很简单。


Edit: I looked further through the repo, and checked function findVectorOfVectorsOfMatchingChars and findVectorOfMatchingChars. 编辑:我进一步查看了repo,并检查了函数findVectorOfVectorsOfMatchingChars和findVectorOfMatchingChars。

Analysis of findVectorOfMatchingChars function: This function takes a possibleChar and checks if this char is close(when all if condition passes) match with any of the possibleChar of vectorOfChars. findVectorOfMatchingChars函数的分析:该函数接受一个possibleChar并检查此char是否接近(如果条件通过的所有条件)与vectorOfChars的任何可能的char匹配。 If there is a match, store all matches together and return the results 如果匹配,则将所有匹配项存储在一起并返回结果

Analysis of findVectorOfVectorsOfMatchingChars function: This function picks any possibleChar from vectorOfPossibleChars and finds all it matches using findVectorOfMatchingChars. findVectorOfVectorsOfMatchingChars函数的分析:该函数从vectorOfPossibleChars中选取任何可能的char,并使用findVectorOfMatchingChars查找所有匹配的。 If a good match is found, this function calls itself using (vectorOfPossibleChars - matchedPossibleChars). 如果找到了良好的匹配,则此函数使用(vectorOfPossibleChars - matchedPossibleChars)调用自身。

Now, here is the problem. 现在,这是问题所在。

Lets say each possibleChar is a vertex of the graph G and there is an edge between two possibleChar iff they satisfy the condition defined in findVectorOfMatchingChars function. 让我们说每个possibleChar是图G的顶点,并且如果它们满足findVectorOfMatchingChars函数中定义的条件,则在两个possibleChar之间存在边。

Now, lets say we have a graph with A,B,C,D,X as possibleChar vertex with X close enough to A,B,C,D but A,B,C,D are just far enough of each other to not be considered a close match. 现在,假设我们有一个A,B,C,D,X作为可能的图形,其中X与E,B,C,D足够接近但是A,B,C,D的距离足够远被认为是一场紧密的比赛。

Now let's apply findVectorOfVectorsOfMatchingChars on this vector of possibleChars. 现在让我们在这个possibleChars向量上应用findVectorOfVectorsOfMatchingChars。

Option 1 : If we choose X first, we find A,B,C,D as its matching possibleChar and thus we get all possibleChar. 选项1 :如果我们首先选择X,我们发现A,B,C,D作为匹配的possibleChar,因此我们得到所有可能的Char。

Option 2 : If we choose A first, we find X to be matching possibleChar of A, but not B,C,D. 选项2 :如果我们首先选择A,我们发现X匹配A的possibleChar,但不匹配B,C,D。 Thus we remove A,X from vectorOfPossibleChars and reapply findVectorOfVectorsOfMatchingChars on B,C,D. 因此,我们从vectorOfPossibleChars中删除A,X并在B,C,D上重新应用findVectorOfVectorsOfMatchingChars。 Now, since there is no match between B,C,D, we end up with no match for B, or C or D. 现在,由于B,C,D之间没有匹配,我们最终没有匹配B,或C或D.

Solution to rectify: 纠正解决方案:

  1. Create a graph class and register each possibleChar in it as Vertex. 创建一个图表类并将其中的每个possibleChar注册为Vertex。 Make edges between each pair of vertex using conditions defined in findVectorOfMatchingChars. 使用findVectorOfMatchingChars中定义的条件在每对顶点之间创建边。
  2. You may need to customize conditions to incorporate the edges between other vertices and the 2 A's vertex. 您可能需要自定义条件以将边缘合并到其他顶点和2 A的顶点之间。 For this, you should use more datasets, so that the condtion you create or changing of threshold is not too generic to accomodate non-license plate chars. 为此,您应该使用更多数据集,以便您创建或更改阈值的条件不太通用,无法容纳非牌照字符。
  3. Find connected tree in the graph to find all the characters. 在图中查找连接的树以查找所有字符。 This may add all possibleChars. 这可能会添加所有可能的运营商。 TO avoid that, you can limit addition using weighted edge. 为避免这种情况,您可以使用加权边限制加法。

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

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