简体   繁体   English

教程如何在Asp.Net MVC应用程序中使用EmguCV

[英]Tutorial how to use EmguCV in Asp.Net MVC application

I created prove-of-concept console application, which is using EmguCV for template matching. 我创建了概念验证控制台应用程序,该应用程序使用EmguCV进行模板匹配。 Version of openCV is 2.4. openCV的版本是2.4。

Now I have problems with my real-life asp.net mvc application. 现在,我的现实生活中的asp.net mvc应用程序出现了问题。 I have a runtime error: 我有一个运行时错误:

The type initializer for 'Emgu.CV.CvInvoke' threw an exception. 'Emgu.CV.CvInvoke'的类型初始值设定项引发了异常。 System.DllNotFoundException: Unable to load DLL 'opencv_core2410': The specified module could not be found. System.DllNotFoundException:无法加载DLL'opencv_core2410':找不到指定的模块。

Saw several other question, but they are incomplete or don't have answers: 看到了其他几个问题,但是它们不完整或没有答案:

  1. How use EmguCV in a MVC.NET project 如何在MVC.NET项目中使用EmguCV

  2. Error:The type initializer for 'Emgu.CV.CvInvoke' threw an exception 错误:“ Emgu.CV.CvInvoke”的类型初始值设定项引发了异常

What I've already tried: 我已经尝试过的:

  1. Copied folders x64 and x86 from EmguCV installation into published bin folder(these folders contains opencv dlls) 将EmguCV安装中的x64和x86文件夹复制到已发布的bin文件夹中(这些文件夹包含opencv dll)

  2. Added opencv dlls to my web project and set them to "Copy to output directory" as described here: http://www.codeproject.com/Articles/257502/Creating-Your-First-EMGU-Image-Processing-Project 将opencv dll添加到我的Web项目中,并将它们设置为“复制到输出目录”,如下所述: http : //www.codeproject.com/Articles/257502/Creating-Your-First-EMGU-Image-Processing-Project

  3. Please note, it's working well in concole application, but not in mvc. 请注意,它在concole应用程序中运行良好,但在mvc中却不能。

Well, I couldn't find normal solution for this problem. 好吧,我找不到这个问题的正常解决方案。

In the topic How use EmguCV in a MVC.NET project there is an info, that EmguCV works with IIS only, not IIS Express. 如何在MVC.NET项目中使用EmguCV主题有一个信息,EmguCV仅适用于IIS,不适用于IIS Express。 Nope, I've got the same error with it even published on our prod server. 不,我什至在我们的产品服务器上发布了同样的错误。

So the only way, how it worked for me was: 因此,唯一的方法是:

  1. Create console app, which uses EmguCV and process my images. 创建控制台应用程序,它使用EmguCV并处理我的图像。
  2. Call it from .net mvc app as .exe file with parameters. 从.net mvc应用程序以带有参数的.exe文件调用它。

I'm marking my question as answered, but this is more a dirty hack, than a good solution. 我将我的问题标记为已回答,但这不是一个好的解决方案,而是更多的肮脏技巧。

the solution from How use EmguCV in a MVC.NET project MVC.NET项目中如何使用EmguCV的解决方案

is partially correct, there are two main changes that need to be made before EMGU will work under IIS 是部分正确的,在EMGU在IIS下运行之前,需要进行两个主要更改

  1. activate your app_pool for the application for running 32 bit https://help.webcontrolcenter.com/kb/a1114/how-to-enable-32-bit-application-pool-iis-7-dedicatedvps.aspx 为运行32位https://help.webcontrolcenter.com/kb/a1114/how-to-enable-32-bit-application-pool-iis-7-dedicatedvps.aspx的应用程序激活app_pool

  2. then you need to go to the application \\bin folder, grant the file security for the folder "x86" (which contains all the dll for emgu) as described in following link http://www.iis.net/learn/manage/configuring-security/application-pool-identities 然后您需要转到应用程序\\ bin文件夹,为文件夹“ x86”(包含emgu的所有dll)授予文件安全性,如以下链接http://www.iis.net/learn/manage/中所述配置安全性/应用程序池标识

    if your apppool being in used in defaulapppool, then you should add user "IIS AppPool\\DefaultAppPool" 如果您的应用程序池在defaulapppool中使用,则应添加用户“ IIS AppPool \\ DefaultAppPool”

this took me 5 hours to figure out!!! 这花了我五个小时才弄清楚!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM