Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

Adding OpenVino to a new project

wsla
Beginner
4,333 Views

I am trying to add OpenVino to C++ dll project, which will be used in an existing C# Windows application. I can build and run all samples using Visual Studio 2017. Now, I tried creating a new C++ dll project, but I can't figure out how to include all of the references to OpenVino libraries. Is there any manual/tutorial how to add it to new projects? I tried copying settings from the sample, but I am getting bunch of errors, and solving one brings out even more..

0 Kudos
27 Replies
Lee__Terry
Beginner
3,594 Views

I'm facing the same challenge. Did anybody able to convert one of the sample c++  exe program to DLL ?

Thanks in advance. 

Terry

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi wsla, Terry,

 >  Did anybody able to convert one of the sample c++  exe program to DLL ?

Yes.

What errors are you getting? Could you tell us more about your environment / OS / tools versions etc?

It is straightforward integration effort but requires to work around a few issues.

> getting bunch of errors, 

Errors-errors or warnings that were treated as errors?

Cheers,

Nikos

 

0 Kudos
wsla
Beginner
3,594 Views

I got it after couple of days of trying different things, I am a C# developer so I don't know as much about C++ solutions therefore it wasn't easy. I basically created new project and copied almost all linking, includes and pre-processor directives etc. from one of the samples. Than slowly changed it into a dll which I now use in the C# application.

It would be good if there would be tutorial covering it.

0 Kudos
Lee__Terry
Beginner
3,594 Views

Thanks wsla,

It's good to know that I'm on the right path.

I'm using similar steps. But still not working. Is it possible to share your DLL project ?

The steps I used are:

1. generate a new c++ DLL project.

2. Copy all the parameters for the project configuration properties from a sample to new DLL project.

3. Copy the functions  from the sample program.

Error occurred on the line 

InferencePlugin plugin = PluginDispatcher({ "../lib/intel64", "" }).getPluginByDevice(FLAGS_d);

Error    C2664    'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>::basic_string(const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> &)': cannot convert argument 1 from '_Ty' to 'std::initializer_list<_Elem>'    locationDLL    c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\xmemory0    881    
environment:

VS 2017, windows 10, c++ ,C#, openvino r5, object_detection_demo_yolov3_async

 

Any idea or suggesting would be greatly appreciated.

Terry

 

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi Terry,

In your project in line 16 of computer_vision_sdk\deployment_tools\inference_engine\include\ie_plugin_dispatcher.hpp is 

UNICODE 

defined or not?

0 Kudos
Lee__Terry
Beginner
3,594 Views

It's no

t define. How do I define it ?

