Search code examples
visual-c++opencvwindows-8visual-studio-2012cmake

Using OpenCV in a Windows Store app with Visual C++


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?


Solution

  • 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