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

后端 未结 4 984
抹茶落季
抹茶落季 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:47

    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 讨论(0)
  • 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 <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)
    0 讨论(0)
  • 2020-12-09 07:51

    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

    0 讨论(0)
  • 2020-12-09 07:58

    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.

    0 讨论(0)
提交回复
热议问题