3
我使用的是Emgu 2(使用opencv 2.4.10.1的那個),並且運行非常穩定,並且可以在不崩潰的情況下運行。我現在已經升級到Emgu 3.1.0.1,並且我的應用程序有時會在幾個小時或一天內崩潰並導致AccessViolationException。我已經看到它現在在兩個不同的地點墜毀。請參閱下面源代碼中標記的兩個位置(CRASH1 & CRASH2)。所以我認爲這裏有一些根本性的錯誤。Emgu AccessViolationException在從Emgu 2升級到Emgu後隨機發生3.1.0.1
我正在運行軟件的發佈版本。任何人有什麼想法可能會發生在這裏?
的CRASH1例外是:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
at Emgu.CV.CvInvoke.cveSubtract(IntPtr, IntPtr, IntPtr, IntPtr, Emgu.CV.CvEnum.DepthType)
at Emgu.CV.CvInvoke.Subtract(Emgu.CV.IInputArray, Emgu.CV.IInputArray, Emgu.CV.IOutputArray, Emgu.CV.IInputArray, Emgu.CV.CvEnum.DepthType)
at Emgu.CV.RotationMatrix2D.CreateRotationMatrix(System.Drawing.PointF, Double, System.Drawing.Size, System.Drawing.Size ByRef)
at Emgu.CV.Image`2[[Emgu.CV.Structure.Bgr, Emgu.CV.World, Version=3.1.0.2282, Culture=neutral, PublicKeyToken=7281126722ab4438],[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Rotate(Double, System.Drawing.PointF, Emgu.CV.CvEnum.Inter, Emgu.CV.Structure.Bgr, Boolean)
at Emgu.CV.Image`2[[Emgu.CV.Structure.Bgr, Emgu.CV.World, Version=3.1.0.2282, Culture=neutral, PublicKeyToken=7281126722ab4438],[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Rotate(Double, Emgu.CV.Structure.Bgr, Boolean)
at XXXX.ProcessFrames()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
的CRASH2例外是:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
at Emgu.CV.Util.VectorOfMat.VectorOfMatPush(IntPtr, IntPtr)
at Emgu.CV.Util.VectorOfMat..ctor(Emgu.CV.Mat[])
at XXXX.ProcessFrames()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
的源代碼是:
public void start()
{
started = true;
// start processing camera frames
cameraThread = new Thread(new ThreadStart(ProcessFrames));
cameraThread.IsBackground = true;
cameraThread.Start();
}
private void ProcessFrames()
{
Bgr frameBg = new Bgr(0,0,0);
while (true)
{
// try to open the camera device
if (capture == null)
{
try
{
int index;
bool isNumeric = int.TryParse(ConfigurationManager.AppSettings["CameraSource"], out index);
capture = isNumeric ? new Capture(index) : new Capture(ConfigurationManager.AppSettings["CameraSource"]);
capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth, 640);
capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight, 480);
capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FourCC, Emgu.CV.VideoWriter.Fourcc('M', 'J', 'P', 'G'));
}
catch
{
frameObservers.ForEach(a => a.frame(cameraNotConnectedBitmap, new List<Person>(), recognizer.isActive()));
}
Task.Delay(1000).Wait();
continue;
}
// read a frame from the camera
Mat matFrame = capture.QueryFrame();
Image<Bgr, byte> frame = null;
if (matFrame != null)
{
frame = matFrame.ToImage<Bgr, byte>();
}
if (frame == null)
{
frameObservers.ForEach(a => a.frame(cameraNotConnectedBitmap, new List<Person>(), recognizer.isActive()));
capture = null; // force to reconnect to camera again
Task.Delay(1000).Wait();
continue;
}
try
{
CRASH1 >>>frame = frame.Rotate(Convert.ToInt32(ConfigurationManager.AppSettings["CameraRotation"]), frameBg, false);
double scale = Convert.ToDouble(ConfigurationManager.AppSettings["CameraScale"]);
if (scale > 0)
{
frame = frame.Resize(scale, Emgu.CV.CvEnum.Inter.Linear);
}
Global.FRAME_HEIGHT = frame.Height;
Global.FRAME_WIDTH = frame.Width;
rawCameraFeedFrameObservers.ForEach(a => a.frame(frame));
if (autoBrightness)
{
Image<Lab, Byte> lab = frame.Convert<Lab, Byte>();
Image<Gray, Byte>[] planes = lab.Split();
CvInvoke.CLAHE(planes[0], claheClipLimit, new Size(8, 8), planes[0]);
CRASH2 >>>VectorOfMat vm = new VectorOfMat(planes[0].Mat, planes[1].Mat, planes[2].Mat);
CvInvoke.Merge(vm, lab);
frame = lab.Convert<Bgr, Byte>();
}
}
catch
{
// not the end of the world
Log.INFO("INFO", "Processing the frame failed, skipping this frame");
continue;
}
}
}
這看起來像一個更大的應用程序的一個線程,您的問題可能在其他地方,並可能與某種競爭條件或非託管數據的其他處理不當,那根本就沒有與以前的庫版本 – slawekwin
的表現出來線程基本上從攝像頭抓取一幀,在代碼中看到它,然後將其發佈到UI線程,UI線程將該幀的位圖顯示在屏幕上。 UI線程中的代碼無論如何都不會操縱該框架。所以我看不出它會如何創建訪問衝突。 – rukiman
我建議你處置每個一次性物品(即墊子)我在我的EMGU嘗試(特別是與BOW相關的調用)上有訪問違規問題。我已經開始使用OpenCVSharp,現在everyhing更穩定。但最新版本有一些我使用的serios問題:https://www.nuget.org/packages/OpenCvSharp3-AnyCPU/3.2.0.20170324 – Koray