无意间发现opencvsharp ,对于 我这种主要平台是C#的人来 说还是 很不错的。但网上这个opencvsharp的资料很少,还好之前对OPENCV 和emgucv比较熟悉,就准备转到这个平台做视觉。opencvsharp 就是opencv给C#的API ,连函数都没有变化,但方法结构有些出入,对说熟悉opencv的人转过来还是比较容易的。不多说了,CSDN上有人发过 一点基本操作,但从图像的轮廓,模板这种实用的视觉手段就没有了,应该是行业不同,这里我就从轮廓开始接起操做。
前面基本的就不说了。
static void Main(string[] args)
{
Mat mat1 = new Mat(@\"棋盘格.jpg\",ImreadModes.AnyColor);
Mat mat2 = new Mat();
Mat mat3 = new Mat();
Cv2.CvtColor(mat1, mat3,ColorConversionCodes.BGR2GRAY,0);
Cv2.Threshold(mat3, mat2, 200, 255,ThresholdTypes.Binary);
// Cv2.Canny(mat2,mat3,0,255);
Point[][] contours;
HierarchyIndex[] hierarchy;
Cv2.FindContours(mat2, out contours, out hierarchy, RetrievalModes.CComp,ContourApproximationModes.ApproxSimple, null);
for (int i = 0; i < hierarchy.Length; i++)
{
Cv2.DrawContours(mat1, contours, i, Scalar.Red,1, LineTypes. 8, hierarchy, 4, new Point(10,10));
}
Cv2.ImShow(\"mat1\",mat1);
Cv2.ImShow(\"mat2\", mat2);
Cv2.ImShow(\"mat3\", mat3);
Cv2.WaitKey();
}
继续阅读与本文标签相同的文章
-
用SolidWorks建模一个首尾相连的Z形圆环
2026-05-18栏目: 教程
-
海南台风灾害影响评估三维模拟系统投入业务试运行
2026-05-18栏目: 教程
-
第六届世界互联网大会:实现5G网络全覆盖
2026-05-18栏目: 教程
-
网站不稳定和服务器没有关系么?
2026-05-18栏目: 教程
-
首座装配式3D打印“赵州桥”建成
2026-05-18栏目: 教程
