I jusst installed Opencv 4.1.1 from source, with python 3 bindings. My Python installation seems to work correctly, because if I run:
import cv2
cv2.__version__
I get '4.1.1'
However, I also want to use some C++ code. I had a previous installation of 3.4.3 that I built from source, and unfortunately I had deleted the build folder before uninstalling it. So, when I run this C++ code, which just finds the version number Macros and prints them:
#include <opencv2/core.hpp>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
//print opencv version
printf("opencv version: %d.%d.%d\n",CV_VERSION_MAJOR,CV_VERSION_MINOR,CV_VERSION_REVISION);
return 0;
}
When i compile with this command :
g++ -o get_version get_version.cpp -I/usr/local/include/opencv4/opencv2 -Lusr/local/lib -lopencv_core
It returned 3.4.3.
So, I wanted to fix this, so I found the old header files, and deleted them all (they were located in /usr/local/include/opencv2). But now when I try to compile my code, it gives me the error:
get_version.cpp:1:10: fatal error: opencv2/core.hpp: No such file or directory
#include <opencv2/core.hpp>
^~~~~~~~~~~~~~~~~~
compilation terminated.
But, if I navigate to /usr/local/include/opencv4/opencv2/, I can see the file, core.hpp, so I don't know why the compiler can't find it.
So, why are my headers not linking correctly? And how can I fix this. I thought the command -I/usr/local/include/opencv4/opencv2 would allow it to find it. I have also already run
sudo ldconfig
Although I'm not sure what that command exactly does. Also, for those that don't know, opencv 4 doesn't automatically include a pkg-config file, so that is not a solution to this problem.
-I/usr/local/include/opencv4
? You should not install and delete files on share header locations. Use your OS' package manager to install the opencv version you want. What OS are you on?