問題描述
從這個線程繼續:
車牌檢測有哪些好的算法?
我開發了我的圖像處理技術來盡可能地強調車牌,總的來說我很滿意,這里有兩個示例.
I've developed my image manipulation techniques to emphasise the license plate as much as possible, and overall I'm happy with it, here are two samples.
現在是最困難的部分,實際檢測車牌.我知道有一些邊緣檢測方法,但我的數學很差,所以我無法將一些復雜的公式翻譯成代碼.
Now comes the most difficult part, actually detecting the license plate. I know there are a few edge detection methods, but my maths is quite poor so I'm unable to translate some of the complex formulas into code.
到目前為止,我的想法是遍歷圖像中的每個像素(基于 img 寬度和高度的 for 循環)由此將每個像素與顏色列表進行比較,由此檢查算法以查看顏色是否保持不變區分車牌白色和文本的黑色.如果發生這種情況,這些像素會被構建到內存中的新位圖中,那么一旦停止檢測到這種模式,就會執行 OCR 掃描.
My idea so far is to loop through every pixel within the image (for loop based on img width & height) From this compare each pixel against a list of colours, from this an algorithm is checked to see if the colors keep differentiating between the license plate white, and the black of the text. If this happens to be true these pixels are built into a new bitmap within memory, then an OCR scan is performed once this pattern has stopped being detected.
我很感激對此的一些意見,因為這可能是一個有缺陷的想法,太慢或太密集.
I'd appreciate some input on this as it might be a flawed idea, too slow or intensive.
謝謝
推薦答案
你的看顏色是否不斷區分車牌白色和文本的黑色"的方法基本上是尋找像素強度變化的區域從黑色到白色,反之亦然很多次.邊緣檢測可以完成基本相同的事情.但是,實現自己的方法仍然是一個好主意,因為您將在此過程中學到很多東西.哎呀,為什么不兩者都做,并將您的方法的輸出與一些現成的邊緣檢測算法的輸出進行比較?
Your method of "see if the colors keep differentiating between the license plate white, and the black of the text" is basically searching for areas where the pixel intensity changes from black to white and vice-versa many times. Edge detection can accomplish essentially the same thing. However, implementing your own methods is still a good idea because you will learn a lot in the process. Heck, why not do both and compare the output of your method with that of some ready-made edge detection algorithm?
在某些時候,您會想要一個二值圖像,例如黑色像素對應于非字符"標簽,白色像素對應于是字符"標簽.也許最簡單的方法是使用閾值函數.但這只有在角色已經以某種方式強調的情況下才會有效.
At some point you will want to have a binary image, say with black pixels corresponding to the "not-a-character" label, and white pixels corresponding to the "is-a-character" label. Perhaps the simplest way to do that is to use a thresholding function. But that will only work well if the characters have already been emphasized in some way.
正如您在另一個帖子中提到的那樣,您可以使用黑帽運算符來執行此操作,結果如下:
As someone mentioned in your other thread, you can do that using the black hat operator, which results in something like this:
如果您使用 Otsu 的方法(自動確定全局閾值級別)對上面的圖像進行閾值處理,您會得到:
If you threshold the image above with, say, Otsu's method (which automatically determines a global threshold level), you get this:
有幾種方法可以清理該圖像.例如,您可以找到連接的組件并丟棄那些太小、太大、太寬或太高而不能成為角色的組件:
There are several ways to clean that image. For instance, you can find the connected components and throw away those that are too small, too big, too wide or too tall to be a character:
由于圖像中的字符相對較大且完全連接,因此此方法效果很好.
Since the characters in your image are relatively large and fully connected this method works well.
接下來,您可以根據鄰居的屬性過濾剩余的組件,直到您擁有所需數量的組件(= 字符數).如果您想識別字符,您可以計算每個字符的特征并將它們輸入到分類器中,該分類器通常使用監督學習構建.
Next, you could filter the remaining components based on the properties of the neighbors until you have the desired number of components (= number of characters). If you want to recognize the character, you could then calculate features for each character and input them to a classifier, which usually is built with supervised learning.
當然,上述所有步驟只是一種方法.
All the steps above are just one way to do it, of course.
順便說一句,我使用 OpenCV + Python 生成了上面的圖像,這是計算機視覺的絕佳組合.
By the way, I generated the images above using OpenCV + Python, which is a great combination for computer vision.
這篇關于續 - 車牌檢測的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!