Setting up OpenCV Development Environment in Xcode for Your macOS

Pre-requisite

  • You should have Homebrew installed by following the install manual on Homebrew website
  • You can use Homebrew to install wget and pkg-config

Install OpenCV

brew install opencv
image

View OpenCV linker flags

pkg-config --flags --libs opencv4
image

My outputs looks like this:

-I/usr/local/Cellar/opencv/4.3.0_5/include/opencv4/opencv -I/usr/local/Cellar/opencv/4.3.0_5/include/opencv4 -L/usr/local/Cellar/opencv/4.3.0_5/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core

Create a C++ Project in Xcode

First, you should create a Command Line Tool project like this, and click next.

image

And you should give your project a name, select the C++ as your project language.

image

Configure OpenCV in Xcode

image

For Header Search Paths, you should add /PATH to your own OpenCV/4.3.0_5/include

image

For Library Search Paths, add /PATH to your own OpenCV/4.3.0_5/lib

image

Set Other LInker Flags
image

If you read this, you’ve successfully setup your OpenCV & C++ development environment on your mac. Actually this post is written for myself, I’ll be really happy if this post helps you!