3

I am trying to use the OpenCV library for some image processing inside my Windows 8 Store app using C++/CX. I am able to build the OpenCV library using Visual C++ 2012 but when I package my app and run the Windows App Certification Kit, I get several errors saying that the OpenCV DLLs use some unsupported Windows API. How do I fix these errors?

Raman Sharma
  • 4,551
  • 4
  • 34
  • 63
  • Now there seems to be a semi-official Windows RT port of OpenCV: http://code.opencv.org/projects/opencv/wiki/WindowsRT – Raman Sharma Jan 01 '14 at 00:54

4 Answers4

8

I've managed to build a subset of OpenCV for ARM.

I started by getting the subset I was interested in building for Windows Store applications in x86. After pointing CMake at a source download of OpenCV, I used the Visual Studio 11 generator to configure an x86 project. I added a new build option within CMake called TARGET_METRO, and used this to further configure the other projects.

This allowed me to turn off several 3rd-party components I did not want to build, eg:

OCV_OPTION(BUILD_PERF_TESTS   "Build performance tests"  ON  IF (NOT IOS AND NOT TARGET_METRO) )

I turned off WITH_VIDEOINPUT, BUILD_PERF_TESTS, and BUILD_TESTS in this fashion. I also added the definitions mentioned by Raman when TARGET_METRO was on:

if(TARGET_METRO)
    add_definitions(-DWINAPI_FAMILY=WINAPI_FAMILY_APP)
    add_definitions(-D_UNICODE)
endif()

I then proceeded to generate the x86 (Visual Studio 11) version of the project with CMake and started attempting to build the project. You will run into a number of issues, most of which relate to missing APIs in WinRT. Most of these are mechanical changes (for example, swapping out InitializeCriticalSection for InitializeCriticalSectionEx). I wrapped these changes under #if WINAPI_FAMILY == WINAPI_FAMILY_APP so that it would not impact the non-TARGET_METRO build.

When it came time to build for ARM, what I did was launch CMake and use the Visual Studio 11 generator to generate a new project (under a directory named 'ARM') and then began manually editing the resulting project files.

The major changes you need to make are:

  • Change all 'Win32' to 'ARM' in all vcxproj files (3rdparty\IlmImf includes filenames which contain 'Win32', be careful to change those instances back)
  • For all projects, add <AppContainerApplication>true</AppContainerApplication> to the Globals propertygroup
  • For the ZERO_CHECK project, change ConfigurationType to "DynamicLibrary" instead of "Utility" (as the Utility type will fail to build)
  • Add the following at the project level (for each project you want to build for ARM):

    <ItemDefinitionGroup>
      <ClCompile>
        <CompileAsWinRT>false</CompileAsWinRT>
      </ClCompile>
      <Link>
        <SubSystem>Console</SubSystem>
        <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
        <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
      </Link>
    </ItemDefinitionGroup>
    
  • Remove "/machine:X86 " from Link: Additional Options (if it is in there)

  • Remove gdi32.lib, winspool.lib, shell32.lib, and comdlg32.lib from additional dependencies (these libs do not exist for ARM)
Andy Rich
  • 1,942
  • 10
  • 14
  • Is it possible to run it on a x86 and not on an ARM processor? – Vinicius Rocha Jun 04 '13 at 19:20
  • Yes - you actually need to do less work to do it on x86. You can probably just follow all the steps up until I talk about the additional hacking I did to get it to work for ARM. – Andy Rich Jun 21 '13 at 00:47
4

OpenCV uses CMake to build its sources. After you have downloaded the OpenCV sources, in the root folder edit the file CMakeLists.txt to contain the following two lines:

add_definitions(-DWINAPI_FAMILY=WINAPI_FAMILY_APP) add_definitions(-D_UNICODE)

in the following #if block:

if(WIN32 AND NOT MINGW)

By doing this your library will only have access to the API that are supported for Windows Store apps. This might mean that you will have to fix some build errors (there weren't too many when I tried last week) but eventually your binaries would be WACK clean.

But the above steps will succeed only for x86 and x64 builds of OpenCV. The CMake tool which is used by OpenCV, doesn't yet support Visual C++ 2012 projects for ARM architecture. That issue is being tracked by this bug.

Update

There is now a port of CMake that support building Windows Store and Phone apps (both 8.0 and 8.1). See details here: http://cmakems.codeplex.com/

Second Update

The below video shows OpenCV working in a Windows 10 Universal app written using C++: http://channel9.msdn.com/Events/Build/2015/3-82

Raman Sharma
  • 4,551
  • 4
  • 34
  • 63
  • I would love if you could leave a comment when any progress are made on the C++ 2012 projects for ARM part. I am about to create a vision project targeting windows 8 (x86 and ARM). – Poul K. Sørensen Jan 08 '13 at 00:12
  • Sure I can do that. For now I am just watching this bug: http://www.cmake.org/Bug/view.php?id=13511 – Raman Sharma Jan 08 '13 at 02:39
  • I just saw the build video, Building Windows 8 Metro style Apps with Visual C++ 2012, at some point in the video he uses "OpenCV Based WinRT SDK for FaceDetection". I did not find this from google, but am wondering if there are some arm opencv build out there. – Poul K. Sørensen Jan 08 '13 at 22:56
  • I know that guy. He has used the x86 build of OpenCV for his demo. Basically he has created a thin WinRT wrapper using C++/CX on top of the OpenCV API. He has not been able to build the library for ARM yet. – Raman Sharma Jan 09 '13 at 00:47
  • Okay, i was under the impression that Windows RT was the ARM Part, and Windows 8 was the x86. But based on your comment i can conclude i was mistaken. Thanks. – Poul K. Sørensen Jan 09 '13 at 06:52
  • 1
    You are right, this terminology is confusing. Windows RT is the ARM part. But when people say Windows Runtime API, they are referring to the new style of API that Windows 8 has exposed, those that can be called from any language: C++, C# of JavaScript. This guy when he said WinRT component, he meant the latter and not ARM – Raman Sharma Jan 09 '13 at 07:19
  • If others tries this, the error Raman is mentioned can be seen here: http://pastebin.com/9kQj1mZw – Poul K. Sørensen Jan 26 '13 at 16:28
  • have you seen this: http://stackoverflow.com/questions/11151474/can-arm-desktop-programs-be-built-using-visual-studio-2012 and do you have any comments on the signing part being discussed? – Poul K. Sørensen Jan 26 '13 at 16:33
  • @s093294 that's a separate issue. that's about not being able to build and run desktop apps on ARM. What we are trying here is about not being able to build OpenCV for ARM store apps, which should ideally be possible. – Raman Sharma Jan 26 '13 at 22:55
  • Okay. Ohh well, this is not the place - but would have been nice with a place where people could discuss/solve this problem. Not being able to get OpenCV build for my Windows Phone is frustrating right now :) – Poul K. Sørensen Jan 27 '13 at 00:35
  • Once we have the ARM support for CMake, I guess it should work for both Windows RT and for Windows Phone I guess, with minor modifications. Even before the CMake ARM support comes in, maybe you could do copy the project setting from x86 and create an ARM config and try fixing errors as they pop. – Raman Sharma Jan 27 '13 at 06:50
0

We are working on enabling OpenCV with the new Phone and Store build of CMake. In the meantime have you looked at http://github.com/msopentech/openCV. This has instructions on building OpenCV for WinRT.

0

Disclaimer: I am 100% new to OpenCV as a library and just started to explore this today when I found some sample apps using OpenCV around Azure Cognitive Vision samples.

My only goal was to even see if "OpenCV was supported on UWP and works with ARM". I read a bunch of posts and blogs that were around since 2015+ and they were making me think this was not possible to get working.

Then I found this sample: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CameraOpenCV

And can confirm it works for my basic test, you can see my video here of ARM Pi 2 running UWP app, using the OpenCV library: https://twitter.com/LyalinDotCom/status/982830053355470848

not saying that this means all of OpenCV will just work but at least this test was a good sign and i wanted to share my early results here.

Dmitry Lyalin
  • 444
  • 5
  • 8
  • One more disclaimer: I work at Microsoft as a Product Manager for VSTS, but all of this is just my side hobby of exploring various fun projects, none of this is my day job nor do i represent the UWP team or this sample. I found it like any other user would, searching the web – Dmitry Lyalin Apr 08 '18 at 04:04