EmguCV类(CvInvoke_Class) 方法整理
- 格式:doc
- 大小:346.50 KB
- 文档页数:21
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{/// <summary>/// A license plate detector/// </summary>public class LicensePlateDetector : DisposableObject{private Tesseract _ocr;/// <summary>/// Create a license plate detector/// </summary>public LicensePlateDetector(){//create OCR_ocr = new Tesseract();//You can download more language definition data from///p/tesseract-ocr/downloads/list//Languages supported includes://Dutch, Spanish, German, Italian, French and English_ocr.Init("eng", false);}/// <summary>/// Detect license plate from the given image/// </summary>/// <param name="img">The image to search license plate from</param>/// <param name="licensePlateList">A list of images where the detected license plate region is stored</param>/// <param name="filteredLicensePlateList">A list of images where the detected license plate region with noise removed is stored</param>/// <param name="boxList">A list where the region of license plate, defined by an MCvBox2D is stored</param>/// <returns>The list of words for each license plate</returns>public List<List<Word>> DetectLicensePlate(Image<Bgr, byte> img, List<Image<Gray, Byte>> licensePlateList, List<Image<Gray, Byte>> filteredLicensePlateList, List<MCvBox2D> boxList){//Stopwatch w = Stopwatch.StartNew();List<List<Word>> licenses = new List<List<Word>>();using (Image<Gray, byte> gray = img.Convert<Gray, Byte>())using (Image<Gray, Byte> canny = new Image<Gray, byte>(gray.Size))using (MemStorage stor = new MemStorage()){CvInvoke.cvCanny(gray, canny, 100, 50, 3);Contour<Point> 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, licenses);}//w.Stop();return licenses;}private void FindLicensePlate(Contour<Point> contours, Image<Gray, Byte> gray, Image<Gray, Byte> canny,List<Image<Gray, Byte>> licensePlateList, List<Image<Gray, Byte>> filteredLicensePlateList, List<MCvBox2D> boxList,List<List<Word>> licenses){for (; contours != null; contours = contours.HNext){Contour<Point> approxContour = contours.ApproxPoly(contours.Perimeter * 0.05, contours.Storage);if (approxContour.Area > 100 && approxContour.Total == 4){//img.Draw(contours, new Bgr(Color.Red), 1);if (!IsParallelogram(approxContour.ToArray())){Contour<Point> child = contours.VNext;if (child != null)FindLicensePlate(child, gray, canny, licensePlateList,filteredLicensePlateList, boxList, licenses);continue;}MCvBox2D box = approxContour.GetMinAreaRect();double whRatio = (double)box.size.Width / box.size.Height;if (!(3.0 < whRatio && whRatio < 8.0)){Contour<Point> child = contours.VNext;if (child != null)FindLicensePlate(child, gray, canny, licensePlateList, filteredLicensePlateList, boxList, licenses);continue;}Image<Gray, Byte> plate = gray.Copy(box);Image<Gray, Byte> filteredPlate = FilterPlate(plate);List<Word> words;using (Bitmap bmp = filteredPlate.Bitmap)words = _ocr.DoOCR(bmp, filteredPlate.ROI);licenses.Add(words);licensePlateList.Add(plate);filteredLicensePlateList.Add(filteredPlate);boxList.Add(box);}}}/// <summary>/// Check if the four points forms a parallelogram/// </summary>/// <param name="pts">The four points that defines a polygon</param>/// <returns>True if the four points defines a parallelogram</returns>private static bool IsParallelogram(Point[] pts){LineSegment2D[] edges = PointCollection.PolyLine(pts, true);double diff1 = Math.Abs(edges[0].Length - edges[2].Length);double diff2 = Math.Abs(edges[1].Length - edges[3].Length);if (diff1 / edges[0].Length <= 0.05 && diff1 / edges[2].Length <= 0.05&& diff2 / edges[1].Length <= 0.05 && diff2 / edges[3].Length <= 0.05){return true;}return false;}/// <summary>/// Filter the license plate to remove noise/// </summary>/// <param name="plate">The license plate image</param>/// <returns>License plate image without the noise</returns>private static Image<Gray, Byte> FilterPlate(Image<Gray, Byte> plate){Image<Gray, Byte> thresh = plate.ThresholdBinaryInv(new Gray(120), new Gray(255));using (Image<Gray, Byte> plateMask = new Image<Gray, byte>(plate.Size))using (Image<Gray, Byte> plateCanny = plate.Canny(new Gray(100), new Gray(50)))using (MemStorage stor = new MemStorage()){plateMask.SetValue(255.0);for (Contour<Point> 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.BoundingRectangle;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();}}}。
invoke调用方法通过invoke调用方法什么是invoke调用方法?在编程领域中,invoke是一种常用的方法调用技术。
通过invoke 调用方法,可以实现动态调用和执行特定的代码段。
无论是在前端开发还是后端开发,invoke都是非常有用的工具。
下面将介绍不同编程语言中的invoke调用方法。
Java中的invoke调用方法在Java中,可以使用反射来实现invoke调用方法。
下面是一些常用的Java反射API,可以用来实现invoke调用方法:•():根据类的完全限定名获取Class对象。
•():根据方法名和参数类型获取Method对象。
•():调用指定对象的方法。
以下是一个Java中使用invoke调用方法的示例:Class<?> clazz = ("");Object obj = ().newInstance();Method method = ("myMethod", , );(obj, 42, "Hello, World!");Python中的invoke调用方法在Python中,可以使用反射机制来实现invoke调用方法。
Python提供了getattr()和setattr()等内置函数来实现反射。
以下是一个Python中使用getattr()和setattr()实现invoke调用方法的示例:class MyClass:def my_method(self, num, message):print(f"Number: {num}, Message: {message}")obj = MyClass()method_name = "my_method"method = getattr(obj, method_name)method(42, "Hello, World!")JavaScript中的invoke调用方法在JavaScript中,可以使用()和()来实现invoke调用方法。
使⽤C#+EmguCV处理图像⼊门(⼀)⾸先我们先了解⼀下该库的⼀些相关信息OpenCV(Open Source Computer Vision Library)是⼀个(开源免费)发⾏的跨平台计算机视觉库,可以运⾏在Linux、Windows、Android、ios等操作系统上,它轻量级⽽且⾼效---由⼀系列C函数和少量C++类构成,同时提供了Python、Ruby、MATLAB等语⾔的接⼝,实现了图像处理和计算机视觉⽅⾯的诸多通⽤算法。
EmguCV是OpenCV的⼀个跨平台的.Net封装,由于OpenCV是⽤C和C++编写的,Emgu⽤C#对其进⾏封装,允许⽤.Net语⾔来调⽤OpenCV函数,如C#、VB、VC++等,同时该封装也可以被编译到Mono平台和允许在Windows、Mac OS、Android、iPhone、iPad等多个平台上运⾏。
OpenCV官⽹:https:///EmguCV官⽹:/wiki/index.php/Main_Page然后EMguCV的⼀些模块的介绍见下图接下来咱们来配置EmguCV(安装与配置环境)1.从官⽹下载安装包(官⽹地址上⾯已经有了)附:安装地址尽量不要安装到C盘,部分win10会出现访问权限限制安装之后如下图2.配置环境变量(在系统⾼级设置⾥⾯的PATH变量)控制⾯板=》系统和安全=》系统=》⾼级系统设置=》⾼级=》环境变量=》系统变量=》PATH添加D:\EmguCV3.3\emgucv-windesktop 3.3.0.2824\bin;D:\EmguCV3.3\emgucv-windesktop 3.3.0.2824\libs\x86;D:\EmguCV3.3\emgucv-windesktop 3.3.0.2824\libs\x64;配置完成后,咱们就可以开始写代码了,在VS上⾯新建控制台项⽬(C#)3.引⽤DLL然后引⽤=》添加引⽤=》浏览=》选择你安装路径下的bin⽂件夹⾥⾯的dll4.选择引⽤之后,再到程序上⾯引⽤命名控件常⽤的类库:using Emgu.CV;using Emgu.CV.Structure;using Emgu.CV.CvEnum;using Emgu.Util;然后开始我们的helloword代码:1 Mat imgscr = CvInvoke.Imread("1.jpg");//读取图像2 CvInvoke.Imshow("img", imgscr);//显⽰图像3 CvInvoke.WaitKey(0);//按键等待。
C#EmguCV机械⼿相机9点坐标标定很多初学者,都对标定概念模糊不清,分不清坐标系之间的关系,搞不清相机标定和机械⼿相机标定有什么关系,想当初⾃⼰也是⼀个⼈摸索了很久,本⽂将尽量给⼤家解释。
我们通常所说的相机标定分为两种,⼀种是相机参数的标定,这⼀般⽤到张⽒标定法,标定的作⽤是校正相机⾃⾝的畸变,利⽤校正得到的参数对图形进⾏处理后再呈现出来。
关于这⽅⾯的资料,⽹上⼤把,我也不再此说明。
⼀般的机械⼿定位也不会进⾏这个标定,因为现在的相机畸变还是很⼩的,精度可以满⾜⼤多数要求。
本⽂要介绍的是第⼆种,相机和机械⼿之间的标定,作⽤:建⽴相机坐标系和机械⼿坐标系之间的关系,即给机械⼿装上眼睛,让它去哪就去哪。
常⽤的⽅法是9点标定,所⽤到函数是EstimateRigidTransform,⽹上关于 estimateRigidTransform 的详细说明很少,Emgucv的⼏乎没有。
当时找了N久,⼀度以为opencv没有坐标系转换的算法,差点就投奔halcon去了,不得不说,opencv在机器视觉⽅⾯的应⽤是完全不如halcon的。
EstimateRigidTransform有两个⽅法。
⽅法⼀:Mat EstimateRigidTransform(PointF[] sourcePoints, PointF[] destinationPoints, bool fullAffine);返回的是⼀个2*3的double的矩阵。
第⼀个参数sourcePoints:换之前图像上的点(相机坐标系下的点)第⼆个参数destinationPoints:换之后图像上的点(机械⼿坐标系下的点)第三个参数fullAffine: TRUE(全仿射变换,包括:rotation, translation, scaling,shearing,reflection)FALSE(带有约束的仿射变换)⽅法⼆:Mat EstimateRigidTransform(IInputArray src, IInputArray dst, bool fullAffine); //返回的是图像第⼀个参数src:变换之前的图像第⼆个参数dst:变换之前的图像第三个参数fullAffine: TRUE(全仿射变换,包括:rotation, translation, scaling,shearing,reflection)FALSE(带有约束的仿射变换)因为我们需要的是坐标点,所以选⽤第⼀个函数。
emgucv例子
Emgu CV(也称为Emgu Computer Vision)是一个基于OpenCV
库的跨平台计算机视觉库,它提供了用于图像处理、对象检测、人
脸识别、视频分析等功能的丰富工具和类库。
下面我将从多个角度
来介绍Emgu CV的例子。
首先,Emgu CV提供了丰富的图像处理功能,包括图像滤波、
边缘检测、图像变换等。
例如,你可以使用Emgu CV来实现图像的
模糊处理、边缘检测以及图像的缩放和旋转等操作。
这些功能可以
帮助你处理图像数据,提取特征并进行后续的分析和识别。
其次,Emgu CV还支持对象检测和识别。
你可以利用Emgu CV
提供的算法和工具来实现目标检测、物体跟踪以及形状识别等功能。
例如,你可以使用Emgu CV来开发一个人脸识别系统,检测视频中
的人脸并进行识别和跟踪。
此外,Emgu CV还提供了丰富的视频处理功能。
你可以利用Emgu CV来实现视频的读取、处理和分析,包括视频流的捕获、帧
处理、运动检测等。
这些功能可以帮助你开发视频监控系统、视频
分析系统以及视频内容识别等应用。
总之,Emgu CV提供了丰富的计算机视觉功能和工具,可以帮助开发者快速实现图像处理、对象检测、人脸识别、视频分析等功能。
通过使用Emgu CV,开发者可以更加高效地开发和部署计算机视觉应用,实现图像和视频数据的分析和识别。
希望这些例子可以帮助你更好地了解Emgu CV的功能和应用。
信息科学①基金项目:本文获江苏省淮安市国际合作科技项目(项目编号:HAC201618)资助。
DOI:10.16660/ki.1674-098X.2018.09.150基于Emgu CV的GPU加速人脸识别①李刚 孙平(淮阴师范学院 江苏淮安 223300)摘 要:Emgu CV是.NET平台下对OpenCV图像处理库的封装,可以实现人脸识别的判断。
本文着重讨论了在.NET 下基于Emgu CV利用GPU加速技术实现了静态图像的人脸检测、人脸识别、人脸比对,以及视频流中的人脸识别。
该软件获得我校技术进步二等奖,实验结果证明本程序运行稳定,结果可靠,识别速度快。
关键词:Emgu CV GPU加速 人脸检测 人脸识别中图分类号:TP39 文献标识码:A 文章编号:1674-098X(2018)03(c)-0150-04 Abstract: Emgu CV is OpenCV image processing library encapsulation on .net platform, that can be used to realize face recognition judgment. This article emphatically introduced Emgu CV graphics library for face detection, face match, and face recognition in image and in video as well, with the assist of GPU speeding technology. This implemented procedure was granted 2nd prize in the Advanced Technologies in Huaiyin Normal University. Long-time running demos show the procedure worked stably, reliably and quickly.Key Words: Emgu CV; GPU; Face Detection; Face Recognition人脸识别作为一种成熟而新颖的生物特征识别技术,具有识别精度高,识别速度快,使用方便,不易被仿冒等优点,与虹膜识别、指纹扫描等这些生物特征识别技术相比,人脸识别技术在各个应用方面都表现出得天独厚的技术优势,而且成本低廉,易于推广使用,企业用户的接受程度非常高。
emgucv 计算像素平均值EmguCV是一个基于C#编写的开源计算机视觉库,它提供了丰富的图像处理与计算机视觉函数和算法。
在EmguCV中,计算像素平均值是一个非常常见的操作,本文将介绍如何使用EmguCV来计算像素平均值,并对此进行详细解析。
首先,我们需要导入EmguCV库并创建一个图像对象。
EmguCV提供了Image类来表示一个图像,我们可以使用该类来加载、保存和处理图像。
```csharpusing Emgu.CV;using Emgu.CV.Structure;Image<Bgr, byte> image = new Image<Bgr,byte>("path_to_image.jpg");```在上述代码中,我们使用了Image<Bgr, byte>泛型类来表示一个RGB图像。
通过指定泛型参数,我们可以指定图像的颜色空间和像素数据类型。
接下来,我们需要将图像转换为灰度图像。
在计算像素平均值时,一般将图像转换为灰度图像,这样可以简化计算过程。
```csharpImage<Gray, byte> grayImage = image.Convert<Gray, byte>();```在上述代码中,我们使用了Convert方法将RGB图像转换为灰度图像。
Convert方法接受一个目标图像类型作为参数,并返回一个转换后的图像对象。
然后,我们需要计算图像的像素平均值。
对于灰度图像,像素的取值范围是0-255,我们可以通过遍历图像的所有像素,并计算所有像素值的总和,再除以像素总数来得到平均值。
```csharpdouble total = 0;int count = 0;for (int y = 0; y < grayImage.Height; y++){for (int x = 0; x < grayImage.Width; x++){total += grayImage.Data[y, x, 0];count++;}}double average = total / count;```在上述代码中,我们使用了Data属性来获取图像的像素数据。
颜色直方图的计算、显示、处理、对比及反向投影(How to Use Histogram? Calculate, Show, Process, Compare and BackProject)作者:王先荣前言颜色直方图直观的显示了图像在色彩空间的分布状况,本文将讨论在EmguCv及OpenCv中跟直方图相关的一些基本操作,包括:计算、显示、处理、对比及反向投影,并谈谈在实践过程中得到的一些经验。
如无特别说明,下文所提的直方图均指颜色直方图。
直方图的计算EmguCv将OpenCv的一系列直方图函数封装到了类DenseHistogram里面,可以用方法Calculate方便的计算图像的直方图。
不过值得注意的是,该方法接受的第一个参数是“单通道”图像数组;而一般情况下的图像都是3通道的,在计算之前我们需要用Image<TColor,TDepth>.Split方法将其分解成单通道图像,然后选择需要参与直方图计算的通道。
下面有几段计算直方图的代码,分别计算单通道(红色)直方图、色调和饱和度直方图。
计算直方图///<summary>///计算直方图(红色)///</summary>private void CalcHistRed(){//计算int rBins = 256;RangeF rRange = new RangeF(0f, 255f);Image<Bgr, Byte> imageSource = new Image<Bgr, By te>((Bitmap)pbSource.Image);Image<Gray, Byte> imageRed = imageSource.Split() [2];DenseHistogram hist = new DenseHistogram(rBins, rRange);hist.Calculate(new IImage[] { imageRed }, false, null);//显示pbHistogram.Image = GenerateHistImage(hist).Bitm ap;//释放资源imageSource.Dispose();imageRed.Dispose();hist.Dispose();}///<summary>///计算直方图(色调和饱和度)///</summary>private void CalcHistHs(){//计算int hBins = 180;RangeF hRange = new RangeF(0f, 179f); //色调的范围在0~180之间int sBins = 256;RangeF sRange = new RangeF(0f, 255f);Image<Bgr, Byte> imageSource = new Image<Bgr, By te>((Bitmap)pbSource.Image);Image<Hsv, Byte> imageHsv = imageSource.Convert< Hsv, Byte>(); //将色彩空间从BGR转换到HSVImage<Gray, Byte>[] imagesHsv = imageSource.Spli t(); //分解成H、S、V三部分DenseHistogram hist = new DenseHistogram(new int [] { hBins, sBins }, new RangeF[] { hRange, sRange });hist.Calculate(new IImage[] { imagesHsv[0], imag esHsv[1] }, false, null);//显示pbHistogram.Image = GenerateHistImage(hist).Bitm ap;//释放资源imageSource.Dispose();imageHsv.Dispose();foreach (Image<Gray, Byte> image in imagesHsv)image.Dispose();hist.Dispose();}直方图的显示我们可以用以下方式来查看直方图:(1)使用HistogramViewer窗体显示直方图;(2)使用HistogramBox控件显示直方图;(3)用自己写的方法将直方图转换成图像,然后显示出来。
emgucv 小波变换去噪
EmguCV是一个基于OpenCV的.NET包装器,它提供了许多计算
机视觉和图像处理功能。
而小波变换是一种信号处理技术,常用于
去噪和特征提取。
结合EmguCV和小波变换可以实现图像去噪的功能。
首先,使用EmguCV加载图像并将其转换为灰度图像。
然后,可
以使用小波变换对灰度图像进行去噪处理。
小波变换可以将图像分
解为不同尺度的细节和近似部分,通过去除细节部分中的噪声来实
现去噪效果。
在EmguCV中,可以使用小波变换函数(如cv2.dwt)来对图像
进行小波变换,然后根据需要去除细节部分中的噪声。
常见的小波
去噪方法包括阈值处理和软硬阈值处理。
阈值处理可以通过设定阈
值来去除小于阈值的细节部分,软硬阈值处理则是在阈值处理的基
础上加入了平滑处理,可以更好地保留图像的细节信息。
另外,还可以使用小波变换的逆变换将处理后的图像恢复到原
始图像空间。
在实现小波去噪时,需要根据具体的应用场景和要求
来选择合适的小波基函数、阈值处理方法以及阈值的设定。
总之,结合EmguCV和小波变换可以实现图像的去噪处理,通过合理选择小波基函数和阈值处理方法,可以有效地去除图像中的噪声,保留图像的细节信息,从而得到清晰的图像结果。
希望这些信息能够帮助到你。
emgu中matchtemplate函数详解MatchTemplate函数是Emgu CV库中非常重要的一个函数,它可以对两幅图像进行匹配,找出其中的相似区域,从而实现图像识别、图像跟踪等多种应用。
本文将从函数的定义、参数、返回值等多个方面详细介绍MatchTemplate函数的使用方法及操作细节。
一、函数定义MatchTemplate函数用于在源图像(inputImage)中搜索目标图像(templateImage)的匹配位置,返回匹配的相关信息。
函数的定义如下:```public static void MatchTemplate(IInputArray inputImage, // 输入图像IInputArray templ, // 模板图像IOutputArray result, // 结果图像TemplateMatchingType matchType, // 匹配类型IInputArray mask = null) // 掩码```函数的参数已在注释中明确给出,这里不再赘述,接下来分别对各个参数进行详细介绍。
二、函数参数1. inputImage:输入图像参数inputImage是待匹配的输入图像,数据类型为IInputArray,可以是图像矩阵,也可以是图像文件路径。
例如:```Mat srcImage = CvInvoke.Imread("inputImage.png"); // 读入图像```2. templ:模板图像3. result:结果图像4. matchType:匹配模式参数matchType是匹配模式,它指定了从输入图像中查找与模板图像最相似的区域时使用的算法。
参数类型为TemplateMatchingType。
目前支持的匹配模式有以下五种:• CcoeffNormed:相关系数归一化匹配;5. mask:掩码参数mask是一个可选参数,用于指定源图像中哪些像素参与匹配操作。