# configure the necessary common CMake environment variables # Clang version is often behind in the XCode installation # Tell compiler to use C++ 14 features which is needed because
Set(OpenCV_DIR /Users/adammcquistan/code/c++/opencv/install/lib/cmake/opencv4) # files within the previously installed opencv program # set OpenCV_DIR variable equal to the path to the cmake # I don't know where to cut off I just use the version I'm using # Older versions of CMake are likely to work just fine but, since main.cppĬout << "Expecting a image file to be passed to program" << endl Ĭout << "Not a valid image file" << endl Ĭv::namedWindow("Simple Demo", cv::WINDOW_AUTOSIZE) Īdditionally, inside the simple_demo directory I create a CMakeLists.txt file, which is essentially a CMake configuration script, and place the following in it. The main method looks for a argument to be passed to the program representing the path to a image file to be read in and displayed using OpenCV.
#BREW INSTALL OPENCV MAC CODE#
Inside the simple_demo directory I make a main.cpp file and fill it with the following code which includes the opencv.hpp and highgui.hpp headers as well as defines a main() method. Then I make a new directory called simple_demo and change directories into it. To do this I change directories back to the top level opencv directory I created at the start of this tutorial (ie, the one that contains the directories opencv, opencv_contrib, build_opencv and install directories). Verify OpenCV Install with Simple Demo Projectīefore moving on to the VS Code setup its a good idea to verify that OpenCV was properly built and installed using a simple demo project. $ export CPUS=$(sysctl -n hw.physicalcpu) The last steps to install is to kick off the multithreaded build to compile the project followed by installing it into the install directory as seen below. D OPENCV_EXTRA_MODULES_PATH=./opencv_contrib/modules \ Next I change directories into the build_opencv directory and configure CMake as shown below. $ mkdir install build_opencvĭrwxr-xr-x 2 adammcquistan staff 64 Mar 29 21:45 build_opencvĭrwxr-xr-x 2 adammcquistan staff 64 Mar 29 21:45 installĭrwxr-xr-x 21 adammcquistan staff 672 Mar 29 21:35 opencvĭrwxr-xr-x 13 adammcquistan staff 416 Mar 29 21:36 opencv_contrib
Next I create two more directories (i) an install directory which will be the target for my installation of OpenCV and, (ii) another named build_opencv for building the sources in. I should now be in the top level opencv directory that contains the two aforementioned repositories. The extra modules are optional and contain experimental algorithms and features but in my opinion they are good to have for development purposes.įirst make a top level opencv directory, change directories into it and clone the two repositories then checkout the most recent tagged release versions which are 4.2.0 as of the date of writing this article. In addition to the main source I will pull down the extra contribution modules for install as well. $ brew install cmake Installing OpenCV from Source with CMakeīefore I can build and install OpenCV I must clone its source repo from GitHub. CMake can be easily installed using brew as follows. I use CMake in this tutorial to build and install OpenCV for C++ as well as run the demo project. $ /bin/bash -c "$(curl -fsSL )" Installing CMakeĬMake is a cross platform build tool popular among native C/C++ developers. To install Homebrew execute this command from your terminal.
#BREW INSTALL OPENCV MAC MAC OS#
Homebrew, aka brew, is a software package manager for the Mac OS platform that is heavily used among developers. Since installing XCode is covered quite well by Apple Developer Support and a very common task among technologists utilizing Mac OS platforms I will simple link to Apple's docs for that part. In order to utilize the popular Mac OS clang compiler you should have XCode and the XCode tools installed.