Compile OpenCV 3 for Windows 10 IoT Core ARM (Rasp

2020-06-23 09:13发布

问题:

What is the easiest way compile OpenCV 3.* for Windows 10 IoT Core ARM (Raspberry Pi) using Visual Studio hosted on Windows OS?

Can I use DNN (Deep Neural Network) module among other contrib modules?

回答1:

I struggled a bit trying to compile OpenCV 3.4.1 for Windows 10 IoT Core (10.0.16299.0) running on Raspberry Pi 3, so I decided to share my experience with the community.

Requirements

All you need to proceed is:

  • OpenCV sources (from Github). opencv for core functionality and opencv_contrib for additional modules.
  • CMake-gui (here)
  • Visual Studio with ARM toolset and Windows 10 SDK.

I used most recent Visual Studio 2017 (15.6.2). Community Edition is enough. Make sure you have required Visual Studio components:

  • Windows 10 SDK (10.0.16299.0) for UWP: C++
  • Visual C++ runtime for UWP
  • Visual C++ compilers and libraries for ARM

Version of SDK obviously shall match target OS platform version. As of today it's 10.0.16299.0.

Configuration

Start CMake-gui. Select where are your OpenCV source codes (root path) and where you want you build (configuration, temp and output) to be stored. Click Configure.

In the popup window select Visual Studio 15 2017 ARM as a generator (toolset and architecture version) and select "Specify options for cross-compiling".

Provide:

  • Operaring System: WindowsStore
  • Version: 10.0
  • Processor: ARM

Successful generation (possibly with some warnings) shall end up with "Configuration done" message and showing make options.

Look for OPENCV_EXTRA_MODULES_PATH option and provide path to you opencv_contrib/modules folder.

Click Configure again.

Now you can select modules you wish to include in your build. In my configuration I have:

  • Enabled building opencv-world single library (BUILD_opencv_world)
  • Disable building tests and apps (BUILD_TESTS, BUILD_PERF_TESTS, BUILD_opencv_apps)
  • (Optionally) Enable Raspberry Pi NEON and VFP3 optimizations (ENABLE_VPF3=ON, ENABLE_NEON=ON). You can add them using 'add entry' in Cmake (as boolean), but there currently some OpenCV make issues processing those options.

I had to disable descriptor (BUILD_opencv_line_descriptor) and saliency modules (BUILD_opencv_saliency) cause they have problems with Microsoft specific __popcnt, which is no available on ARM platform for MS compiler.

And I used a trick to enable DNN module for Windows. In /modules/dnn/CMakeList.txt you have to comment first three lines:

#if(WINRT)
#  ocv_module_disable(dnn)
#endif()

Configure again and click Generate. Open Project (.SLN) in Visual Studio.

Default project is ALL_BUILD is this is the one to be build. Select configuration you want to build (Release or Debug). Pay attention that resulting import libraries (.lib) and dlls (.dll) will have different names for different configurations.

That's it! Those libraries may be link against UWP applications (C++/CX) and libraries for ARM platform.

Moreover - you can use the same process to build your own configuration for x64 or x86 platforms: Start over Cmake-gui again, select different build folder and in the very first step of the configuration choose Visual Studio 15 2017 x64 or x86 as your generator and then processor accordingly in the cross-compiling options. The rest of the configuration process looks the same.

To play further with OpenCV on Windows 10 IoT Core you may have a look at samples provided by Microsoft itself, e.g. here.