2

I'm currently struggling to build OpenCV for the UWP.

I already googled quite a lot and found Microsoft's OpenCV Github Repo which tecnically should do the magic. However, this repo and pretty much everything else I found in this regard are outdated (Visual Studio 2015, old OpenCV versions etc.). I need to use OpenCV 3.3 because it's a cross platform project and I don't want to recompile everything else solely because of an outdated git repo.

Can anyone explain the process of building OpenCV using CMake from the official repo for the UWP?


My first attempt was to simply use the Windows Dlls, however my application than shouts "Failed to load module" at me. Then, I tried to build OpenCV the Visual Studio Project files as stated here and here. However, this doesn't do it for me as it throws the following error:

CMake Error at cmake/OpenCVUtils.cmake:440 (if): if given arguments:

"(" "OR" "OFF" ")"

Unknown arguments specified Call Stack (most recent call first): CMakeLists.txt:317 (OCV_OPTION)

It also tells me to check the CMakeOutput.log but there it's 0 errors everywhere.

If someone could tell me either how to get rid of this error or what to change in the CMake GUI to build OpenCV for UWP, that'd be great!

Edit:

I also tried to compile OpenCV with a platform specific toolchain for WinRT as found in platforms/winrt. It doesn't really change anything though (I'm not even sure if it should), I still get "Unable to load Dll: The specified module could not be found". Maybe GPPK is right in his assumption that it's more an UWP problem than an OpenCV one. Anyways, if anyone knows anything about this, I'd really love to get some help!

FERNman
  • 325
  • 2
  • 13
  • https://blogs.msdn.microsoft.com/lucian/2015/11/27/opencv-building-uwp-binaries/ – GPPK Dec 12 '17 at 13:26
  • I'm sorry that I haven't mentioned this in the question, but the author actually does nothing himself except using the outdated microsoft repo, which I also mentioned. – FERNman Dec 12 '17 at 13:28
  • I think you may have more of a UWP issue than a OpenCV issue. If it is giving you a failed to load module error are you sure that you have added the DLLs etc in the right place? – GPPK Dec 12 '17 at 13:40
  • 95% sure. I actually built my own C++ Dll that uses OpenCV and exports a C interface that I call from C# in Unity. It's working on Android, Windows x64 and Windows x86 already. I followed exactly the same procedure for UWP as for the others. At first I hoped that I could use the same Dlls that I use for x86 Windows for UWP, but now I don't think so anymore (why should there be an extra git repo by microsoft themselves if it's not necessary?). Concerning the position of the Dlls: I created a demo Dll without OpenCV and it's working, so I think everything should be correct. – FERNman Dec 12 '17 at 13:52

1 Answers1

8

Ok, I didn't get an answer yet, so I managed to do it myself (more or less).

Here's how I did it:

Prerequisites

  • Visual Studio (2017)
  • UWP SDK
  • CMake
  • OpenCV from official repo

Steps

  1. Create a build folder which you want the UWP libraries to built in.
  2. Start PowerShell in this folder and execute the following command (exchange C:\OpenCV with your local OpenCV path): cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERS ION="10.0" -DCMAKE_VS_EFFECTIVE_PLATFORMS=x86 -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF C:\OpenCV
  3. If you get the same error message as I did (see question for more details), go to the root CMakeLists.txt in the OpenCV folder and add a # in front of line 317 (OCV_OPTION(ENABLE_PYLINT)). This should fix it, to check, execute the command from above once more.
  4. Ensure that the output claims "Windows RT support YES" and "Building for Microsoft platform: Windows".
  5. Open OpenCV.sln in the build folder. Ensure that all projects are either of type "Windows Store" or "Universal Windows" and build the ALL_BUILD Project twice: Once in Release configuration, and once in Debug. Then build the INSTALL Project.

That's it, you should find the built Dlls in the install folder. Step 3 is probably a bug in OpenCV and will hopefully be fixed in upcoming versions.

FERNman
  • 325
  • 2
  • 13
  • 1
    Thanks for your solution. Since I am building an UWP app also meant to run on ARM, I am struggling to understand how to compile OpenCV not only for x86/x64, any idea? Posted it here: https://stackoverflow.com/questions/48035118/how-to-compile-opencv-3-4-with-visual-studio-15-2017-arm-for-uwp – Guido Magrin Dec 30 '17 at 16:03
  • This was very helpful thank you for answering your own question so thoroughly – Matt Dotson Apr 25 '18 at 22:08
  • I was only able to build version 3.3.1 successfully. Versions 3.4.5 and 4.0.1 didn't require editing the root CMakeLists.txt, but failed to build as they now use Win32 functions all over the place. – Magnus Jan 16 '19 at 22:52