Package OpenCV not found? Let’s Find It.
2015-12-30 15:07
337 查看
转载地址:http://prateekvjoshi.com/2013/10/18/package-opencv-not-found-lets-find-it/
OpenCV has been refined over the years and installing it has become way more user-friendly now. If has been ported to many platforms and you don’t need an IDE to use it. There are many different ways in which you can install it and use it in your existing code.
But sometimes, when people try to do different things with it, they run into problems. This post deals with one such problem. When you write code that uses OpenCV, you need to tell your compiler where it is. The reason for this is that this location will contains
all the libraries and binaries necessary for the header files to work in your code. If you don’t specify this, you will encounter the following error:
Where do we go from here?
The reason for the error is that when you try to compile your code from the command line, you need to tell it where to find OpenCV related stuff. People generally use pkg-config to take care of this because it’s easy to handle and it looks clean. Imagine doing
the ‘-l’ library-includes every time you want to compile some code. Tedious! Just open your terminal and type the following:
This is the path to opencv.pc by default. If you have already installed OpenCV, you should already have opencv.pc somewhere on your machine. So in case you don’t have opencv.pc file in that path, just search for it and assign the path to the PKG_CONFIG_PATH
variable:
And you are done! It’s better to add this line to your bashrc file so that you don’t have to do it every single time you reopen your terminal.
I can’t find my opencv.pc file, what do I do?
If you cannot find the opencv.pc file, don’t worry! Just create a new file called opencv.pc in /usr/local/lib/pkgconfig and add the following content to that file:
After creating this file, make sure the PKG_CONFIG_PATH variable contains this path and you are good to go.
How do I run my OpenCV code now?
Now that all that installing stuff is out of the way, let’s see how we can run your OpenCV code:
Install opencv on your system.
Unzip the zip file
Open the terminal and go to that folder
Type the following on your terminal to compile:
Type the following on your terminal to run (you may need to chmod 777 main.o):
OpenCV has been refined over the years and installing it has become way more user-friendly now. If has been ported to many platforms and you don’t need an IDE to use it. There are many different ways in which you can install it and use it in your existing code.
But sometimes, when people try to do different things with it, they run into problems. This post deals with one such problem. When you write code that uses OpenCV, you need to tell your compiler where it is. The reason for this is that this location will contains
all the libraries and binaries necessary for the header files to work in your code. If you don’t specify this, you will encounter the following error:
Package opencv was not found in the pkg-config search path. Perhaps you should add the directory containing `opencv.pc' to the PKG_CONFIG_PATH environment variable No package 'opencv' found
Where do we go from here?
The reason for the error is that when you try to compile your code from the command line, you need to tell it where to find OpenCV related stuff. People generally use pkg-config to take care of this because it’s easy to handle and it looks clean. Imagine doing
the ‘-l’ library-includes every time you want to compile some code. Tedious! Just open your terminal and type the following:
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
This is the path to opencv.pc by default. If you have already installed OpenCV, you should already have opencv.pc somewhere on your machine. So in case you don’t have opencv.pc file in that path, just search for it and assign the path to the PKG_CONFIG_PATH
variable:
$ export PKG_CONFIG_PATH=/path/to/the/file
And you are done! It’s better to add this line to your bashrc file so that you don’t have to do it every single time you reopen your terminal.
I can’t find my opencv.pc file, what do I do?
If you cannot find the opencv.pc file, don’t worry! Just create a new file called opencv.pc in /usr/local/lib/pkgconfig and add the following content to that file:
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 -l
After creating this file, make sure the PKG_CONFIG_PATH variable contains this path and you are good to go.
How do I run my OpenCV code now?
Now that all that installing stuff is out of the way, let’s see how we can run your OpenCV code:
Install opencv on your system.
Unzip the zip file
Open the terminal and go to that folder
Type the following on your terminal to compile:
$ g++ main.cpp MyFile.h MyFile.cpp `pkg-config opencv --cflags --libs` -o main.o
Type the following on your terminal to run (you may need to chmod 777 main.o):
$ ./main.o
相关文章推荐
- linux内核 80x86保护模式及其编程
- 网站开发记事
- CentOS 6.4安装Kangle面板
- linux uid备忘
- 网站上线之前的基础SEO设置
- Linux安装最新版Mono,Jexus(截至2015年12月30日)
- linux top命令详解
- Docker创建支持ssh服务的容器和镜像
- 设置nginx反向代理
- 如何加入监控程序在Ubontu系统下高效执行
- 第一次实现最基本的MVC架构--登录注册查询删除基本操作
- 01_04_Linux操作系统基础
- ecshop常用模板解析
- Photoshop中图层叠加效果的算法
- Photoshop中图层叠加效果的算法
- 详解Nginx的核心配置模块中对于请求体的接受流程
- linux grep命令
- 详解likely和unlikely函数
- ecshop首页显示产品数量控制
- CentOS-6.5安装配置SVN