I’m trying to add a pnp solver to opencv
I’m working on ubuntu OS.
first I followed a tutorial on how to install opencv from source by cloning the repositories, then I tested the example and it worked so it compiled and installed succesfully.
I began adding my files and I made sure that no names are duplicated and all the files have been added so there were no issues with dependancies.
then I ran the cmake again, and ran the make command, but it is giving me the following error:-
opencv/modules/calib3d/src/RansacOptimalNPnP/../NPnP/DualVar.h:71:8: error: ‘optional’ in namespace ‘std’ does not name a template type
71 | std::optional<std::tuple<Eigen::Matrix3d, Eigen::Vector3d, double>>
I looked it up online and there is a possibility that I need to use C++ version 17 but the standard version in opencv is set to 11.
what can I change in the opencv cmake list to change that?
2
Answers
You can install OpenCV from ubuntu’s opencv package via the following:
for python:
for libopencv-dev:
If you want to compile it and not use ubuntu’s OpenCV package, do the following:
now that you are done with dependencies continue to the actual installation
if properly configured this is the output
This was shamelessly copied from opencv docs py setup in ubunutu
As I understand it Thamognya’s answer, while useful to most users, misses what you are trying to do :
author and build a new module, to be compiled into the OpenCV library, (and your new module depends on C++17).
Re Setting C++ version and other options in Cmake:
To set the C++ version, and other Cmake options, I recommend using "cmake-gui". This is part of cmake, but separately installed in Ubuntu (and most Linix distros).
You will find the c++ compiler options in the CMAKE_CXX* variables.
Re extending OpenCV:
If you have not already done so, I recommend cloning the OpenCV-contrib and OpenCV-extra repositories.
These provide
Re C++ version compatability:
C++ is intended to be backwards compatible, but there are details…
ABI compatability between compiler versions is a related issue.
This thread gives information on mixing versions of C++ in a library: Is it safe to link C++17, C++14, and C++11 objects
I would recommend starting by setting C++ version in "cmake-gui", and seeing if there are problems in configuration, build file generation, and compilation. Start with a minimal build and add only what you need. (i.e. Don’t take on more complexity/bugs than you have to.)
OpenCV has the option to build many of its dependencies from source, (rather than using the versions you may have insalled on your operating system). This may help avoid compatability issues.