user2048466
user2048466

Reputation: 385

OpenCV: 32-bit libs & dlls for Visual Studio project

I am upgrading a C++ Visual Studio project that uses OpenCV 2.4 to a more recent version of OpenCV (e.g. 4.1.2 or 4.4.0). I need 32-bit and 64-bit builds of my project, so I need 32-bit and 64-bit versions of the OpenCV libs and dlls.

But recent pre-built downloadable versions of OpenCV for Windows contain libs and dlls for x64 only. I did find 32-bit and 64-bit precompiled binaries here (https://github.com/huihut/OpenCV-MinGW-Build) but they are built with MinGW and don't have the VS-compatible libs I need for linking.

I can try to build my own 32-bit version of the OpenCV libs but at first glance this looks like it could take a lot of effort. OpenCV utilizes CMake and other tools I'm not familiar with.

So my question is: can anyone point me to 32-bit build of a recent version of OpenCV that has libs built with Visual Studio? Or if not, can anyone confirm that they have built a 32-bit OpenCV with Visual Studio? If this is my only choice I'll go down this road, but I'd like to know in advance if this is difficult (for example, maybe OpenCV itself has dependencies that are not available as 32-bit?).

Any help appreciated!

Upvotes: 4

Views: 5604

Answers (1)

user2048466
user2048466

Reputation: 385

I built OpenCV myself, it turned out not to be difficult. I followed the guides here and here. I'll put my own detailed steps below, it might help someone else.

I am using Visual Studio Enterprise 2019. My choices are shown in parenthesis.

  • Download and install CMake from https://cmake.org/download (CMake 3.18.3)
  • Download the OpenCV source code from https://opencv.org/releases (OpenCv 4.4.0)
  • Unzip the source code (c:\opencv\src)
  • Run CMake
  • In the CMake UI, specify Where is the source code (c:\opencv\src) and Where to build the binaries (c:\opencv\build)
  • Check the Grouped and Advanced checkboxes
  • Click Configure. If CMake asks permission to create the build folder, allow it
  • Choose the Specify the generator for this project (Visual Studio 16 2019)
  • Choose the Optional platform for generator (Win32)
  • For Optional toolset to use, I left this blank
  • Choose Use default native compilers
  • Click Finish. CMake will process for a few minutes.

For me at this point, there is a big list of items in red and in the detail area at the bottom, everything is ok except for some Python errors in red. I don't care about the Python parts, so:

  • In the upper pane, expand the BUILD item
  • Uncheck BUILD_opencv_python_bindings_generator
  • Uncheck BUILD_opencv_python_tests

Click Configure again... wait to see the 'Configuring done' message. All the red disappears. Click Generate and wait to see the 'Generating done' message. Look in your build folder... open the solution 'OpenCV.sln' Open it in Visual Studio, build Release or Debug.

If you want to make an x64 build, start over by doing File->Delete Cache, and select x64 at the Optional platform for generator step.

Upvotes: 10

Related Questions