C# EMGU CV随机冻结系统,在控制台上抛出奇怪的错误
我在Nuget的项目中添加了EMGU CV(3.1.0.2282) 问题是整个系统有时会冻结(在调试中): CvInvoke.Canny(源、cannyEdge、cannyThreshold、cannyThresholdLinking) 有时下一行,等等。。。我已经重新启动了4次系统 更重要的是。在控制台上的第一次初始操作中,我有如下结束的日志信息: “错误:前端编译器构建失败”,但某些opencv方法运行顺利 我的代码是这样的:C# EMGU CV随机冻结系统,在控制台上抛出奇怪的错误,c#,emgucv,C#,Emgucv,我在Nuget的项目中添加了EMGU CV(3.1.0.2282) 问题是整个系统有时会冻结(在调试中): CvInvoke.Canny(源、cannyEdge、cannyThreshold、cannyThresholdLinking) 有时下一行,等等。。。我已经重新启动了4次系统 更重要的是。在控制台上的第一次初始操作中,我有如下结束的日志信息: “错误:前端编译器构建失败”,但某些opencv方法运行顺利 我的代码是这样的: using Emgu.CV; using Emgu.CV.CvE
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenCV.NETTest
{
public class SquareRecognition
{
public SquareRecognition() {}
private void PyrDownUp(UMat source)
{
using (UMat pyrDownGray = new UMat())
{
CvInvoke.PyrDown(source, pyrDownGray);
CvInvoke.PyrUp(pyrDownGray, source);
}
}
private UMat CannyEdges(UMat source)
{
double cannyThresholdLinking = 120.0;
double cannyThreshold = 180.0;//5.0
UMat cannyEdges = new UMat();
CvInvoke.Canny(source, cannyEdges, cannyThreshold, cannyThresholdLinking);
cannyEdges.Save(@"c:\ttt.jpg");
return cannyEdges;
}
private List<RotatedRect> GetRectangles(UMat source)
{
//PyrDownUp(source);
UMat cannyEdges = CannyEdges(source);
List<RotatedRect> boxList = new List<RotatedRect>(); //a box is a rotated rectangle
using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())
{
CvInvoke.FindContours(cannyEdges, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);
int count = contours.Size;
for (int i = 0; i < count; i++)
{
using (VectorOfPoint contour = contours[i])
using (VectorOfPoint approxContour = new VectorOfPoint())
{
CvInvoke.ApproxPolyDP(contour, approxContour, CvInvoke.ArcLength(contour, true) * 0.05, true);
if (CvInvoke.ContourArea(approxContour, false) > 250) //only consider contours with area greater than 250
{
if (approxContour.Size == 4) //The contour has 4 vertices.
{
#region determine if all the angles in the contour are within [80, 100] degree
bool isRectangle = true;
Point[] pts = approxContour.ToArray();
LineSegment2D[] edges = PointCollection.PolyLine(pts, true);
for (int j = 0; j < edges.Length; j++)
{
double angle = Math.Abs(
edges[(j + 1) % edges.Length].GetExteriorAngleDegree(edges[j]));
if (angle < 80 || angle > 100)
{
isRectangle = false;
break;
}
}
#endregion
if (isRectangle) boxList.Add(CvInvoke.MinAreaRect(approxContour));
}
}
}
}
}
return boxList;
}
public void FindSquares(string FileName)
{
if (!File.Exists(FileName))
throw new Exception(string.Format("No file: {0}", FileName));
using (UMat uimageGray = new UMat())
{
using (Image<Bgr, Byte> img = new Image<Bgr, byte>(FileName))
{
CvInvoke.CvtColor(img, uimageGray, ColorConversion.Bgr2Gray);
}
var RectList = GetRectangles(uimageGray);
}
}
}
}
使用Emgu.CV;
使用Emgu.CV.CvEnum;
使用Emgu.CV.Structure;
使用Emgu.CV.Util;
使用制度;
使用System.Collections.Generic;
使用系统图;
使用System.IO;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间OpenCV.NETTest
{
公营部门认可
{
公共识别(){}
专用电源(UMat源)
{
使用(UMat-pyrdownggray=new-UMat())
{
CvInvoke.PyrDown(源代码,pyrDownGray);
CvInvoke.PyrUp(pyrdownggray,来源);
}
}
专用UMat CannyEdges(UMat来源)
{
双筒ResholdLinking=120.0;
双cannyThreshold=180.0;//5.0
UMat cannyEdges=新的UMat();
CvInvoke.Canny(源、cannyEdge、cannyThreshold、cannyThresholdLinking);
cannyEdges.Save(@“c:\ttt.jpg”);
返回罐头;
}
私有列表Get矩形(UMat源)
{
//pyrdowup(源);
UMat cannyEdges=cannyEdges(源);
List boxList=new List();//框是一个旋转的矩形
使用(VectorOfVectorOfPoint等高线向量=新VectorOfVectorOfPoint()向量)
{
CvInvoke.FindContours(CannyEdge、contours、null、RetrType.List、ChainApproxMethod.ChainApproxSimple);
int count=轮廓。大小;
for(int i=0;i100)
{
isRectangle=false;
打破
}
}
#端区
if(isRectangle)boxList.Add(CvInvoke.minareact(approxContour));
}
}
}
}
}
返回框列表;
}
公共无效FindSquares(字符串文件名)
{
如果(!File.Exists(FileName))
抛出新异常(string.Format(“无文件:{0}”,文件名));
使用(UMat uimageGray=new UMat())
{
使用(图像img=新图像(文件名))
{
CvInvoke.CvtColor(img、uimageGray、ColorConversion.Bgr2Gray);
}
var RectList=get矩形(uimageGray);
}
}
}
}
这是一条非常不健康的错误消息。你,分配错了。我想这有用!你可以写下来作为答案。谢谢