Skip to content

Instantly share code, notes, and snippets.

@rohanrudra55
Last active January 24, 2022 08:23
Show Gist options
  • Save rohanrudra55/21ba8e11b3d934c8827348d3427c8047 to your computer and use it in GitHub Desktop.
Save rohanrudra55/21ba8e11b3d934c8827348d3427c8047 to your computer and use it in GitHub Desktop.
To setup OpenCV for C++ environment in macOS

First Mehtod

NOTE: Folder names may vary and may need tweaking

Dependencies

  • Open terminal and check for xcode tools xcode-select --install

Using Homebrew

  • Run: brew install opencv (It will take some time)
  • It's installed location is: cd /usr/local/Cellar/opencv and locate for opencv4 folder

Second Method

( For linux its almost same )

Building from source

  • Insatll make brew install make
  • Install cmake brew install cmake
  • Download opencv .zip from github
  • Unzip it in ~ home dirctory
  • Go to unziped folder and follow:
    • mkdir -p build && cd build
    • cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON ..
    • make -j8
    • sudo make install
  • Remove the opencv folder from home directory
  • It's installed location is cd /usr/local/include/ and locate for opencv4 folder

Final Step

For VS Code

  • Open configuration pallate, then open the c_cpp_properties.json file from .vccode
  • Add the OpenCV lib path: /usr/local/Cellar/opencv/4.5.2_4/include/opencv4/** ( In my case)
@Aditi2323
Copy link

Nice

@codesoumya
Copy link

Wah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment