In order to install OpenCV on my Mac, I opted to use brew install opencv
instead of building from source as is specified in the Mac installation tutorials. Homebrew's installation path appears to be /opt/homebrew, and all of the included packages that I have downloaded appear to be contained in the include in that directory.
I wrote a sample program program in order to test the installation:
#include <opencv4/opencv2/imgcodecs.hpp>
#include <opencv4/opencv2/highgui.hpp>
#include <opencv4/opencv2/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
VideoCapture cap(0);
Mat img;
while (1) {
cap.read(img);
imshow("Image", img);
if (waitKey(1) == 27) {
break;
}
}
return 0;
}
And, to compile it, I ran:
g++ video.cpp `pkg-config --cflags --libs opencv4`
which returned:
fatal error: 'opencv4/opencv2/imgcodecs.hpp' file not found
I ran pkg-config --cflags --libs opencv4
to check whether it was set correctly, and the following was returned:
-I/opt/homebrew/Cellar/opencv/4.5.2_4/include/opencv4 -L/opt/homebrew/Cellar/opencv/4.5.2_4/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -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_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_viz -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
I think that this implies that the path to OpenCV is set for linking the package during compilation, so I was wondering about why the linker couldn't find it. Also, my end-goal is to write a program involving pcl, and I also installed pcl via brew. Since it is also contained in opt/homebrew/, do I have to create a specific reference to its path outside of /usr/ when making the cake file? Thanks!