【问题标题】:TypeInitializationException trown while importing Video with EmguCV使用 EmguCV 导入视频时出现 TypeInitializationException
【发布时间】:2015-12-08 17:53:58
【问题描述】:

我正在开展一个项目,希望用户能够导入视频。每次,当我选择要导入的视频时,public class CvString : UnmanagedObject 都会向我抛出 System.TypeInitializationException 错误。这不取决于数据类型,它不适用于图片,例如.jpeg.png,也不适用于我尝试过的任何视频格式 (.avi``.mp4``.wmp)

这是我要加载和显示视频的sn-p(自己写的代码)

OpenFileDialog ofd = new OpenFileDialog();
Capture _capture;
Timer My_Time = new Timer();
int FPS = 30;
public Form1()
{
    InitializeComponent();
    //Frame Rate
    My_Time.Interval = 1000 / FPS;
    My_Time.Tick += new EventHandler(timer1_Tick);
    My_Time.Start();

    _capture = new Capture("20151102_110553.mp4");

}

private void timer1_Tick(object sender, EventArgs e)
{
    imageBox1.Image = _capture.QueryFrame();
}


private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
    _capture = new Capture(openFileDialog1.FileName.ToString());
}

private void button2_Click(object sender, EventArgs e)//Import-Button
{
     openFileDialog1.ShowDialog();
}

这里是抛出异常的方法(来自 Emgu.CV 的代码)

namespace Emgu.CV
{
   public class CvString : UnmanagedObject
   { 
        private bool _needDispose;

        internal CvString(IntPtr ptr, bool needDispose)
        {
             _ptr = ptr;
             _needDispose = needDispose;
        }

        public CvString(String s)
        {
        if (s == null)
            {
                _ptr = CvInvoke.cveStringCreate();
            }
        else
        {
            byte[] bytes = Encoding.UTF8.GetBytes(s);
            Array.Resize(ref bytes, bytes.Length + 1);
            bytes[bytes.Length - 1] = 0; //The end of string '\0' character
            GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
            _ptr =CvInvoke.cveStringCreateFromStr(handle.AddrOfPinnedObject());
            // ^ Exception is thrown ^
            handle.Free();
        }

        _needDispose = true;
    }

我已经尝试将视频或图片导入我的项目,在启动项目时直接导入,或者在运行时使用OpenFileDialog 选择文件,但结果相同。一旦我选择了一个文件并将其加载到我的项目中,就会抛出异常。

编辑:添加堆栈跟踪

堆栈跟踪

No suitable directory found to load unmanaged modules
Exception thrown : "System.DllNotFoundException" in Emgu.CV.dll
Exception thrown : "System.TypeInitializationException" in Emgu.CV.dll
Thread 0xa64 ended with Code 0 (0x0).
Exception thrown : "System.TypeInitializationException" in Emgu.CV.dll
Exception thrown : "System.TypeInitializationException" in Emgu.CV.dll
Exception thrown : "System.TypeInitializationException" in Emgu.CV.dll

【问题讨论】:

  • . 文件中是否有静态变量? . .该课程的一部分?你能添加堆栈跟踪吗?
  • 我添加了... 部分的代码。堆栈跟踪是什么意思?
  • 当你捕捉到一个异常,或者当调试器捕捉到一个异常时,检查异常详细信息中的 StackTrace 属性。 StackTrace是一个字符串,你可以复制粘贴到这里
  • 整张太大了,抛出异常的部分我取了。
  • 这不是堆栈跟踪,但至少有消息。我认为它正在寻找 Assets\Plugins 文件夹并且找不到它。您可以使用 sys internals 中的 Process Monitor 来查看它正在寻找的目录。

标签: c# exception video exception-handling emgucv


【解决方案1】:

我也遇到过同样的问题,不知道对你有没有帮助,试试看吧。

只需将cvexternmsvcp120msvcr120opencv_ffmpeg300_64 dll 拖放到您的项目中。它们应该位于emgu...\bin\x64\

这应该可以修复您的 DllNotFoundException,也许还有其他问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多