- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当我运行我的程序时,我总是遇到这个错误...
我不确定我的程序有什么问题,仅供引用,实际上我的程序包含许多图像处理算法,例如
我不知道这些过程是否触发了错误......
但是当我移除凸包/凸缺陷时,错误消失了......有什么解决办法吗?
编辑:(添加)
这是代码片段
private void ExtractContourAndHull()
{
using (MemStorage storage = new MemStorage())
{
Contour<Point> contours = backproject.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage);
Contour<Point> biggestContour = null;
Double Result1 = 0;
Double Result2 = 0;
while (contours != null)
{
Result1 = contours.Area;
if (Result1 > Result2)
{
Result2 = Result1;
biggestContour = contours;
}
contours = contours.HNext;
}
if (biggestContour != null)
{
//image.Draw(biggestContour, new Bgr(Color.DarkViolet), 2);
Contour<Point> currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.005, storage);
image.Draw(currentContour, new Bgr(Color.LimeGreen), 2);
biggestContour = currentContour;
hull = biggestContour.GetConvexHull(ORIENTATION.CV_CLOCKWISE);
box = biggestContour.GetMinAreaRect();
PointF[] points = box.GetVertices();
//handRect = box.MinAreaRect();
//image.Draw(handRect, new Bgr(200, 0, 0), 1);
Point[] ps = new Point[points.Length];
for (int i = 0; i < points.Length; i++)
ps[i] = new Point((int)points[i].X, (int)points[i].Y);
image.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2);
image.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2);
//ellip.MCvBox2D= CvInvoke.cvFitEllipse2(biggestContour.Ptr);
//image.Draw(new Ellipse(ellip.MCvBox2D), new Bgr(Color.LavenderBlush), 3);
//PointF center;
//float radius;
//CvInvoke.cvMinEnclosingCircle(biggestContour.Ptr, out center, out radius);
//image.Draw(new CircleF(center, radius), new Bgr(Color.Gold), 2);
//image.Draw(new CircleF(new PointF(ellip.MCvBox2D.center.X, ellip.MCvBox2D.center.Y), 3), new Bgr(100, 25, 55), 2);
//image.Draw(ellip, new Bgr(Color.DeepPink), 2);
//CvInvoke.cvEllipse(image, new Point((int)ellip.MCvBox2D.center.X, (int)ellip.MCvBox2D.center.Y), new System.Drawing.Size((int)ellip.MCvBox2D.size.Width, (int)ellip.MCvBox2D.size.Height), ellip.MCvBox2D.angle, 0, 360, new MCvScalar(120, 233, 88), 1, Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED, 0);
//image.Draw(new Ellipse(new PointF(box.center.X, box.center.Y), new SizeF(box.size.Height, box.size.Width), box.angle), new Bgr(0, 0, 0), 2);
filteredHull = new Seq<Point>(storage);
for (int i = 0; i < hull.Total; i++)
{
if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
{
filteredHull.Push(hull[i]);
}
}
defects = biggestContour.GetConvexityDefacts(storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
defectArray = defects.ToArray();
}
}
}
private void DrawAndComputeFingersNum()
{
using (MemStorage storage = new MemStorage())
{
int fingerNum = 0;
#region hull drawing
//for (int i = 0; i < filteredHull.Total; i++)
//{
// PointF hullPoint = new PointF((float)filteredHull[i].X,
// (float)filteredHull[i].Y);
// CircleF hullCircle = new CircleF(hullPoint, 4);
// image.Draw(hullCircle, new Bgr(Color.Aquamarine), 2);
//}
#endregion
#region defects drawing
***defects = new Seq<MCvConvexityDefect>(storage);***
for (int i = 0; i < defects.Total; i++)
{
PointF startPoint = new PointF((float)defectArray[i].StartPoint.X,
(float)defectArray[i].StartPoint.Y);
PointF depthPoint = new PointF((float)defectArray[i].DepthPoint.X,
(float)defectArray[i].DepthPoint.Y);
PointF endPoint = new PointF((float)defectArray[i].EndPoint.X,
(float)defectArray[i].EndPoint.Y);
LineSegment2D startDepthLine = new LineSegment2D(defectArray[i].StartPoint, defectArray[i].DepthPoint);
LineSegment2D depthEndLine = new LineSegment2D(defectArray[i].DepthPoint, defectArray[i].EndPoint);
CircleF startCircle = new CircleF(startPoint, 5f);
CircleF depthCircle = new CircleF(depthPoint, 5f);
CircleF endCircle = new CircleF(endPoint, 5f);
MCvFont angga = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SCRIPT_COMPLEX, 0.5, 0.5);
// image.Draw(defectArray[i].StartPoint.X.ToString() + " , " + defectArray[i].StartPoint.Y.ToString(), ref angga, new Point(defectArray[i].StartPoint.X, defectArray[i].StartPoint.Y), new Bgr(Color.Red));
image.Draw(defectArray[i].StartPoint.X.ToString() + " , " + defectArray[i].StartPoint.Y.ToString() + " , " + i.ToString(), ref angga, new Point(defectArray[i].StartPoint.X, defectArray[i].StartPoint.Y), new Bgr(Color.Red));
//Custom heuristic based on some experiment, double check it before use
if ((startCircle.Center.Y < box.center.Y || depthCircle.Center.Y < box.center.Y) && (startCircle.Center.Y < depthCircle.Center.Y) && (Math.Sqrt(Math.Pow(startCircle.Center.X - depthCircle.Center.X, 2) + Math.Pow(startCircle.Center.Y - depthCircle.Center.Y, 2)) > box.size.Height / 6.5))
{
fingerNum++;
//image.Draw(startDepthLine, new Bgr(Color.Blue), 2);
//image.Draw(depthEndLine, new Bgr(Color.Magenta), 2);
}
image.Draw(startCircle, new Bgr(Color.Red), 2);
image.Draw(depthCircle, new Bgr(Color.Yellow), 5);
//image.Draw(endCircle, new Bgr(Color.DarkBlue), 4);
}
#endregion
MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_DUPLEX, 5d, 5d);
image.Draw(fingerNum.ToString(), ref font, new Point(50, 150), new Bgr(Color.White));
hand.fingerChangedCompute = fingerNum;
}
}
public MemStorage storage { get; set; }
来源看看 DrawandComputeFingersNUm() 你会看到一行
defects = new Seq<MCvConvexityDefect>(storage);
当我取消注释上面的行时会出现问题..
有人知道怎么解决这个问题吗?任何帮助,将不胜感激..谢谢
最佳答案
如您所知,我是您正在使用的代码的创建者。
我的一位读者有时会发现与您类似的问题,评论了我的帖子并建议删除 using Memstorage 并将其全局放置然后清除 DrawAndComputeFingersNum()
函数中的存储
MemStorage storage = new MemStorage() //Global Declaration
private void DrawAndComputeFingersNum()
{
int fingerNum = 0;
#region hull drawing
//for (int i = 0; i < filteredHull.Total; i++)
//{
// PointF hullPoint = new PointF((float)filteredHull[i].X,
// (float)filteredHull[i].Y);
// CircleF hullCircle = new CircleF(hullPoint, 4);
// image.Draw(hullCircle, new Bgr(Color.Aquamarine), 2);
//}
#endregion
#region defects drawing
defects = new Seq<MCvConvexityDefect>(storage);
for (int i = 0; i < defects.Total; i++)
{
PointF startPoint = new PointF((float)defectArray[i].StartPoint.X,
(float)defectArray[i].StartPoint.Y);
PointF depthPoint = new PointF((float)defectArray[i].DepthPoint.X,
(float)defectArray[i].DepthPoint.Y);
PointF endPoint = new PointF((float)defectArray[i].EndPoint.X,
(float)defectArray[i].EndPoint.Y);
LineSegment2D startDepthLine = new LineSegment2D(defectArray[i].StartPoint, defectArray[i].DepthPoint);
LineSegment2D depthEndLine = new LineSegment2D(defectArray[i].DepthPoint, defectArray[i].EndPoint);
CircleF startCircle = new CircleF(startPoint, 5f);
CircleF depthCircle = new CircleF(depthPoint, 5f);
CircleF endCircle = new CircleF(endPoint, 5f);
MCvFont angga = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SCRIPT_COMPLEX, 0.5, 0.5);
// image.Draw(defectArray[i].StartPoint.X.ToString() + " , " + defectArray[i].StartPoint.Y.ToString(), ref angga, new Point(defectArray[i].StartPoint.X, defectArray[i].StartPoint.Y), new Bgr(Color.Red));
image.Draw(defectArray[i].StartPoint.X.ToString() + " , " + defectArray[i].StartPoint.Y.ToString() + " , " + i.ToString(), ref angga, new Point(defectArray[i].StartPoint.X, defectArray[i].StartPoint.Y), new Bgr(Color.Red));
//Custom heuristic based on some experiment, double check it before use
if ((startCircle.Center.Y < box.center.Y || depthCircle.Center.Y < box.center.Y) && (startCircle.Center.Y < depthCircle.Center.Y) && (Math.Sqrt(Math.Pow(startCircle.Center.X - depthCircle.Center.X, 2) + Math.Pow(startCircle.Center.Y - depthCircle.Center.Y, 2)) > box.size.Height / 6.5))
{
fingerNum++;
//image.Draw(startDepthLine, new Bgr(Color.Blue), 2);
//image.Draw(depthEndLine, new Bgr(Color.Magenta), 2);
}
image.Draw(startCircle, new Bgr(Color.Red), 2);
image.Draw(depthCircle, new Bgr(Color.Yellow), 5);
//image.Draw(endCircle, new Bgr(Color.DarkBlue), 4);
}
#endregion
MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_DUPLEX, 5d, 5d);
image.Draw(fingerNum.ToString(), ref font, new Point(50, 150), new Bgr(Color.White));
hand.fingerChangedCompute = fingerNum;
storage.clear(); // clear storage allocation
}
关于c# - EMGU CV 中未处理 AccessViolationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11348384/
我到处都找了很多,找不到我的问题的答案。我试图从这个线程复制一个文本检测软件(Extracting text OpenCV)但是在代码的末尾有一条消息错误说没有匹配的矩形,即使我已经在上面绘制了一个并
我已经彻底搜索过,但没有找到直接的答案。 将 opencv 矩阵 (cv::Mat) 作为参数传递给函数,我们传递的是智能指针。我们对函数内部的输入矩阵所做的任何更改也会改变函数范围之外的矩阵。 我读
在我的应用程序中,我有一个通过引用接收 cv::Mat 对象的函数。这是函数的声明: void getChains(cv::Mat &img,std::vector &chains,cv::
我正在使用 Qt 编写一个 GUI 程序,并使用 OpenCV 进行一些视频处理。我在主 GUI 线程的标签中显示 OpenCV 进程(在单独的线程中)的结果。 我遇到的问题是 cv::waitKey
Mat a = (Mat_(3,3) = 2 int dims; //! the number of rows and columns or (-1, -1) when the arr
我尝试运行下面的代码,但出现错误。我正在为名为“Mat::at”的 OpenCV 函数创建一个包装器,并尝试使用“G++”将其编译为 Ubuntu Trusty 上的“.so”。我在下面列出了“.cp
我在 C# 中使用 EmguCV,当我想从网络摄像头抓取帧时遇到问题,语句中出现红色下划线: imgOrg = capturecam.QueryFrame(); error: Cannot impli
我正在尝试从另外两个矩阵生成一个 cv::Mat C,以便获得第三个矩阵,该矩阵由通过组合矩阵 A 和 B 的一维点生成的二维点构成。 我的问题是,我尝试的所有操作都只是连接矩阵,并没有真正将每个点与
我用 cv.imread在 python 中读取 png 文件。然后当我使用 cv.imwrite立即保存图像的功能我然后发现图像中的颜色略有变化。我正在尝试在此图像上执行字符识别,而 OCR 在 p
我尝试将 cv::bitwise_not 转换为 double 值的 cv::Mat 矩阵。我申请了 cv::bitwise_not(img, imgtemp); img是0和1的CV_64F数据。但
我正在尝试使用函数 cv.glmnet 找到最佳的 lambda(使用 RIDGE 回归)以预测某些对象的归属类别。所以我使用的代码是: CVGLM<-cv.glmnet(x,y,nfolds=34,
我有这个方法: static void WriteMatVect(const std::string& filename, const std::vector& mats); ... void Fil
下面的转换是我想要做的。 对于源图像中的每个图 block ,我知道每个角的坐标,并且我知道输出图像中每个对应角的坐标,所以我可以调用 cvWarpPerspective 扭曲每个图 block ,然
我必须在C++ / CLI中的托管和非托管代码中都使用OpenCV。 我正在尝试在托管代码中使用Emgu CV来包装OpenCV对象,但是在进行转换时遇到了麻烦。 我该怎么做: Emgu::CV::M
我正在尝试在 cv::Mat 中使用 CV_32FC4,以便它存储 RGBA32 图像。但是当我使用 cv::imwrite 将其保存为 png 文件时,结果文件始终是一个空图像。 例如,我创建了这样
无法在 VS 2017 中设置 OpenCV。我做错了什么?是的,我已将所有其他帖子设为红色。 代码: #include "opencv2/highgui/highgui.hpp" u
我有两个(相同大小,相同类型)cv:Mat 让我们称它们为 A,B。我还有另一个 cv::Mat,它是一个掩码(0 和 1 值或其他值,0 和 255 也适用)让我们称它为 M。 我需要构造一个新的
使用 OpenCV 中实现的 Scalar 类,我不明白这段代码有什么区别: Mat test; test = Scalar::all(0); 还有这个: Mat test = Scalar::all
我对这行代码感到困惑: cv::Mat_::iterator 我知道 Mat_ 属于 cv 命名空间和 vec3b 也。但是之后的最后一个 :: 操作符和 iterator 让我感到困惑!它也属于 c
我想优雅地将 Mat 转换为 Vec3f。目前我是这样做的: Mat line; Vec3f ln; ln[0] = line.
我是一名优秀的程序员,十分优秀!