cgsaxner / HL2ToolTracking

Creative Commons Zero v1.0 Universal
27 stars 7 forks source link

Difficulties with OpenCV library version >= 4.3.0 #4

Closed SWAGamaz closed 9 months ago

SWAGamaz commented 1 year ago

Good day. I'm having trouble compiling the OpenCV library for the UWP/ARM64 platform with CMake. When compiling for the ARM / ARM 64 platform, there are countless errors. Could you please share the finished OpenCV >= 4.3.0 library for UWP / ARM64 ?

dallen-28 commented 1 year ago

Hello, I am also having the same issue building OpenCV for ARM64, it fails with this error: 15>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\emmintrin.h(20,1): fatal error C1189: #error: This header is specific to X86 and X64 targets.

Using CMake 3.16.3, Visual Studio 2019, and OpenCV 4.3.0, please let me know if you have any insight into this error or if you have a successful build you can provide, thanks!

cgsaxner commented 1 year ago

Hi, sorry to hear you have troubles with compiling OpenCV for ARM64. I have uploaded my build here, I hope that works. Don't forget that you still need to configure the additional include directories and dependencies in the solution.

Otherwise, here are few things that might help when compiling OpenCV for ARM64 from source (these are from my notes, it has been a while since I've done this). Tested with CMake 3.18.4 GUI, OpenCV 4.3.0 and Visual Studio 2017.

  1. Download OpenCV and OpenCV contrib from GitHub
  2. Open CMake GUI. Set the source folder to the downloaded release.
  3. Add following entries in cmake:
    1. CMAKE_SYSTEM_NAME=WindowsStore
    2. CMAKE_SYSTEM_VERSION=10.0
    3. CMAKE_SYSTEM_PROCESSOR=aarch64
  4. Hit configure. I used Visual Studio 15 2017 as generator.
  5. Add the path to opencv_contrib/modules to OPENCV_EXTRA_MODULES_PATH
  6. Configure again.
  7. Disable the following modules from OpenCV:
    1. BUILD_opencv_videoio, BUILD_opencv_python_bindings_generator, BUILD_opencv_python_java_generator, BUILD_opencv_ts, BUILD_opencv_hdf, BUILD_opencv_xfeatures2d, BUILD_opencv_js, BUILD_opencv_dnn_objectdetect, BUILD_opencv_gapi, BUILD_opencv_saliency, BUILD_opencv_line_descriptor, BUILD_opencv_bsegm
    2. Optional: BUILD_TESTS and BUILD_PERF_TESTS for a faster build.
  8. Configure again. Make sure the summary states Windows RT support: YES
  9. Hit generate. No errors should appear during generation (otherwise, it might be that you need do disable more modules).
  10. Open the OpenCV.sln with Visual Studio (I used 2017).
  11. Switch configuration to Release, ARM64. Build the BUILD_ALL, then the INSTALL project. There should be no errors.
dallen-28 commented 1 year ago

Hi Christina,

Thank you for the response, I was able to build openCV 4.3.0 for ARM64 successfully with VS 2019 using your instructions, I just had to also disable the BUILD_opencv_rgbd and BUILD_opencv_tracking options. The HL2ToolTrackingWRC solution built fine as well, if you have a sample unity application you could provide that demos how to use the plugin that would be much appreciated. Thanks for the great work!

SWAGamaz commented 1 year ago

@cgsaxner , many thanks for the instructions. The library has been successfully compiled. Now I'm having trouble using it in Unity. Could you share a code example on how to include and use HL2ToolTrackingWRC.dll in a Unity project?

I added .dll and .winmd files to the project and tried to call the wrapped library:

#if ENABLE_WINMD_SUPPORT
using HL2ToolTrackingWRC;
HL2ToolTracking tracking = new HL2ToolTracking();
#endif

but I get an error: error CS0009: Metadata file 'D:\Unity\Proj\ToolTracker\Assets\Plugins\HL2ToolTrackingWRC\HL2ToolTrackingWRC.dll' could not be opened -- PE image doesn't contain managed metadata.

But I can’t imagine how to add a constructor to make an instance of an object using DllImport.

cgsaxner commented 1 year ago

Hi! @SWAGamaz code should work. Have you made sure that the plugins (.winmd and .dll files) are configured in the Unity Inspector to use WSA Player and ARM64 platform: image

If you put your plugins in a folder Assets\Plugins\WSA\ARM\..., Unity should automatically configure them correctly.

Also, make sure that you include the dlls for OpenCV dependencies in the same folder / configure them in the same way (i.e., opencv_calib3d, opencv_core, opencv_features2d, opencv_flann, opencv_imgproc, opencv_video).

I will try to upload a Unity sample project soon.