2012-09-19 3 views
2

EMGUCV를 C#으로 사용하려고합니다. 현재 Visual Studio 2010 Express Edition을 설치했습니다. 몇 가지 간단한 명령을 실행하려고하면 Emgu.CV.CvInvoke 예외가 발생하여 관리되지 않는 코드가 exe 폴더에 저장됩니다. 그러나 여전히 그것은 나에게 오류를주고있다. 그래서 솔루션 익스플로러에 관리되지 않는 코드를 추가하려고 시도했지만 여전히이 오류가 발생합니다. 내가 할 수있는 일이 또 있나요? 결국 emguCV를 사용할 수 있습니까?Emgu.CV.CvInvoke '예외가 throw되었습니다.

예외

System.TypeInitializationException was unhandled 
    Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception. 

갖는 스택 트레이스이다

at Emgu.CV.CvInvoke.cvCreateCameraCapture(Int32 index) 
    at Emgu.CV.Capture..ctor(Int32 camIndex) in C:\Program Files (x86)\Emgu\libemgucv-windows-x64-2.2.1.1150\Emgu.CV\Capture\Capture.cs:line 105 
    at Emgu.CV.Capture..ctor() in C:\Program Files (x86)\Emgu\libemgucv-windows-x64-2.2.1.1150\Emgu.CV\Capture\Capture.cs:line 93 
    at cameraWorks.Form1.camButton_Click(Object sender, EventArgs e) in C:\Users\Adrian\documents\visual studio 2010\Projects\cameraWorks\cameraWorks\Form1.cs:line 38 
    at System.Windows.Forms.Control.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
    at System.Windows.Forms.Button.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
    at System.Windows.Forms.Application.Run(Form mainForm) 
    at cameraWorks.Program.Main() in C:\Users\Adrian\documents\visual studio 2010\Projects\cameraWorks\cameraWorks\Program.cs:line 18 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

의 InnerException :

InnerException: System.BadImageFormatException Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Source=Emgu.CV StackTrace: at Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata) at Emgu.CV.CvInvoke..cctor() in C:\Program Files (x86)\Emgu\libemgucv-windows-x64-2.2.1.1150\Emgu.CV\PInvoke\CvInvoke.cs:line 50

I 단지 간단한 코드 존재 실행하고 :

public partial class Form1 : Form 
{ 
    private Capture capture; 
    private bool captureInProgress; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void ProcessFrame(Object sender, EventArgs args) 
    { 
     Image<Bgr, Byte> ImageFrame = capture.QueryFrame(); 
     CamImageBox1.Image = ImageFrame; 
    } 

    private void camButton_Click(object sender, EventArgs e) 
    { 
     if (capture == null) 
     { 
      try 
      { 
       capture = new Capture(); 
      } 
      catch (NullReferenceException excpt) 
      { 
       MessageBox.Show(excpt.Message); 
      } 
     } 

     if (capture != null) 
     { 
      if (captureInProgress) 
      { 
       camButton.Text = "start"; 
      } 
      else 
      { 
       camButton.Text = "stop"; 
       Application.Idle += ProcessFrame; 
      } 
      captureInProgress = !captureInProgress; 
     } 
    } 

    private void ReleaseData() 
    { 
     if (capture != null) 
     { 
      capture.Dispose(); 
     } 
    } 
012,351을

emguCV 예제는 내 컴퓨터에서 작동합니다. 고마워 Adrian

+1

아마 예외의 세부 사항이 도움이 될 것입니까? – John3136

+0

정확히 예외는 무엇입니까? 메시지 및 스택 트레이스가 도움이 될 것입니다. –

+0

done stacktrace 및 예외 –

답변

2

다음 오류 : "잘못된 형식의 프로그램을로드하려고했습니다." .NET 코드가 현재 실행되고있는 플랫폼과 다른 플랫폼에 대해 관리되지 않는 어셈블리가 컴파일 된 경우 표시됩니다.

예 : x86 용으로 컴파일 된 일부 DLL을 가져 와서 C#에 대한 일부 함수 호출을 가져 와서 실행합니다. 64 비트 Windows를 사용하는 경우. NET 코드가 x64로 컴파일되기 때문에 실패합니다.

당신이 두 가지 가능성이이 문제를 해결하려면 다음) 1) 플랫폼 이 일치되지 않는 DLL 버전을 사용하기를 프로젝트 -> 속성 -> 빌드 -> 관리되지 않는 DLL을 컴파일하는 플랫폼에 맞는 플랫폼을 선택합니다 (x86, x64) (아마도 Any CPU로 설정 됨).


은하지 일부 하위 폴더에 \ 빈 \ 디버그 및/또는 \ 빈 \ 릴리스 프로젝트로 관리되지 않는 DLL을 복사! 일부 하위 폴더에서 dll을 사용하려면 다음과 같이 프로세스 환경 변수를 편집하십시오.

Environment.SetEnvironmentVariable (경로, Environment.GetEnvironmentVariable (경로) + Path.PathSeparator +);

이렇게하면 검색 경로에 하위 폴더가 추가됩니다. 이 변수는 프로세스 변수로서 프로세스의 실행이 중지되면 모든 변경 사항이 실행 취소됩니다.

관련 문제