1

I have a Visual Studio solution (all code in C#) that has the structure:

MySolution
|
+--MyLibrary (DLL library)
|
+--MyMVCSite (MVC 5 site)
|
+--MyConsoleApp (Console app)

MyLibrary references the Emgu.CV DLLs, which are a set of C# wrappers for the unmanaged library OpenCV. And I have all the OpenCV dlls being "Copy always" to the bin directory on building.

Now here is the issue. In MyConsoleApp, program.cs, I have the code:

MyLibrary mylib = new MyLibrary();
Image img = Image.FromFile(@"c:\\cat.jpg");
using (MemoryStream ms = new MemoryStream()) {
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    arr = ms.ToArray();
    mylib.Process(arr);
}

which calls the MyLibrary code:

public void Process(byte[] buffer) {
    PreprocessImage(buffer, true);
}

private Image<Gray, byte> PreprocessImage(byte[] buffer, bool resize) {

    Image<Gray, byte> grayImage;
    using (MemoryStream mss = new MemoryStream(buffer)) {
        Bitmap bmpImage = (Bitmap)Image.FromStream(mss);

        Image<Bgr, byte> img = new Image<Bgr, byte>(bmpImage); // <-- Emgu.CV type
        // More processing on img

    }
}

and everything succeeds. The variable img (which is built via Emgu.CVs wrapper functions to OpenCV) is set correctly and can be processed downstream, etc.

HOWEVER, when I try to repeat the exact same code from MyConsoleApp in the HomeController.cs of MyMVCSite using the code (in HomeController.cs), I get a runtime error on the line: Image<Bgr, byte> img = new Image<Bgr, byte>(bmpImage); stating {"Unable to load DLL 'opencv_core300': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"}

Both MyConsoleApp MyMVCSite reference MyLibrary, yet the console app works and the MVC app does not, despite using the same exact code to call MyLibrary. Does anyone have any idea what could be going on? I repeated this in a barebones project, and the behavior is still see the same thing.

UPDATE

I've posted my barebones project that shows this behavior at: https://github.com/brspurri/Test Still at a total loss here.

tereško
  • 58,060
  • 25
  • 98
  • 150
Brett
  • 11,637
  • 34
  • 127
  • 213
  • I'm guessing the MyMVCSite has settings included that the console does not, and under the hood it tries to load more things in. Have you seen this: http://stackoverflow.com/questions/9509702/installing-opencv-highgui-missing? – Nerf Herder Nov 21 '14 at 22:45
  • I agree, there must be a setting difference, possible related to my visual studio settings. I'm not sure though, and I don't even know where to begin to look. Any advice? The SO question you suggested doesn't seem to help. – Brett Nov 22 '14 at 15:01
  • Thanks for retired the negative points in my answer, I find the response, EnguCv don't work with IIS Express, change the project properties to use Local IIS, more details in my answer (http://stackoverflow.com/questions/26634157/how-use-emgucv-in-a-mvc-net-project/27080126#27080126) – chefjuanpi Nov 22 '14 at 17:14

0 Answers0