0

I'm building an image processing application using Emgu CV (for x64) and I want to use the filtering functions on images. So, I use opencv_imgproc.dll but it throws BadImageFormatException

Solution Platform : x86 
Operating System : Windows 7 - 64
Language: C# 
IDE: Visual C# 2010 express 
Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
Shimaa
  • 477
  • 1
  • 6
  • 16
  • Have you seen http://stackoverflow.com/questions/5229310/system-badimageformatexception-could-not-load-file-or-assembly? – nick_w Nov 01 '12 at 04:34
  • yes , all the comments talk about a x64 vs x84 issue , i tried changing it before to x64 or AnyCPU but it throw "Emgu.CV.CvInvoke" exception when i use Emgu CV basic functions, – Shimaa Nov 02 '12 at 05:15
  • Can you show the exception stack trace for that error? Also, where are the OpenCV DLLs located in your solution? From memory Emgu expects these to be in a certain location. – nick_w Nov 02 '12 at 05:20
  • @NickW it located @ the bin folder next to the .exe , other .DLLs work just fine , you want me exception stack for the "BadImageFormatException"? – Shimaa Nov 02 '12 at 05:52
  • Could you include the stack traces for both errors? – nick_w Nov 02 '12 at 05:56
  • for the "BadImageFormatException" : http://pastie.org/5170481 for the " Emgu.CV.CvInvoke" : http://pastie.org/5170499 – Shimaa Nov 02 '12 at 06:01
  • Based on those exceptions, it seems like you are using the 32-bit version on Emgu. Try setting `Platform target` to x86 in the Build properties for your project. – nick_w Nov 02 '12 at 06:09
  • @NickW the platform is set to x86 already and the 1st exception still there , and when i changed it to x64 the second exception appeared , the only thing that solved the issue is using the Emgu library for x86 instead of for x64 despite that the OS is x64 .I'm just asking if that will cause future problems as the X86 is working happily @ the x64 OS now , and why the x64 platform didn't work with the X64 library and x64 OS ? thanks a lot for your efforts – Shimaa Nov 02 '12 at 06:19
  • The x86 version of Emgu will happily run on either an x64 or x86 OS, but you will need to be targetting x86 (as you are now) in Visual Studio for it to work. Did that suggestion of mine work? If so then I will post it as the answer - if you could then accept it that would be great. – nick_w Nov 02 '12 at 06:30
  • you suggested to set the platform to x86, it will work with the x86 Emgu only not the x64 and the x64 Emgu won't work for both platforms till now and that's the problem, you may post it as an answer for sure just add that comment as the question is stating that I'm using a x86 platform already , just no to get the user confused , thanks – Shimaa Nov 02 '12 at 06:38

1 Answers1

1

Emgu is a managed wrapper for OpenCV. Because OpenCV is unmanaged, you will need to ensure that you are compiling with the correct settings for the version of Emgu you are using.

Based on the exceptions posted in the comments (http://pastie.org/5170481 and http://pastie.org/5170499 for reference), the Emgu version being compiled against is the x86 one, meaning that the OpenCV DLLs it depends on will need to be compiled for 32-bit . For your code to run, the Platform target in the Build settings of you project needs to be set to x86, regardless of the bitness of the OS you are running on.

To use the 64-bit version of Emgu, you will need to download a version compiled for 64-bit (you can see the different options here) and then set the Platform target to x64.

nick_w
  • 14,758
  • 3
  • 51
  • 71