Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program cannot run OpenCV even though others can

I am trying to run a program that uses OpenCV and I have gotten it to run on other machines, and other programs on my machine run using it, but this one returns:

programname.cpp:  fatal error: opencv/cv.h: No such file or directory

Anyone know how to fix the path or what might be going wrong? I am running Ubuntu 12.04 and OpenCV-2.4.0

like image 474
clifgray Avatar asked Jun 01 '12 23:06

clifgray


People also ask

Why OpenCV-Python is not working?

Not having the opencv-python package installed by running pip install opencv-python . Installing the package in a different Python version than the one you're using. Installing the package globally and not in your virtual environment. Your IDE running an incorrect version of Python.

Is cv2 OpenCV?

cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.

Where is cv2 in Python?

The file cv2.so is stored in /usr/local/lib/python2. 7/site-packages/... There are also folders in /usr/local/lib called python3.

What is cv2 module?

cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python". The traditional OpenCV has many complicated steps involving building the module from scratch, which is unnecessary. I would recommend remaining with the opencv-python library.


2 Answers

Change from:

#include <opencv/cv.h>

to:

#include <opencv2/opencv.hpp>

like image 200
jag2kn Avatar answered Sep 26 '22 05:09

jag2kn


On my Ubuntu 11.04, the headers are in: */usr/include/opencv-2.3.1/*, I assume it should be */usr/include/opencv-2.4.0/* for you.

You have two solutions:

  • When you compile, use the -I option: g++ -o [name] [src] -I/usr/include/opencv-2.4.0
  • Create symbolic links to opencv-2.4.0/opencv and opencv-2.4.0/opencv2 in /usr/include.

The second solution is useful if you're using CMake, because FindOpenCV2 does not look for OpenCV in /usr/include/opencv-2.4.0. I hope this (ugly) hack will solve your problem.

like image 27
Samuel Gosselin Avatar answered Sep 24 '22 05:09

Samuel Gosselin