我正在开发一个项目,我希望用户能够导入视频。每当我选择要导入的视频时,public class CvString : UnmanagedObject
都会给我一个System.TypeInitializationException
错误。这不依赖于数据类型,它不适用于.jpeg
或.png
等图片,也不适用于我尝试的任何视频格式(.avi``.mp4``.wmp
)< / 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
答案 0 :(得分:1)
我曾经遇到过同样的问题,我不知道它是否对你有帮助,但是试试看。
只需将cvextern
,msvcp120
,msvcr120
和opencv_ffmpeg300_64
dll拖放到项目中即可。它们应位于emgu...\bin\x64\
。
这应该可以解决您的DllNotFoundException
,也可能是其他问题。