LN 16 namespace InferenceEngine {
LN 17/**
LN 18* @brief This is a class to load a suitable plugin
LN 19*/
LN 20 class PluginDispatcher {

Thanks
 

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Well, the reason I am saying this is because in my case I had to undefine UNICODE in ie_unicode.hpp and ie_plugin_dispatcher.hpp

Depends on your project - you may want to try and test with

#ifdef UNICODE
#undef UNICODE
#endif

or change makefile / visual studio solution to see if it compiles.

0 Kudos
Lee__Terry
Beginner
3,594 Views

Hi Nikos,

With you tips about unicode, I was able to go pass compiling issue. However, I'm still not able to run the DLL. I have spend days on trying to converting exe to DLL without much success. Could you provide a simple DLL that contain interference plug in ? Since I'm not familiar with C++, it's very hard to figuring out all the errors shows up during the process.

Thanks,

Terry

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi Terry,

Happy to see UNICODE tips resolved the compiler issue.

>  Could you provide a simple DLL that contain interference plug in 

Sorry, not easy to provide a dll as it project dependent but would be happy to help if you can let us know the errors you are seeing.

Cheers,

Nikos  

0 Kudos
Lee__Terry
Beginner
3,594 Views

Nikos,

Understand,

The current error is "Access violation" . when running on DLL.

The sample that I'm following is "hello_classification".

Key Steps:

1. generate a DLL project.

2. copy configure parameters from hello_classification.

3. generate C# project to call the DLL with function init().

4. copy two lines of code from hello_classification.

    PluginDispatcher dispatcher({ _T("../../../lib/intel64"), _T("") });
    InferencePlugin plugin(dispatcher.getSuitablePlugin(TargetDevice::eCPU));

   The error occur on the second line.

   The problem is at line "if (InferenceEngine::OK != findPlugin({ device }, result, &desc)) {" on file ie_plugin_dispatcher.hpp.

For some reason, the result size is huge instead of 1.

Thanks for your helps,

Terry

  

 

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi Terry,

I believe this is still a UNICODE issue - was getting similar issues when loading OpenVino plug-ins.

https://docs.microsoft.com/en-us/windows/desktop/learnwin32/working-with-strings

In the samples UNICODE is defined. In your application you may have to undefine.  I would suggest you write a minimal app that just loads the plug-in (or maybe this is what you are already doing). Then search headers for UNICODE sections and make sure they are grayed out.  Use the debugger in a debug build to confirm that you are getting the proper plug-in name string.

Also what happens if you load by device name like for example

openVinoPlugin = InferenceEngine::PluginDispatcher({ "","./lib" }).getPluginByDevice("CPU");

Also make sure you copy all required OpenVino dlls to your product build directory. Note when you run form Visual Studio this may be another location.

Good Luck!

Nikos

0 Kudos
Lee__Terry
Beginner
3,594 Views

Hi nikos,

Thanks for continue helping. I gave it a quick try on all the suggestions and have not make any progress yet. One question regarding to the input parameters is "./lib".

Is this the directory to the  library ? or to DLL plugIn like "myriadPlugind.dll".

Thanks,
Terry

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi Terry,

> Is this the directory to the  library ? or to DLL plugIn like "myriadPlugind.dll".

It is the  the directory to the plugin (  * @param pp Vector of paths to plugin directories )

Try to add a breakpoint and debug PluginDispatcher   : computer_vision_sdk\deployment_tools\inference_engine\include\ie_plugin_dispatcher.hpp

namespace InferenceEngine {
/**
* @brief This is a class to load a suitable plugin
*/
class PluginDispatcher {
public:
    /**
     * @brief A constructor
     * @param pp Vector of paths to plugin directories
     */
    explicit PluginDispatcher(const std::vector<file_name_t> &pp) : pluginDirs(pp) {}

    /**
    * @brief Loads a plugin from plugin directories
    * @param name Plugin name
    * @return A pointer to the loaded plugin
    */
    virtual InferencePlugin getPluginByName(const file_name_t& name) const {

 

Cheers,

nikos

0 Kudos
Lee__Terry
Beginner
3,594 Views

Hi Nikos,

I step through the up the PluginDispatcher  procedure as you suggested. The directories seems OK . 

The issue is at the procedure: InferenceEnginePluginPtr getSuitablePlugin(TargetDevice device) const

Line: if (InferenceEngine::OK != findPlugin({ device }, result, &desc)) 

When run on exe: The result size is = 1

When run on DLL: The result size is =   576460752303418732

the data looks corrupts: [0] = "0‹[!æ\x1"

I'm not able to figure out the reason for the difference.

Note: 

Command line:     InferencePlugin openVinoPlugin = InferenceEngine::PluginDispatcher({ "" ,"C:\\Intel\\computer_vision_sdk_2018.5.445\\deployment_tools\\inference_engine\bin\intel64\\Debug" }).getPluginByDevice("CPU");

Environment:

windows 10, vs2017, openvino R5.

I'm out of idea to try. Any though could be greatly appreciated.

Thanks,

Terry

 

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi Terry,

Sorry to hear the issue is still here. Some deltas from your setup is that in my dll / integration project I am using VS2015 not VS2017 so I have not tested for VS2017 issues. I am also building release (and debugging my release builds :-) ) . I had some issues before with earlier versions of the SDK with debug builds so I stick to Release for now. It all works fine. Main issue I had was similar to yours, around plug-in dispatcher but after fixing UNICODE it loaded properly all plug-ins provided all dlls can be found in the path.

Is it possible to get a very minimal visual studio project that can repro the issue? I think a simple C++ program that loads the plug-n should repro the issue. If so can you attach here for us to diagnose and help resolve the issue?

Also safer compiler versions, and flag and other parameters used to compile the dll and application to be the same to avoid any issues.

Thanks,

Nikos

0 Kudos
Lee__Terry
Beginner
3,594 Views

Hi Nikos,

Thanks for the suggestions. I know how hard is to try to help without knowing the details.

I manage to get pass the plug in and loading the network. Now I have some errors on the reading images.

on the line "FormatReader::ReaderPtr reader(i.c_str());". I got the error message

System.IO.FileNotFoundException: 'Could not load file or assembly 'Wrapper.dll' or one of its dependencies. The specified module could not be found.' 

I try everything and could not figure out the dependent DLL that is missing.

The sample program is Classification_sample. Any idea or things that I can try?

Thanks,

Terry

 

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi Terry,

Happy to hear plugin issue is now resolved.I am not using FormatReader in my applications as I do my own custom reading and image processing. In any case please make sure the format_reader.dll can be found, should be accessible preferably in the same place as inference_engine.dll

You could also use tools like the Dependency Walker (or ldd -r on Linux) to see and help resolve any other dependencies.

Cheers,

Nikos

0 Kudos
Lee__Terry
Beginner
3,594 Views

Hi Nikos,

Thanks again for your helps. I manage to compile the sample program "Classification_sample" with DLL (c++/cli) without error. However, there still an issue when running the program. After tracking down the issue by comparing between the DLL and EXE (working), the source of the issue is at the line: 

CNNNetReader network_reader;

I generated an DLL and EXE with just this line of code. The parameter network_reader with not data under actual on DLL and with data on EXE.  I could not figure out the reason for it. Please view that attached screen images.

I could not figure out the reason for it. Please take a look and see of you can think of any reason for it.

Thanks again.  

 

0 Kudos
nikos1
Valued Contributor I
3,594 Views

Hi Terry,

Good progress, glad to hear you were successful in compiling the sample program.

I am not sure what the other issue is, could not see anything wrong in the attachments but it could be some setting in the visual studio project. Could you possibly share a minimal VS project and minimal source files to try to repro and debug here?

Thanks,

Nikos

0 Kudos
Lee__Terry
Beginner
3,173 Views

Hi Nikos, Thanks for the quick reply. 

Attached are the  c++/cli and c# projects with one line of code.

The product is created at directory: C:\Users\trafficcountuser\Documents\Intel\OpenVINO\inference_engine_samples_2017\CLIExample.

environment: vs2017, openCV v5 windowns 10

Terry  

0 Kudos
Reply