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

后端 未结 4 983
抹茶落季
抹茶落季 2020-12-09 07:24

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

4条回答
  •  时光说笑
    2020-12-09 07:50

    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 true 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):

      
        
          false
        
        
          Console
          false
          false
        
      
      
    • 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)

提交回复
热议问题