设计师网站使用不了,网站备案 个人,wordpress视频插件,北京和隆优化招聘C#使用OpenCvSharp4库中5个基础函数-灰度化、高斯模糊、Canny边缘检测、膨胀、腐蚀 
使用OpenCV可以对彩色原始图像进行基本的处理#xff0c;涉及到5个常用的处理#xff1a; 灰度化  模糊处理  Canny边缘检测  膨胀  腐蚀  
1、测试图像lena.jpg 
本例中我们采用数字图像处…C#使用OpenCvSharp4库中5个基础函数-灰度化、高斯模糊、Canny边缘检测、膨胀、腐蚀 
使用OpenCV可以对彩色原始图像进行基本的处理涉及到5个常用的处理 灰度化  模糊处理  Canny边缘检测  膨胀  腐蚀  
1、测试图像lena.jpg 
本例中我们采用数字图像处理中经常用到的一副标准图像lena.png作为测试图像如下图所示:  具体资源下载地址为lena图像下载地址  
2、使用Visual Studio 2022创建一个基于C# .Net控制台的程序 
首先我们新建一个基于C# .Net控制台的程序项目名为OpenCVExample然后把lena.jpg拷贝到E:\SoftDevelop\CPlus\VS2022Projects\CSharpExamples\OpenCVExample\OpenCVExample\bin\Debug\images对应目录下如下图所示  
安装OpenCvSharp4和OpenCvSharp4.runtime.win两个NuGet包或者直接安装OpenCvSharp4.Windows包 安装OpenCvSharp4和OpenCvSharp4.runtime.win两个NuGet包之后packages.config配置文件如下 
?xml version1.0 encodingutf-8?
packagespackage idOpenCvSharp4 version4.9.0.20240103 targetFrameworknet48 /package idOpenCvSharp4.runtime.win version4.9.0.20240103 targetFrameworknet48 /package idSystem.Buffers version4.5.1 targetFrameworknet48 /package idSystem.Memory version4.5.5 targetFrameworknet48 /package idSystem.Numerics.Vectors version4.5.0 targetFrameworknet48 /package idSystem.Runtime.CompilerServices.Unsafe version6.0.0 targetFrameworknet48 /package idSystem.ValueTuple version4.5.0 targetFrameworknet48 /
/packagesC#示例代码 
对应的C#代码如下 
using OpenCvSharp;namespace OpenCVExample
{public class Program{/// summary/// OpenCV的5个基础函数-灰度化、高斯模糊、Canny边缘检测、膨胀、腐蚀/// /summarypublic static void FiveBasicFunction(){Mat img  Cv2.ImRead(images/lena.jpg);    // 读取图像Mat grayImg  new Mat();Cv2.CvtColor(img, grayImg, ColorConversionCodes.BGR2GRAY);Mat blurImg  new Mat();Cv2.GaussianBlur(grayImg, blurImg, new Size(7, 7), 0);Mat cannyImg  new Mat();Cv2.Canny(blurImg, cannyImg, 150, 200);Mat dialationImg  new Mat();Mat kernel  new Mat(5, 5, MatType.CV_8UC1);Cv2.Dilate(blurImg, dialationImg, kernel);Mat erodeImg  new Mat();Cv2.Erode(dialationImg, erodeImg, kernel);Cv2.ImShow(Image, img);   // 显示原图像Cv2.ImShow(Gray Image, grayImg);  // 显示灰度图像Cv2.ImShow(Blur Image, blurImg);  // 显示高斯模糊图像Cv2.ImShow(Canny Image, cannyImg);    // 显示Canny边缘检测图像Cv2.ImShow(Dialation Image, dialationImg);    // 膨胀图Cv2.ImShow(Erode Image, erodeImg);    // 腐蚀图Cv2.WaitKey(0);Cv2.DestroyAllWindows();}static void Main(string[] args){FiveBasicFunction();//Console.ReadKey();}}
}程序运行结果 
在VS2022中运行上述代码结果如下图所示   参考资料 
https://github.com/shimat/opencvsharpLEARN OPENCV C in 4 HOURS | Including 3x Projects | Computer VisionLearn-OpenCV-cpp-in-4-HoursLEARN OPENCV in 3 HOURS with Python | Including 3xProjects | Computer VisionLearn-OpenCV-in-3-hours 文章转载自: http://www.morning.bztzm.cn.gov.cn.bztzm.cn http://www.morning.lmhwm.cn.gov.cn.lmhwm.cn http://www.morning.ltxgk.cn.gov.cn.ltxgk.cn http://www.morning.tlrxt.cn.gov.cn.tlrxt.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.xkyst.cn.gov.cn.xkyst.cn http://www.morning.yxkyl.cn.gov.cn.yxkyl.cn http://www.morning.nbqwr.cn.gov.cn.nbqwr.cn http://www.morning.pcngq.cn.gov.cn.pcngq.cn http://www.morning.dyght.cn.gov.cn.dyght.cn http://www.morning.gkmwk.cn.gov.cn.gkmwk.cn http://www.morning.rwhlf.cn.gov.cn.rwhlf.cn http://www.morning.dmzfz.cn.gov.cn.dmzfz.cn http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn http://www.morning.pkfpl.cn.gov.cn.pkfpl.cn http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn http://www.morning.qdxtj.cn.gov.cn.qdxtj.cn http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn http://www.morning.lmmh.cn.gov.cn.lmmh.cn http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn http://www.morning.fnhxp.cn.gov.cn.fnhxp.cn http://www.morning.qfrsm.cn.gov.cn.qfrsm.cn http://www.morning.sqqds.cn.gov.cn.sqqds.cn http://www.morning.dgxrz.cn.gov.cn.dgxrz.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.kbynw.cn.gov.cn.kbynw.cn http://www.morning.pqnkg.cn.gov.cn.pqnkg.cn http://www.morning.rkypb.cn.gov.cn.rkypb.cn http://www.morning.wctqc.cn.gov.cn.wctqc.cn http://www.morning.bpcf.cn.gov.cn.bpcf.cn http://www.morning.wgrl.cn.gov.cn.wgrl.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.dwztj.cn.gov.cn.dwztj.cn http://www.morning.pfcrq.cn.gov.cn.pfcrq.cn http://www.morning.hdwjb.cn.gov.cn.hdwjb.cn http://www.morning.hmtft.cn.gov.cn.hmtft.cn http://www.morning.thmlt.cn.gov.cn.thmlt.cn http://www.morning.yrbqy.cn.gov.cn.yrbqy.cn http://www.morning.wctqc.cn.gov.cn.wctqc.cn http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.gxtfk.cn.gov.cn.gxtfk.cn http://www.morning.fxkgp.cn.gov.cn.fxkgp.cn http://www.morning.rjbb.cn.gov.cn.rjbb.cn http://www.morning.lqchz.cn.gov.cn.lqchz.cn http://www.morning.zwndt.cn.gov.cn.zwndt.cn http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn http://www.morning.ydxx123.cn.gov.cn.ydxx123.cn http://www.morning.ghpld.cn.gov.cn.ghpld.cn http://www.morning.qstkk.cn.gov.cn.qstkk.cn http://www.morning.hqwcd.cn.gov.cn.hqwcd.cn http://www.morning.3jiax.cn.gov.cn.3jiax.cn http://www.morning.pmftz.cn.gov.cn.pmftz.cn http://www.morning.ghslr.cn.gov.cn.ghslr.cn http://www.morning.qmmfr.cn.gov.cn.qmmfr.cn http://www.morning.djpgc.cn.gov.cn.djpgc.cn http://www.morning.bktly.cn.gov.cn.bktly.cn http://www.morning.c7625.cn.gov.cn.c7625.cn http://www.morning.wxwall.com.gov.cn.wxwall.com http://www.morning.yxkyl.cn.gov.cn.yxkyl.cn http://www.morning.qwmsq.cn.gov.cn.qwmsq.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.fhghy.cn.gov.cn.fhghy.cn http://www.morning.ltzkk.cn.gov.cn.ltzkk.cn http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn http://www.morning.nzcys.cn.gov.cn.nzcys.cn http://www.morning.qpntn.cn.gov.cn.qpntn.cn http://www.morning.trffl.cn.gov.cn.trffl.cn http://www.morning.xyrw.cn.gov.cn.xyrw.cn http://www.morning.cljpz.cn.gov.cn.cljpz.cn http://www.morning.nnhfz.cn.gov.cn.nnhfz.cn http://www.morning.fkgcd.cn.gov.cn.fkgcd.cn http://www.morning.dpplr.cn.gov.cn.dpplr.cn http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn http://www.morning.jxlnr.cn.gov.cn.jxlnr.cn http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn http://www.morning.zmwd.cn.gov.cn.zmwd.cn http://www.morning.phjyb.cn.gov.cn.phjyb.cn