0

I followed this tutorial to build OpenCV: https://qengineering.eu/install-opencv-on-raspberry-pi.html

It built and installed successfully, but trying to include opencv2/opencv.hpp is not working. The file is definitely present in /usr/local/include/opencv4/opencv2/opencv.hpp.

I know I could just add it as an include directory in the C++ project with the -I flag, but I want to understand why it's not working.

The ${OpenCV_INCLUDE_DIRS} is not defined. Is it supposed to be added to .bashrc or somewhere else by Make? Did a certain step fail without warning?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Valeriy Novytskyy
  • 775
  • 1
  • 7
  • 18
  • 1
    `${OpenCV_INCLUDE_DIRS}` is from CMake when you use `find_package(opencv)` in your CMakeLists.txt that you have for the code you are building. – drescherjm Aug 01 '23 at 16:22
  • please contact the author of the tutorial. – Christoph Rackwitz Aug 01 '23 at 16:25
  • Here is what I am talking about in my first comment about ${OpenCV_INCLUDE_DIRS} : [https://stackoverflow.com/a/42658058/487892](https://stackoverflow.com/a/42658058/487892) When configuring your CMakeLists.txt `${OpenCV_INCLUDE_DIRS}` is set if you have a find_package(opencv) and OpenCV was found. – drescherjm Aug 01 '23 at 17:08
  • @ChristophRackwitz the tutorial is based on OpenCV build documentation, it just fills in the parts that are missing in the original documentation and adds a few things like swap file resizing that don't affect the outcome of the build process, only its speed. – Valeriy Novytskyy Aug 01 '23 at 18:28
  • @drescherjm is it true in general that OpenCV tutorials simply don't include the information on how to compile the code? In other words, they assume that you either use `find_package` or the `-I` flag to tell the compiler that OpenCV is located at `/usr/local/include`. If that's so, feel free to add that as a reply and I will accept. – Valeriy Novytskyy Aug 01 '23 at 18:30
  • 2
    The tutorial you link is about installing opencv on your raspberry, not about how to include it in another project. That's why it doesn't cover this. `find_package` is the way to go. – Wutz Aug 01 '23 at 19:23

1 Answers1

0

Thanks to @drescherjm for pointing me to OpenCV make documentation and @Wutz for confirming:

https://docs.opencv.org/4.x/db/df5/tutorial_linux_gcc_cmake.html

This has you create CMakeLists.txt, then run cmake . to create Makefile, then run make to build using the makefile.

That will correctly tell the compiler where OpenCV is using macros for include and lib.

Valeriy Novytskyy
  • 775
  • 1
  • 7
  • 18