收藏 分享(赏)

车牌识别emgucv.doc

上传人:精品资料 文档编号:10936107 上传时间:2020-01-22 格式:DOC 页数:5 大小:14.98KB
下载 相关 举报
车牌识别emgucv.doc_第1页
第1页 / 共5页
车牌识别emgucv.doc_第2页
第2页 / 共5页
车牌识别emgucv.doc_第3页
第3页 / 共5页
车牌识别emgucv.doc_第4页
第4页 / 共5页
车牌识别emgucv.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、using System;using System.Collections.Generic;using System.Text;using System.Drawing;using Emgu.Util;using Emgu.CV;using Emgu.CV.Structure;using tessnet2;using System.Diagnostics;namespace LicensePlateRecognition/ / A license plate detector/ public class LicensePlateDetector : DisposableObjectprivat

2、e Tesseract _ocr;/ / Create a license plate detector/ public LicensePlateDetector()/create OCR_ocr = new Tesseract();/You can download more language definition data from/http:/ supported includes:/Dutch, Spanish, German, Italian, French and English_ocr.Init(“eng“, false);/ / Detect license plate fro

3、m the given image/ / The image to search license plate from/ A list of images where the detected license plate region is stored/ A list of images where the detected license plate region with noise removed is stored/ A list where the region of license plate, defined by an MCvBox2D is stored/ The list

4、 of words for each license platepublic List DetectLicensePlate(Image img, List licensePlateList, List filteredLicensePlateList, List boxList)/Stopwatch w = Stopwatch.StartNew();List licenses = new List();using (Image gray = img.Convert()using (Image canny = new Image(gray.Size)using (MemStorage stor

5、 = new MemStorage()CvInvoke.cvCanny(gray, canny, 100, 50, 3);Contour contours = canny.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE,stor);FindLicensePlate(contours, gray, canny, licensePlateList, filteredLicensePlateList, boxList, licens

6、es);/w.Stop();return licenses;private void FindLicensePlate(Contour contours, Image gray, Image canny,List licensePlateList, List filteredLicensePlateList, List boxList,List licenses)for (; contours != null; contours = contours.HNext)Contour approxContour = contours.ApproxPoly(contours.Perimeter * 0

7、.05, contours.Storage);if (approxContour.Area 100 if (!IsParallelogram(approxContour.ToArray()Contour child = contours.VNext;if (child != null)FindLicensePlate(child, gray, canny, licensePlateList, filteredLicensePlateList, boxList, licenses);continue;MCvBox2D box = approxContour.GetMinAreaRect();do

8、uble whRatio = (double)box.size.Width / box.size.Height;if (!(3.0 child = contours.VNext;if (child != null)FindLicensePlate(child, gray, canny, licensePlateList, filteredLicensePlateList, boxList, licenses);continue;Image plate = gray.Copy(box);Image filteredPlate = FilterPlate(plate);List words;usi

9、ng (Bitmap bmp = filteredPlate.Bitmap)words = _ocr.DoOCR(bmp, filteredPlate.ROI);licenses.Add(words);licensePlateList.Add(plate);filteredLicensePlateList.Add(filteredPlate);boxList.Add(box);/ / Check if the four points forms a parallelogram/ / The four points that defines a polygon/ True if the four

10、 points defines a parallelogramprivate static bool IsParallelogram(Point pts)LineSegment2D edges = PointCollection.PolyLine(pts, true);double diff1 = Math.Abs(edges0.Length - edges2.Length);double diff2 = Math.Abs(edges1.Length - edges3.Length);if (diff1 / edges0.Length / Filter the license plate to

11、 remove noise/ / The license plate image/ License plate image without the noiseprivate static Image FilterPlate(Image plate)Image thresh = plate.ThresholdBinaryInv(new Gray(120), new Gray(255);using (Image plateMask = new Image(plate.Size)using (Image plateCanny = plate.Canny(new Gray(100), new Gray

12、(50)using (MemStorage stor = new MemStorage()plateMask.SetValue(255.0);for (Contour contours = plateCanny.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,stor);contours != null; contours = contours.HNext)Rectangle rect = contours.Bound

13、ingRectangle;if (rect.Height (plate.Height 1)rect.X -= 1; rect.Y -= 1; rect.Width += 2; rect.Height += 2;rect.Intersect(plate.ROI);plateMask.Draw(rect, new Gray(0.0), -1);thresh.SetValue(0, plateMask);thresh._Erode(1);thresh._Dilate(1);return thresh;protected override void DisposeObject()_ocr.Dispose();

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报