I have a dual camera hardware module for my raspberry pi zero. It requires some software to get working though. I have cloned the required repo from, as seen here:
pi@luna:~/RaspberryPi/Multi_Camera_Adapter/Multi_Adapter_Board_2Channel_uc444 $ ls
arducam_multi_adapter_uc444.cpp Makefile obj readme.md shell
When I try to make, I get the following error:
pi@luna:~/RaspberryPi/Multi_Camera_Adapter/Multi_Adapter_Board_2Channel_uc444 $ sudo make
g -c -o obj/arducam_multi_adapter_uc444.o arducam_multi_adapter_uc444.cpp `pkg-config --cflags --libs opencv`
arducam_multi_adapter_uc444.cpp:4:10: fatal error: opencv2/opencv.hpp: No such file or directory
4 | #include <opencv2/opencv.hpp>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:10: obj/arducam_multi_adapter_uc444.o] Error 1
Looking at /usr/include/opencv4/opencv2
I see the file this script wants.
pi@luna:~/RaspberryPi/Multi_Camera_Adapter/Multi_Adapter_Board_2Channel_uc444 $ ls /usr/include/opencv4/opencv2
alphamat.hpp ccalib dnn_superres.hpp freetype.hpp imgcodecs line_descriptor.hpp opencv_modules.hpp quality shape superres video ximgproc
aruco ccalib.hpp dpm.hpp fuzzy imgcodecs.hpp mcc optflow quality.hpp shape.hpp superres.hpp video.hpp ximgproc.hpp
aruco.hpp core face fuzzy.hpp img_hash mcc.hpp optflow.hpp rapid.hpp stereo surface_matching videoio xobjdetect.hpp
bgsegm.hpp core_detect.hpp face.hpp hdf img_hash.hpp ml phase_unwrapping reg stereo.hpp surface_matching.hpp videoio.hpp xphoto
bioinspired core.hpp features2d hdf.hpp imgproc ml.hpp phase_unwrapping.hpp rgbd stitching text videostab xphoto.hpp
bioinspired.hpp datasets features2d.hpp hfs.hpp imgproc.hpp objdetect photo rgbd.hpp stitching.hpp text.hpp videostab.hpp
calib3d dnn flann highgui intensity_transform.hpp objdetect.hpp photo.hpp saliency structured_light tracking viz
calib3d.hpp dnn.hpp flann.hpp highgui.hpp line_descriptor opencv.hpp plot.hpp saliency.hpp structured_light.hpp tracking.hpp viz.hpp
I tried to create an opencv.pc as described in this earlier question, but the opencv.hpp is still not being found.
pi@luna:~/RaspberryPi/Multi_Camera_Adapter/Multi_Adapter_Board_2Channel_uc444 $ cat /usr/local/lib/pkgconfig/opencv.pc
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: opencv
Description: The opencv library
Version: 2.x.x
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui
I felt like that opencv.pc is not point to the right place as it resolves to /usr/include/opencv2
and on my pi, I have the files in /usr/include/opencv4/opencv2
, though even with tinkering with where the opencv.pc file points, I'm still running into the error above. I have since returned it to its original state and have modified my .bashrc
as they suggested.
pi@luna:~/RaspberryPi/Multi_Camera_Adapter/Multi_Adapter_Board_2Channel_uc444 $ pkg-config --cflags --libs opencv
-I/usr/include/opencv -I/usr/include/opencv2 -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui
pi@luna:~/RaspberryPi/Multi_Camera_Adapter/Multi_Adapter_Board_2Channel_uc444 $ echo $PKG_CONFIG_PATH
:/usr/local/lib/pkgconfig
I feel like something needs to be linked or pointed to somewhere to get make to see that opencv.hpp
file. If I go in and manually edit arducam_multi_adapter_uc444.cpp
's 4th line to the absolute path of the opencv.hpp
, I no longer get an error in arducam_multi_adapter_uc444.cpp
, but in opencv.hpp
as it then is included and starts looking for core.hpp
and other .hpp
s in /usr/include/opencv4/opencv2
. How can I fix this, I feel close, I just don't know how to tell make where to look.
CodePudding user response:
This has nothing to do with make per se. The problem is that your compiler invocation is wrong for the include statement you have.
You can debug this yourself: first, see the command make invoked:
g -c -o obj/arducam_multi_adapter_uc444.o arducam_multi_adapter_uc444.cpp `pkg-config --cflags --libs opencv`
Now run that command yourself from your shell prompt. You'll see it fails the same way. So you know it's not make, but rather the compiler command that's wrong.
Next, figure out what the pkg-config
is expanding to; run that from your shell prompt:
pkg-config --cflags --libs opencv
It will print out the options it's adding. These options are wrong and causing your compile to fail.
First, you are compiling a source file into an object file, so you don't need the --libs
option. The --libs
option provides libraries to link with and these are not used during compilation.
Second, your configuration says this:
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
which means the compiler will see options like -I.../include/opencv -I.../include/opencv2
. There's no magic to the way header files are looked up: the compiler takes the paths provided by -I
, and appends the path it needs from your #include
line, one by one, until the header is found. That's all.
Since you're including opencv2/opencv.hpp
, it will add that path to each of the -I
paths. So, the compiler looks for .../include/opencv/opencv2/opencv.hpp
first, then it will look for .../include/opencv/opencv2/opencv2/opencv.hpp
.
Clearly, the header you want is not available at either of those paths: the header you want is (presumably) .../include/opencv2/opencv.hpp
.
So, if you want your #include
to specify opencv2/opencv.hpp
, your cflags need to be:
Cflags: -I${includedir}